[SERVER-45682] Ninja compiledb incorrect for some targets Created: 21/Jan/20  Updated: 29/Oct/23  Resolved: 24/Jan/20

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

Type: Bug Priority: Major - P3
Reporter: Ryan Timmons Assignee: Mathew Robinson (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Dev Platform 2020-01-27
Participants:

 Description   

Repro steps:

python3 ./buildscripts/scons.py \
  --dbg --variables-files=etc/scons/xcode_macosx.vars \
  --modules= \
  --ninja new.build.ninja
ninja -f ./new.build.jinja compiledb

Expected: No lines have file:<path_to_compiler>.

Actual:

Some lines look like the following:

    "file": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++",

Mat and I looked into this. It seems related to the ordering of dependencies. E.g. in the new.build.ninja file, we see:

    build build/debug/mongo/dbtests/catalogtests.o: CMD_W_DEPS | src/mongo/dbtests/catalogtests.cpp $
        /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ $
        /Users/rtimmons/mongodb/mongo/new.build.ninja || _generated_sources
      cmd = PATH=/usr/local/bin:/opt/bin:/bin:/usr/bin $

for a target that has the correct "file" attribute and

build build/debug/mongo/dbtests/basictests.o: CMD_W_DEPS | $
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ $
    src/mongo/dbtests/basictests.cpp /Users/rtimmons/mongodb/mongo/new.build.ninja || $

for a target that does not.

It seems like the ordering of dependencies may vary run over run (python sets are hash-based) so sometimes the order of clang++ and {{.cpp} files changes.

Scons gets the compiledb right fwiw:

    python3 ./buildscripts/scons.py \
      --dbg --variables-files=etc/scons/xcode_macosx.vars \
      --modules= \
      compiledb



 Comments   
Comment by Githook User [ 22/Jan/20 ]

Author:

{'email': 'mathew.robinson@mongodb.com', 'username': 'chasinglogic', 'name': 'Mathew Robinson'}

Message: SERVER-45682 Correct Ninja compiledb, improve performance
Branch: master
https://github.com/mongodb/mongo/commit/d1c386904123e7a200f3a4ee2e33dc21b52e5031

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