Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-scan-deps] Infer the tool locations from PATH #108539

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

mstorsjo
Copy link
Member

This allows the clang driver to know which tool is meant to be executed, which allows the clang driver to load the right clang config files, and allows clang to find colocated sysroots.

This makes sure that doing clang-scan-deps -- <tool> ... looks up things in the same way as if one just would execute <tool> ..., when <tool> isn't an absolute or relative path.

This allows the clang driver to know which tool is meant to be
executed, which allows the clang driver to load the right clang
config files, and allows clang to find colocated sysroots.

This makes sure that doing `clang-scan-deps -- <tool> ...`
looks up things in the same way as if one just would execute
`<tool> ...`, when `<tool>` isn't an absolute or relative path.
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2024

@llvm/pr-subscribers-clang

Author: Martin Storsjö (mstorsjo)

Changes

This allows the clang driver to know which tool is meant to be executed, which allows the clang driver to load the right clang config files, and allows clang to find colocated sysroots.

This makes sure that doing clang-scan-deps -- &lt;tool&gt; ... looks up things in the same way as if one just would execute &lt;tool&gt; ..., when &lt;tool&gt; isn't an absolute or relative path.


Full diff: /~https://github.com/llvm/llvm-project/pull/108539.diff

12 Files Affected:

  • (modified) clang/include/clang/Tooling/CompilationDatabase.h (+6)
  • (modified) clang/lib/Tooling/CMakeLists.txt (+1)
  • (added) clang/lib/Tooling/LocateToolCompilationDatabase.cpp (+71)
  • (modified) clang/test/ClangScanDeps/modules-extern-submodule.c (+1-1)
  • (modified) clang/test/ClangScanDeps/modules-full-output-tu-order.c (+2-2)
  • (modified) clang/test/ClangScanDeps/modules-has-include-umbrella-header.c (+1-1)
  • (modified) clang/test/ClangScanDeps/modules-header-sharing.m (+1-1)
  • (modified) clang/test/ClangScanDeps/modules-implementation-module-map.c (+1-1)
  • (modified) clang/test/ClangScanDeps/modules-implementation-private.m (+1-1)
  • (modified) clang/test/ClangScanDeps/modules-priv-fw-from-pub.m (+1-1)
  • (added) clang/test/ClangScanDeps/resolve-executable-path.c (+32)
  • (modified) clang/tools/clang-scan-deps/ClangScanDeps.cpp (+2)
diff --git a/clang/include/clang/Tooling/CompilationDatabase.h b/clang/include/clang/Tooling/CompilationDatabase.h
index fee584acb48623..36fe0812ebe974 100644
--- a/clang/include/clang/Tooling/CompilationDatabase.h
+++ b/clang/include/clang/Tooling/CompilationDatabase.h
@@ -234,6 +234,12 @@ std::unique_ptr<CompilationDatabase>
 std::unique_ptr<CompilationDatabase>
 inferTargetAndDriverMode(std::unique_ptr<CompilationDatabase> Base);
 
+/// Returns a wrapped CompilationDatabase that will transform argv[0] to an
+/// absolute path, if it currently is a plain tool name, looking it up in
+/// PATH.
+std::unique_ptr<CompilationDatabase>
+inferToolLocation(std::unique_ptr<CompilationDatabase> Base);
+
 /// Returns a wrapped CompilationDatabase that will expand all rsp(response)
 /// files on commandline returned by underlying database.
 std::unique_ptr<CompilationDatabase>
diff --git a/clang/lib/Tooling/CMakeLists.txt b/clang/lib/Tooling/CMakeLists.txt
index 93a9e707a134cf..fc1f1f9f9d367e 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -25,6 +25,7 @@ add_clang_library(clangTooling
   GuessTargetAndModeCompilationDatabase.cpp
   InterpolatingCompilationDatabase.cpp
   JSONCompilationDatabase.cpp
+  LocateToolCompilationDatabase.cpp
   Refactoring.cpp
   RefactoringCallbacks.cpp
   StandaloneExecution.cpp
diff --git a/clang/lib/Tooling/LocateToolCompilationDatabase.cpp b/clang/lib/Tooling/LocateToolCompilationDatabase.cpp
new file mode 100644
index 00000000000000..033f69f3760c6d
--- /dev/null
+++ b/clang/lib/Tooling/LocateToolCompilationDatabase.cpp
@@ -0,0 +1,71 @@
+//===- GuessTargetAndModeCompilationDatabase.cpp --------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
+#include <memory>
+
+namespace clang {
+namespace tooling {
+
+namespace {
+class LocationAdderDatabase : public CompilationDatabase {
+public:
+  LocationAdderDatabase(std::unique_ptr<CompilationDatabase> Base)
+      : Base(std::move(Base)) {
+    assert(this->Base != nullptr);
+  }
+
+  std::vector<std::string> getAllFiles() const override {
+    return Base->getAllFiles();
+  }
+
+  std::vector<CompileCommand> getAllCompileCommands() const override {
+    return addLocation(Base->getAllCompileCommands());
+  }
+
+  std::vector<CompileCommand>
+  getCompileCommands(StringRef FilePath) const override {
+    return addLocation(Base->getCompileCommands(FilePath));
+  }
+
+private:
+  std::vector<CompileCommand>
+  addLocation(std::vector<CompileCommand> Cmds) const {
+    for (auto &Cmd : Cmds) {
+      if (Cmd.CommandLine.empty())
+        continue;
+      std::string &Driver = Cmd.CommandLine.front();
+      // If the driver name already is absolute, we don't need to do anything.
+      if (llvm::sys::path::is_absolute(Driver))
+        continue;
+      // If the name is a relative path, like bin/clang, we assume it's
+      // possible to resolve it and don't do anything about it either.
+      if (llvm::any_of(Driver,
+                       [](char C) { return llvm::sys::path::is_separator(C); }))
+        continue;
+      auto Absolute = llvm::sys::findProgramByName(Driver);
+      // If we found it in path, update the entry in Cmd.CommandLine
+      if (Absolute && llvm::sys::path::is_absolute(*Absolute))
+        Driver = std::move(*Absolute);
+    }
+    return Cmds;
+  }
+  std::unique_ptr<CompilationDatabase> Base;
+};
+} // namespace
+
+std::unique_ptr<CompilationDatabase>
+inferToolLocation(std::unique_ptr<CompilationDatabase> Base) {
+  return std::make_unique<LocationAdderDatabase>(std::move(Base));
+}
+
+} // namespace tooling
+} // namespace clang
diff --git a/clang/test/ClangScanDeps/modules-extern-submodule.c b/clang/test/ClangScanDeps/modules-extern-submodule.c
index 92f2c749dd2c30..196a9e695f66f7 100644
--- a/clang/test/ClangScanDeps/modules-extern-submodule.c
+++ b/clang/test/ClangScanDeps/modules-extern-submodule.c
@@ -112,7 +112,7 @@ module third {}
 // CHECK:                  "-fmodule-map-file=[[PREFIX]]/first/first/module.modulemap",
 // CHECK:                  "-fmodule-file=first=[[PREFIX]]/cache/{{.*}}/first-{{.*}}.pcm",
 // CHECK:                ],
-// CHECK-NEXT:           "executable": "clang",
+// CHECK-NEXT:           "executable": "{{.*}}clang",
 // CHECK-NEXT:           "file-deps": [
 // CHECK-NEXT:             "[[PREFIX]]/tu.m"
 // CHECK-NEXT:           ],
diff --git a/clang/test/ClangScanDeps/modules-full-output-tu-order.c b/clang/test/ClangScanDeps/modules-full-output-tu-order.c
index 04939826817fc1..794503d6507269 100644
--- a/clang/test/ClangScanDeps/modules-full-output-tu-order.c
+++ b/clang/test/ClangScanDeps/modules-full-output-tu-order.c
@@ -35,7 +35,7 @@
 // CHECK:                  "-D"
 // CHECK-NEXT:             "ONE"
 // CHECK:                ],
-// CHECK-NEXT:           "executable": "clang",
+// CHECK-NEXT:           "executable": "{{.*}}clang",
 // CHECK-NEXT:           "file-deps": [
 // CHECK-NEXT:             "[[PREFIX]]/tu.c"
 // CHECK-NEXT:           ],
@@ -52,7 +52,7 @@
 // CHECK:                  "-D"
 // CHECK-NEXT:             "TWO"
 // CHECK:                ],
-// CHECK-NEXT:           "executable": "clang",
+// CHECK-NEXT:           "executable": "{{.*}}clang",
 // CHECK-NEXT:           "file-deps": [
 // CHECK-NEXT:             "[[PREFIX]]/tu.c"
 // CHECK-NEXT:           ],
diff --git a/clang/test/ClangScanDeps/modules-has-include-umbrella-header.c b/clang/test/ClangScanDeps/modules-has-include-umbrella-header.c
index e9363b2e14b07a..78c5ffe11d2374 100644
--- a/clang/test/ClangScanDeps/modules-has-include-umbrella-header.c
+++ b/clang/test/ClangScanDeps/modules-has-include-umbrella-header.c
@@ -64,7 +64,7 @@ module Dependency { header "dependency.h" }
 // CHECK:                ],
 // CHECK-NEXT:           "command-line": [
 // CHECK:                ],
-// CHECK-NEXT:           "executable": "clang",
+// CHECK-NEXT:           "executable": "{{.*}}clang",
 // CHECK-NEXT:           "file-deps": [
 // CHECK-NEXT:             "[[PREFIX]]/tu.c"
 // CHECK-NEXT:           ],
diff --git a/clang/test/ClangScanDeps/modules-header-sharing.m b/clang/test/ClangScanDeps/modules-header-sharing.m
index ec94923ae8eeee..60fdf3aafa42d3 100644
--- a/clang/test/ClangScanDeps/modules-header-sharing.m
+++ b/clang/test/ClangScanDeps/modules-header-sharing.m
@@ -77,7 +77,7 @@
 // CHECK:                  "-fmodule-map-file=[[PREFIX]]/frameworks/A.framework/Modules/module.modulemap",
 // CHECK:                  "-fmodule-name=A",
 // CHECK:                ],
-// CHECK-NEXT:           "executable": "clang",
+// CHECK-NEXT:           "executable": "{{.*}}clang",
 // CHECK-NEXT:           "file-deps": [
 // CHECK-NEXT:             "[[PREFIX]]/tu.m",
 // CHECK-NEXT:             "[[PREFIX]]/shared/H.h"
diff --git a/clang/test/ClangScanDeps/modules-implementation-module-map.c b/clang/test/ClangScanDeps/modules-implementation-module-map.c
index d76d3157004699..d988faa35ab23d 100644
--- a/clang/test/ClangScanDeps/modules-implementation-module-map.c
+++ b/clang/test/ClangScanDeps/modules-implementation-module-map.c
@@ -27,7 +27,7 @@ framework module FWPrivate { header "private.h" }
 // CHECK:                "-fmodule-map-file=[[PREFIX]]/frameworks/FW.framework/Modules/module.private.modulemap",
 // CHECK:                "-fmodule-name=FWPrivate",
 // CHECK:              ],
-// CHECK-NEXT:         "executable": "clang",
+// CHECK-NEXT:         "executable": "{{.*}}clang",
 // CHECK-NEXT:         "file-deps": [
 // CHECK-NEXT:           "[[PREFIX]]/tu.m"
 // CHECK-NEXT:         ],
diff --git a/clang/test/ClangScanDeps/modules-implementation-private.m b/clang/test/ClangScanDeps/modules-implementation-private.m
index acc01017d66403..236e6ba9f0b783 100644
--- a/clang/test/ClangScanDeps/modules-implementation-private.m
+++ b/clang/test/ClangScanDeps/modules-implementation-private.m
@@ -62,7 +62,7 @@
 // CHECK-NEXT:           ],
 // CHECK-NEXT:           "command-line": [
 // CHECK:                ],
-// CHECK-NEXT:           "executable": "clang",
+// CHECK-NEXT:           "executable": "{{.*}}clang",
 // CHECK-NEXT:           "file-deps": [
 // CHECK-NEXT:             "[[PREFIX]]/tu.m",
 // CHECK-NEXT:             "[[PREFIX]]/frameworks/FW.framework/PrivateHeaders/Missed.h",
diff --git a/clang/test/ClangScanDeps/modules-priv-fw-from-pub.m b/clang/test/ClangScanDeps/modules-priv-fw-from-pub.m
index 4847fedac3bf6f..a7ac19b49431d3 100644
--- a/clang/test/ClangScanDeps/modules-priv-fw-from-pub.m
+++ b/clang/test/ClangScanDeps/modules-priv-fw-from-pub.m
@@ -110,7 +110,7 @@
 // CHECK-NEXT:           ],
 // CHECK-NEXT:           "command-line": [
 // CHECK:                ],
-// CHECK-NEXT:           "executable": "clang",
+// CHECK-NEXT:           "executable": "{{.*}}clang",
 // CHECK-NEXT:           "file-deps": [
 // CHECK-NEXT:             "[[PREFIX]]/tu.m"
 // CHECK-NEXT:           ],
diff --git a/clang/test/ClangScanDeps/resolve-executable-path.c b/clang/test/ClangScanDeps/resolve-executable-path.c
new file mode 100644
index 00000000000000..63e34ca256a8b4
--- /dev/null
+++ b/clang/test/ClangScanDeps/resolve-executable-path.c
@@ -0,0 +1,32 @@
+// UNSUPPORTED: system-windows
+
+// Check that we expand the executable name to an absolute path, when invoked
+// with a plain executable name, which is implied to be found in PATH.
+// REQUIRES: x86-registered-target
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/bin
+// RUN: ln -s %clang %t/bin/x86_64-w64-mingw32-clang
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
+
+// Check that we can deduce this both when using a compilation database, and when using
+// a literal command line.
+
+// RUN: env "PATH=%t/bin:%PATH%" clang-scan-deps -format experimental-full -compilation-database %t/cdb.json | FileCheck %s -DBASE=%/t
+
+// RUN: env "PATH=%t/bin:%PATH%" clang-scan-deps -format experimental-full -- x86_64-w64-mingw32-clang %t/source.c -o %t/source.o | FileCheck %s -DBASE=%/t
+
+// CHECK: "executable": "[[BASE]]/bin/x86_64-w64-mingw32-clang"
+
+//--- cdb.json.in
+[
+  {
+    "directory": "DIR"
+    "command": "x86_64-w64-mingw32-clang -c DIR/source.c -o DIR/source.o"
+    "file": "DIR/source.c"
+  },
+]
+
+//--- source.c
+void func(void) {}
diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
index 1db7245390f557..ac68e3605a10cb 100644
--- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -815,6 +815,8 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
 
   Compilations = inferTargetAndDriverMode(std::move(Compilations));
 
+  Compilations = inferToolLocation(std::move(Compilations));
+
   // The command options are rewritten to run Clang in preprocessor only mode.
   auto AdjustingCompilations =
       std::make_unique<tooling::ArgumentsAdjustingCompilations>(

@jansvoboda11
Copy link
Contributor

Can you explain why exactly is this necessary/beneficial? If the compilation database got created with just the tool name, I'd expect the rest of the build to be able to use just the tool name when the scanner spits it out again, no? If this is about the scanner finding the right config, sysroot, resource directory, etc., I'd expect that to already happen, since the scanner needs to be colocated with the toolchain itself (since clang and clang-scan-deps are effectively version-locked).

@mstorsjo
Copy link
Member Author

Can you explain why exactly is this necessary/beneficial? If the compilation database got created with just the tool name, I'd expect the rest of the build to be able to use just the tool name when the scanner spits it out again, no? If this is about the scanner finding the right config, sysroot, resource directory, etc., I'd expect that to already happen, since the scanner needs to be colocated with the toolchain itself (since clang and clang-scan-deps are effectively version-locked).

It's about the scanner finding the right config files and sysroot.

Even if clang-scan-deps is colocated with the toolchain, the tool never assumes that. Normally when you invoke clang to compile, it sets the executable directory so that within the clang::Driver class, Dir points to where clang resides.

Now when clang-scan-deps inspects one or more clang tool invocations, the clang::Driver class never gets set up with the Dir of the clang-scan-deps executable - it only sets things based on what it literally sees in the command lines, without any outside assumptions about default directory.

@mstorsjo
Copy link
Member Author

And practically - in the cases I've seen where CMake generates calls to clang-scan-deps, it always invokes clang-scan-deps ... -- /absolute/path/to/compiler (CMake in general is very keen on absolute paths to tools).

But in separate testing of these tools, I ran into this situation, where <triple>-clang ... works and picks up the <triple>.cfg config file next to the <triple>-clang executable, and finds the colocated sysroot. But when invoking clang-scan-deps -- <triple>-clang, where clang-scan-deps itself is colocated with the <triple>-clang binary, it didn't find the config file nor the sysroot.

@jansvoboda11
Copy link
Contributor

Ok, thanks for the explanation. This LGTM, but the checks are failing on Windows due to .exe extension that's not accounted for. I don't think any of the tests you touched really care about the executable path, so I'd be fine with just removing those check lines.

@mstorsjo
Copy link
Member Author

Ok, thanks for the explanation. This LGTM, but the checks are failing on Windows due to .exe extension that's not accounted for. I don't think any of the tests you touched really care about the executable path, so I'd be fine with just removing those check lines.

Ah, thanks. Yeah it's probably best that we remove those checks that don't carry much relevance there. (The main test that really exercise this functionality, that I'm adding here, has a UNSUPPORTED: system-windows marking due to using symlinks for setting up the PATH test environment though. But that's only an issue with the test - the implementation seems to work fine regardless, as noted when the other tests fail.)

@mstorsjo mstorsjo merged commit a26ec54 into llvm:main Sep 13, 2024
8 checks passed
@mstorsjo mstorsjo deleted the clang-scan-deps-search-path branch September 13, 2024 20:18
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 13, 2024

LLVM Buildbot has detected a new failure on builder clang-solaris11-sparcv9 running on solaris11-sparcv9 while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/13/builds/2197

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'Clang :: ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: rm -rf /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir
+ rm -rf /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir
RUN: at line 2: rm -rf /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/foodir
+ rm -rf /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/foodir
RUN: at line 3: rm -rf /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.cdb
+ rm -rf /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.cdb
RUN: at line 5: mkdir -p /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir
+ mkdir -p /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir
RUN: at line 6: mkdir -p /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/foodir
+ mkdir -p /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/foodir
RUN: at line 8: cp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/Inputs/header.h /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/foodir/foodirheader.h
+ cp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/Inputs/header.h /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/foodir/foodirheader.h
RUN: at line 9: cp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/headerwithdirname_input.cpp
+ cp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/headerwithdirname_input.cpp
RUN: at line 10: cp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/headerwithdirname_input_clangcl.cpp
+ cp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/headerwithdirname_input_clangcl.cpp
RUN: at line 11: mkdir /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/Inputs
+ mkdir /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/Inputs
RUN: at line 12: cp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/Inputs/foodir /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/Inputs/foodir
+ cp /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/Inputs/foodir /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/Inputs/foodir
RUN: at line 13: sed -e "s|DIR|/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir|g" /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json > /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.cdb
+ sed -e 's|DIR|/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir|g' /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/Inputs/headerwithdirnamefollowedbyinclude.json
RUN: at line 15: /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/clang-scan-deps -compilation-database /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.cdb -j 1 | /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/FileCheck /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
+ /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/clang-scan-deps -compilation-database /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.cdb -j 1
+ /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/bin/FileCheck /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp
/opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp:24:11: error: CHECK: expected string not found in input
// CHECK: headerwithdirname_input_clangcl.o
          ^
<stdin>:3:173: note: scanning from here
 /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/Inputs/foodir \
                                                                                                                                                                            ^
<stdin>:6:160: note: possible intended match here
 /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/headerwithdirname_input_clangcl.cpp \
                                                                                                                                                               ^

Input file: <stdin>
Check file: /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/llvm/clang/test/ClangScanDeps/headerwithdirnamefollowedbyinclude.cpp

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            1: headerwithdirname_input.o: \ 
            2:  /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/headerwithdirname_input.cpp \ 
            3:  /opt/llvm-buildbot/home/solaris11-sparcv9/clang-solaris11-sparcv9/stage1/tools/clang/test/ClangScanDeps/Output/headerwithdirnamefollowedbyinclude.cpp.tmp.dir/Inputs/foodir \ 
...

cachemeifyoucan added a commit to cachemeifyoucan/llvm-project that referenced this pull request Sep 16, 2024
Fix clang path output in clang-scan-deps output after upstream change
makes the tool to return full path to clang.
cachemeifyoucan added a commit to swiftlang/llvm-project that referenced this pull request Sep 17, 2024
Fix clang path output in clang-scan-deps output after upstream change
makes the tool to return full path to clang.
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Sep 24, 2024
This allows the clang driver to know which tool is meant to be executed,
which allows the clang driver to load the right clang config files, and
allows clang to find colocated sysroots.

This makes sure that doing `clang-scan-deps -- <tool> ...` looks up
things in the same way as if one just would execute `<tool> ...`, when
`<tool>` isn't an absolute or relative path.

(cherry picked from commit a26ec54)
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Oct 1, 2024
This allows the clang driver to know which tool is meant to be executed,
which allows the clang driver to load the right clang config files, and
allows clang to find colocated sysroots.

This makes sure that doing `clang-scan-deps -- <tool> ...` looks up
things in the same way as if one just would execute `<tool> ...`, when
`<tool>` isn't an absolute or relative path.

(cherry picked from commit a26ec54)
cachemeifyoucan added a commit to cachemeifyoucan/llvm-project that referenced this pull request Oct 3, 2024
Fix clang path output in clang-scan-deps output after upstream change
makes the tool to return full path to clang.

(cherry picked from commit 4b9ce22)
cachemeifyoucan added a commit to swiftlang/llvm-project that referenced this pull request Oct 3, 2024
Fix clang path output in clang-scan-deps output after upstream change
makes the tool to return full path to clang.

(cherry picked from commit 4b9ce22)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants