Skip to content

Commit 47eec78

Browse files
committed
[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
1 parent 15f8f3e commit 47eec78

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

clang/test/ClangScanDeps/Inputs/resource_directory/compiler

-3
This file was deleted.

clang/test/ClangScanDeps/resource_directory.c

+26-5
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,42 @@
55

66
// Deduce the resource directory from the compiler path.
77
//
8-
// RUN: sed -e "s|CLANG|/our/custom/bin/clang|g" -e "s|DIR|%/t|g" \
8+
// With `%clang-scan-deps --resource-dir-recipe modify-compiler-path`, the
9+
// resource directory should be identical to `%clang -print-resource-dir`.
10+
// (Assuming both binaries are built from the same Git checkout.)
11+
// Here we get the expected path by running `%clang -print-resource-dir` and
12+
// then verify `%clang-scan-deps` arrives at the same path by calling the
13+
// `Driver::GetResourcesPath` function.
14+
//
15+
// RUN: EXPECTED_RESOURCE_DIR=`%clang -print-resource-dir`
16+
// RUN: sed -e "s|CLANG|%clang|g" -e "s|DIR|%/t|g" \
917
// RUN: %S/Inputs/resource_directory/cdb.json.template > %t/cdb_path.json
18+
//
1019
// RUN: clang-scan-deps -compilation-database %t/cdb_path.json --format experimental-full \
1120
// RUN: --resource-dir-recipe modify-compiler-path > %t/result_path.json
12-
// RUN: cat %t/result_path.json | sed 's:\\\\\?:/:g' | FileCheck %s --check-prefix=CHECK-PATH
21+
// RUN: cat %t/result_path.json | sed 's:\\\\\?:/:g' \
22+
// RUN: | FileCheck %s --check-prefix=CHECK-PATH -DEXPECTED_RESOURCE_DIR="$EXPECTED_RESOURCE_DIR"
1323
// CHECK-PATH: "-resource-dir"
14-
// CHECK-PATH-NEXT: "/our/custom/lib{{.*}}"
24+
// CHECK-PATH-NEXT: "[[EXPECTED_RESOURCE_DIR]]"
1525

1626
// Run the compiler and ask it for the resource directory.
1727
//
28+
// With `%clang-scan-deps --resource-dir-recipe invoke-compiler`, the resource
29+
// directory should be identical to `<clang> -print-resource-dir`, where <clang>
30+
// is an arbitrary version of Clang. (This configuration is not really supported.)
31+
// Here we hard-code the expected path into `%t/compiler` and then verify
32+
// `%clang-scan-deps` arrives at the path by actually running the executable.
33+
//
34+
// RUN: EXPECTED_RESOURCE_DIR="/custom/compiler/resources"
35+
// RUN: echo "#!/bin/sh" > %t/compiler
36+
// RUN: echo "echo '$EXPECTED_RESOURCE_DIR'" >> %t/compiler
1837
// RUN: chmod +x %t/compiler
1938
// RUN: sed -e "s|CLANG|%/t/compiler|g" -e "s|DIR|%/t|g" \
2039
// RUN: %S/Inputs/resource_directory/cdb.json.template > %t/cdb_invocation.json
40+
//
2141
// RUN: clang-scan-deps -compilation-database %t/cdb_invocation.json --format experimental-full \
2242
// RUN: --resource-dir-recipe invoke-compiler > %t/result_invocation.json
23-
// RUN: cat %t/result_invocation.json | sed 's:\\\\\?:/:g' | FileCheck %s --check-prefix=CHECK-INVOCATION
43+
// RUN: cat %t/result_invocation.json | sed 's:\\\\\?:/:g' \
44+
// RUN: | FileCheck %s --check-prefix=CHECK-PATH -DEXPECTED_RESOURCE_DIR="$EXPECTED_RESOURCE_DIR"
2445
// CHECK-INVOCATION: "-resource-dir"
25-
// CHECK-INVOCATION-NEXT: "/custom/compiler/resources"
46+
// CHECK-INVOCATION-NEXT: "[[EXPECTED_RESOURCE_DIR]]"

0 commit comments

Comments
 (0)