Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-24032

Clang: Remove CompilerOptionsBuilder's dependency to CLANG_VERSION /CLANG_RESOURCE_DIR macros where possible

    XMLWordPrintable

Details

    Description

      Observations

      1. The macros CLANG_VERSION /CLANG_RESOURCE_DIR are set by the build system, which queries bin/llvm-config for the corresponding values.
      2. ClangTools/ClangCodeModel and others depend on these macros due to the use of CompilerOptionsBuilder, but ideally shouldn't need them.
      3. CompilerOptionsBuilder constructs an include path list for the clang invocation and needs the include path from clang's "resource directory" (e.g. , /d2/llvm/10/vanilla/installs/Release/lib/clang/10.0.1/include) too - this include path is computed with the mentioned macros.

      Some background on this

      Why does CompilerOptionsBuilder fiddles about include paths at all and does not take just what the project manager provides as user-includes (-I) via ProjecPart?

      Our clang invocation should honor the toolchain set in the kit. Without pointing clang to the include paths of the kit's toolchain, it defaults to the toolchain detected in the system (e.g. highest gcc version found). While this might work out fine on Desktop, it will show for custom toolchains installed at non-standard locations.

      So our clang invocations contains -nostdinc, -nostdinc++ to reset what is auto-detected on the system by clang and -isystem args to provide the kit's toolchain built-in include paths.

      However, by providing -nostdinc the built-in resource directory include path of clang is removed, too. So when constructing the include path list, this one needs to be provided explicitly (and at the right position). That's why we currently need the resource path directory of clang...

      Proposals

      1. Ideal solution would be to somehow avoid explicitly providing the resource directory include path. Any idea?
      2. Try detecting the clang resource path at run-time (with a probe, once) as we could query it from the given tool binaries.
        $ /d2/llvm/10/vanilla/installs/Release/bin/clang -print-resource-dir
        /d2/llvm/10/vanilla/installs/Release/lib/clang/10.0.1
        
        $ /d2/llvm/10/vanilla/installs/Release/bin/clang-tidy /tmp/empty.cpp -- -print-resource-dir
        lib/clang/10.0.1
        Error while trying to load a compilation database:
        ...
        <snip>
        
        $ /d2/clazy/trunk/installs/Release/bin/clazy-standalone /tmp/empty.cpp -- -print-resource-dir
        lib/clang/8.0.0
        Error while trying to load a compilation database:
        ...
        <snip>
        

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kandeler Christian Kandeler
            kosjar Nikolai Kosjar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes