Skip to content

Commit 9e5bb53

Browse files
committed
Fix a case where the hash should ignore cwd but still includs it through -working-directory.
1 parent 8f79f1b commit 9e5bb53

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,11 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
492492
HashBuilder.add(getClangFullRepositoryVersion());
493493
HashBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR);
494494
llvm::ErrorOr<std::string> CWD = VFS.getCurrentWorkingDirectory();
495+
auto &FSOpts = const_cast<FileSystemOptions &>(CI.getFileSystemOpts());
495496
if (CWD && !IgnoreCWD)
496497
HashBuilder.add(*CWD);
498+
else
499+
FSOpts.WorkingDir.clear();
497500

498501
// Hash the BuildInvocation without any input files.
499502
SmallString<0> ArgVec;

clang/test/ClangScanDeps/modules-context-hash-cwd.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
// RUN: sed -e "s|DIR|%/t|g" %t/cdb1.json.in > %t/cdb1.json
99
// RUN: sed -e "s|DIR|%/t|g" %t/cdb3.json.in > %t/cdb3.json
1010
// RUN: sed -e "s|DIR|%/t|g" %t/cdb4.json.in > %t/cdb4.json
11+
// RUN: sed -e "s|DIR|%/t|g" %t/cdb5.json.in > %t/cdb5.json
1112
// RUN: clang-scan-deps -compilation-database %t/cdb0.json -format experimental-full > %t/result0.json
1213
// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full > %t/result1.json
1314
// It is not a typo to use cdb1.json for result2. We intend to use the same
1415
// compilation database, but different clang-scan-deps optimize-args options.
1516
// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full -optimize-args=header-search,system-warnings,vfs,canonicalize-macros > %t/result2.json
1617
// RUN: clang-scan-deps -compilation-database %t/cdb3.json -format experimental-full > %t/result3.json
1718
// RUN: clang-scan-deps -compilation-database %t/cdb4.json -format experimental-full > %t/result4.json
19+
// RUN: clang-scan-deps -compilation-database %t/cdb5.json -format experimental-full > %t/result5.json
1820
// RUN: cat %t/result0.json %t/result1.json | FileCheck %s
1921
// RUN: cat %t/result0.json %t/result2.json | FileCheck %s -check-prefix=SKIPOPT
2022
// RUN: cat %t/result3.json %t/result4.json | FileCheck %s -check-prefix=RELPATH
23+
// RUN: cat %t/result0.json %t/result5.json | FileCheck %s
2124

2225
//--- cdb0.json.in
2326
[{
@@ -48,6 +51,14 @@
4851
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fprebuilt-module-path=.././module -IDIR/include/ -o DIR/tu.o ",
4952
"file": "DIR/tu.c"
5053
}]
54+
55+
//--- cdb5.json.in
56+
[{
57+
"directory": "DIR",
58+
"command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/include/ -Xclang -working-directory=DIR/a/ -o DIR/tu.o",
59+
"file": "DIR/tu.c"
60+
}]
61+
5162
//--- include/module.modulemap
5263
module mod {
5364
header "mod.h"
@@ -58,9 +69,9 @@ module mod {
5869
//--- tu.c
5970
#include "mod.h"
6071

61-
// Check that result0 and result1 compute the same hash with optimization
62-
// on. The only difference between result0 and result1 is the compiler's
63-
// working directory.
72+
// Check that result0 and result1/result5 compute the same hash with
73+
// optimization on. The only difference between result0 and result1/result5 is
74+
// the compiler's working directory.
6475
// CHECK: {
6576
// CHECK-NEXT: "modules": [
6677
// CHECK-NEXT: {

0 commit comments

Comments
 (0)