bazel build compiledb produces broken compile_commands.json

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • 8.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • DevProd Build
    • ALL
    • Hide

       

      #!/usr/bin/env sh
      bazel build compiledb
      cat > compiledb_to_makefile.py << EOF
      import json
      import fileinput
      def print_mk(target, prerequisites, recipe):
          print(target, ": ", " ".join(prerequisites))
          for c in recipe:
              print("\t" + c)
          print()
      
      all_targets = []
      commands = json.loads("".join([line for line in fileinput.input()]))
      for c in commands:
          target = c["output"]
          all_targets.append(target)
          recipe = []
          recipe.append("mkdir -p \$(dir \$@)")
          recipe.append(" ".join(c["arguments"]))
          print_mk(target, [], recipe)
      print_mk("all", all_targets, ["echo done"])
      EOF
      python3 ./compiledb_to_makefile.py < compile_commands.json > compiledb.mk
      make -j `nproc` -f compiledb.mk -k all
      

       

      Show
        #!/usr/bin/env sh bazel build compiledb cat > compiledb_to_makefile.py << EOF import json import fileinput def print_mk(target, prerequisites, recipe):     print(target, ": " , " " .join(prerequisites))     for c in recipe:         print( "\t" + c)     print() all_targets = [] commands = json.loads("".join([line for line in fileinput.input()])) for c in commands:     target = c[ "output" ]     all_targets.append(target)     recipe = []     recipe.append( "mkdir -p \$(dir \$@)" )     recipe.append( " " .join(c[ "arguments" ]))     print_mk(target, [], recipe) print_mk( "all" , all_targets, [ "echo done" ]) EOF python3 ./compiledb_to_makefile.py < compile_commands.json > compiledb.mk make -j `nproc` -f compiledb.mk -k all  
    • Build OnDeck
    • None
    • 1
    • Hour
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Some source files can't be compiled using the command from compile_commands.json.

      Most likely there are missing -I and -i flags pointing to directories with headers but other flags may be missing/different as well. 

      The impact of that is that clangd may not compile the code and code search / lint / macro expansions / iwyu don't work the expected way.

      Most errors I saw are like this:

      make: *** [compiledb.mk:3343: /home/ubuntu/mongo/.compiledb/compiledb-out/aarch64-dbg-ST-b7bb0a70eec4/bin/src/mongo/db/extension/test_examples/_objs/foo_mongo_extension_with_debug/foo.pic.o] Error 1
      In file included from src/mongo/db/extension/test_examples/fail_to_load/no_symbol.cpp:30:
      In file included from src/mongo/db/extension/sdk/extension_factory.h:32:
      In file included from src/mongo/db/extension/sdk/aggregation_stage.h:30:
      In file included from src/mongo/bson/bsonobj.h:32:
      src/mongo/base/data_type.h:32:10: fatal error: 'mongo/base/error_codes.h' file not found 

            Assignee:
            Daniel Moody
            Reporter:
            Serhii Lysenko
            Votes:
            2 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: