[SERVER-45684] Ninja compiledb adds env vars to commands Created: 21/Jan/20  Updated: 06/Dec/22  Resolved: 19/Feb/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ryan Timmons Assignee: [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Development Platform
Operating System: ALL
Participants:

 Description   

Ninja compiledb adds env vars to commands

Expected: compile_commands.json that looks like this (this is what scons produces):

        "command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -o build/debug/third_party/murmurhash3/MurmurHash3.o -c -Woverloaded-virtual -Werror=unused-result -Wpessimizing-move -Wredundant-move -Wno-undefined-var-template -Wno-instantiation-after-specialization -fsized-deallocation -Wno-defaulted-function-deleted -Wunused-exception-parameter -std=c++17 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.12 -target darwin16.0.0 -arch x86_64 -fno-omit-frame-pointer -fno-strict-aliasing -fasynchronous-unwind-tables -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O0 -Wno-unused-local-typedefs -Wno-unused-function -Wno-unused-private-field -Wno-deprecated-declarations -Wno-tautological-constant-out-of-range-compare -Wno-tautological-constant-compare -Wno-tautological-unsigned-zero-compare -Wno-tautological-unsigned-enum-zero-compare -Wno-unused-const-variable -Wno-missing-braces -Wno-inconsistent-missing-override -Wno-potentially-evaluated-expression -Wno-unused-lambda-capture -Wno-exceptions -Wunguarded-availability -fstack-protector-strong -fno-builtin-memcmp -DPCRE_STATIC -DBOOST_THREAD_VERSION=5 -DBOOST_THREAD_USES_DATETIME -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS -DBOOST_ENABLE_ASSERT_DEBUG_HANDLER -DBOOST_LOG_NO_SHORTHAND_NAMES -DBOOST_LOG_USE_NATIVE_SYSLOG -DABSL_FORCE_ALIGNED_ACCESS -Isrc/third_party/fmt/dist/include src/third_party/murmurhash3/MurmurHash3.cpp",

Actual:

    "command": "PATH=/usr/local/bin:/opt/bin:/bin:/usr/bin PATHOSX=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands HOME=/Users/rtimmons TERM=xterm-256color /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -o build/debug/mongo/dbtests/basictests.o -c -Woverloaded-virtual -Werror=unused-result -Wpessimizing-move -Wredundant-move -Wno-undefined-var-template -Wno-instantiation-after-specialization -fsized-deallocation -Wno-defaulted-function-deleted -Wunused-exception-parameter -std=c++17 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -mmacosx-version-min=10.12 -target darwin16.0.0 -arch x86_64 -fno-omit-frame-pointer -fno-strict-aliasing -fasynchronous-unwind-tables -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O0 -Wno-unused-local-typedefs -Wno-unused-function -Wno-unused-private-field -Wno-deprecated-declarations -Wno-tautological-constant-out-of-range-compare -Wno-tautological-constant-compare -Wno-tautological-unsigned-zero-compare -Wno-tautological-unsigned-enum-zero-compare -Wno-unused-const-variable -Wno-missing-braces -Wno-inconsistent-missing-override -Wno-potentially-evaluated-expression -Wno-unused-lambda-capture -Wno-exceptions -Wunguarded-availability -fstack-protector-strong -fno-builtin-memcmp -MMD -MF build/debug/mongo/dbtests/basictests.o.d -DSAFEINT_USE_INTRINSICS=0 -DPCRE_STATIC -DBOOST_THREAD_VERSION=5 -DBOOST_THREAD_USES_DATETIME -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS -DBOOST_ENABLE_ASSERT_DEBUG_HANDLER -DBOOST_LOG_NO_SHORTHAND_NAMES -DBOOST_LOG_USE_NATIVE_SYSLOG -DABSL_FORCE_ALIGNED_ACCESS -Isrc/third_party/SafeInt -Isrc/third_party/pcre-8.42 -Isrc/third_party/fmt/dist/include -Isrc/third_party/boost-1.70.0 -Isrc/third_party/abseil-cpp-master/abseil-cpp -Ibuild/debug -Isrc src/mongo/dbtests/basictests.cpp",

This causes at least CLion to not recognize the compiler correctly.

I don't know if the spec allows for env vars to be specified like this (seems like maybe it should allow it). If so it's reasonable to say "wontfix" to this and say it's a bug in editors not parsing commands correctly or something. But it seems reasonable to want that scons and ninja produce similar files.

For now it's not hard to use global-search-and-replace to remove the PATH= etc prefixes.



 Comments   
Comment by Daniel Moody [ 11/Nov/20 ]

Possible we can strip the environments from the generated compile_commands.json? It would require a tricky regex, but I think adding a sed command in the ninja tool where the compile_commands.json is created could do it.

Comment by Andrew Morrow (Inactive) [ 19/Feb/20 ]

This isn't a regression from the old ninja module, which had the same issue. There also isn't much we can do about it. In many cases, we must include these environment variables on the Ninja command line in order to enable features like ccache and icecream. Since the Ninja generated compiledb will reflect those commands, there isn't a way for us to avoid issuing them. Our recommendation will be that users generate their compilation database directly from SCons, which will not include the environment variables, since SCons manages the environment differently than Ninja. Generating the compilation database with SCons is very fast.

Generated at Thu Feb 08 05:09:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.