[clang] 47eec78 - [clang][deps] Remove hard-coded resource directory from tests
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 14 02:37:54 PST 2021
Author: Jan Svoboda
Date: 2021-12-14T10:59:47+01:00
New Revision: 47eec789ed9cc7d4cb9f1eaa0cafe3e509af015c
URL: https://github.com/llvm/llvm-project/commit/47eec789ed9cc7d4cb9f1eaa0cafe3e509af015c
DIFF: https://github.com/llvm/llvm-project/commit/47eec789ed9cc7d4cb9f1eaa0cafe3e509af015c.diff
LOG: [clang][deps] Remove hard-coded resource directory from tests
Dependency scanner test for resource directory deduction doesn't account for LLVM builds with custom `CLANG_RESOURCE_DIR`.
This patch ensures we don't hardcode the default behavior into the test and take into account the actual value. This is done by running `%clang -print-resource-dir` and using that as the expected value in test assertions.
New comment also clarifies this is different from running that command as part of the dependency scan.
Reviewed By: mgorny
Differential Revision: https://reviews.llvm.org/D115628
Added:
Modified:
clang/test/ClangScanDeps/resource_directory.c
Removed:
clang/test/ClangScanDeps/Inputs/resource_directory/compiler
################################################################################
diff --git a/clang/test/ClangScanDeps/Inputs/resource_directory/compiler b/clang/test/ClangScanDeps/Inputs/resource_directory/compiler
deleted file mode 100755
index edeb2a2fd0009..0000000000000
--- a/clang/test/ClangScanDeps/Inputs/resource_directory/compiler
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-echo "/custom/compiler/resources"
diff --git a/clang/test/ClangScanDeps/resource_directory.c b/clang/test/ClangScanDeps/resource_directory.c
index 6912aa9a19952..55d5d90bbcdea 100644
--- a/clang/test/ClangScanDeps/resource_directory.c
+++ b/clang/test/ClangScanDeps/resource_directory.c
@@ -5,21 +5,42 @@
// Deduce the resource directory from the compiler path.
//
-// RUN: sed -e "s|CLANG|/our/custom/bin/clang|g" -e "s|DIR|%/t|g" \
+// With `%clang-scan-deps --resource-dir-recipe modify-compiler-path`, the
+// resource directory should be identical to `%clang -print-resource-dir`.
+// (Assuming both binaries are built from the same Git checkout.)
+// Here we get the expected path by running `%clang -print-resource-dir` and
+// then verify `%clang-scan-deps` arrives at the same path by calling the
+// `Driver::GetResourcesPath` function.
+//
+// RUN: EXPECTED_RESOURCE_DIR=`%clang -print-resource-dir`
+// RUN: sed -e "s|CLANG|%clang|g" -e "s|DIR|%/t|g" \
// RUN: %S/Inputs/resource_directory/cdb.json.template > %t/cdb_path.json
+//
// RUN: clang-scan-deps -compilation-database %t/cdb_path.json --format experimental-full \
// RUN: --resource-dir-recipe modify-compiler-path > %t/result_path.json
-// RUN: cat %t/result_path.json | sed 's:\\\\\?:/:g' | FileCheck %s --check-prefix=CHECK-PATH
+// RUN: cat %t/result_path.json | sed 's:\\\\\?:/:g' \
+// RUN: | FileCheck %s --check-prefix=CHECK-PATH -DEXPECTED_RESOURCE_DIR="$EXPECTED_RESOURCE_DIR"
// CHECK-PATH: "-resource-dir"
-// CHECK-PATH-NEXT: "/our/custom/lib{{.*}}"
+// CHECK-PATH-NEXT: "[[EXPECTED_RESOURCE_DIR]]"
// Run the compiler and ask it for the resource directory.
//
+// With `%clang-scan-deps --resource-dir-recipe invoke-compiler`, the resource
+// directory should be identical to `<clang> -print-resource-dir`, where <clang>
+// is an arbitrary version of Clang. (This configuration is not really supported.)
+// Here we hard-code the expected path into `%t/compiler` and then verify
+// `%clang-scan-deps` arrives at the path by actually running the executable.
+//
+// RUN: EXPECTED_RESOURCE_DIR="/custom/compiler/resources"
+// RUN: echo "#!/bin/sh" > %t/compiler
+// RUN: echo "echo '$EXPECTED_RESOURCE_DIR'" >> %t/compiler
// RUN: chmod +x %t/compiler
// RUN: sed -e "s|CLANG|%/t/compiler|g" -e "s|DIR|%/t|g" \
// RUN: %S/Inputs/resource_directory/cdb.json.template > %t/cdb_invocation.json
+//
// RUN: clang-scan-deps -compilation-database %t/cdb_invocation.json --format experimental-full \
// RUN: --resource-dir-recipe invoke-compiler > %t/result_invocation.json
-// RUN: cat %t/result_invocation.json | sed 's:\\\\\?:/:g' | FileCheck %s --check-prefix=CHECK-INVOCATION
+// RUN: cat %t/result_invocation.json | sed 's:\\\\\?:/:g' \
+// RUN: | FileCheck %s --check-prefix=CHECK-PATH -DEXPECTED_RESOURCE_DIR="$EXPECTED_RESOURCE_DIR"
// CHECK-INVOCATION: "-resource-dir"
-// CHECK-INVOCATION-NEXT: "/custom/compiler/resources"
+// CHECK-INVOCATION-NEXT: "[[EXPECTED_RESOURCE_DIR]]"
More information about the cfe-commits
mailing list