Skip to content

Commit dcd444e

Browse files
committed
Fix the following CAS related test for Windows (#11494)
Clang :: ClangScanDeps/include-tree-with-pch.c (Cherry picked from commit 9a08d92)
1 parent d23a5d3 commit dcd444e

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

clang/test/ClangScanDeps/include-tree-with-pch.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@
55

66
// RUN: %clang -x c-header %t/prefix.h -target x86_64-apple-macos12 -o %t/prefix.pch -fdepscan=inline -fdepscan-include-tree -Xclang -fcas-path -Xclang %t/cas
77
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree -cas-path %t/cas > %t/result.txt
8-
// RUN: FileCheck %s -input-file %t/result.txt -DPREFIX=%/t
8+
// RUN: cat %t/result.txt | %PathSanitizingFileCheck --sanitize PREFIX=%/t %s
99

10-
// CHECK: {{.*}} - [[PREFIX]]/t.c
10+
// CHECK: {{.*}} - PREFIX{{/|\\}}t.c
1111
// CHECK-NEXT: (PCH)
12-
// CHECK-NEXT: [[PREFIX]]/t.c
12+
// CHECK-NEXT: PREFIX{{/|\\}}t.c
1313
// CHECK-NEXT: 1:1 <built-in>
14-
// CHECK-NEXT: [[PREFIX]]/t.h
14+
// CHECK-NEXT: PREFIX{{/|\\}}t.h
1515
// CHECK-NEXT: Files:
16-
// CHECK-NEXT: [[PREFIX]]/t.c
17-
// CHECK-NEXT: [[PREFIX]]/t.h
18-
// CHECK-NEXT: [[PREFIX]]/prefix.h
19-
// CHECK-NEXT: [[PREFIX]]/n1.h
20-
// CHECK-NEXT: [[PREFIX]]/n2.h
21-
// CHECK-NEXT: [[PREFIX]]/n3.h
22-
// CHECK-NOT: [[PREFIX]]
16+
// CHECK-NEXT: PREFIX{{/|\\}}t.c
17+
// CHECK-NEXT: PREFIX{{/|\\}}t.h
18+
// CHECK-NEXT: PREFIX{{/|\\}}prefix.h
19+
// CHECK-NEXT: PREFIX{{/|\\}}n1.h
20+
// CHECK-NEXT: PREFIX{{/|\\}}n2.h
21+
// CHECK-NEXT: PREFIX{{/|\\}}n3.h
22+
// CHECK-NOT: PREFIX
2323

2424
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree-full -cas-path %t/cas > %t/deps.json
2525

2626
// RUN: cat %t/result.txt > %t/full.txt
2727
// RUN: echo "FULL DEPS START" >> %t/full.txt
28-
// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' >> %t/full.txt
28+
// RUN: cat %t/deps.json >> %t/full.txt
2929

30-
// RUN: FileCheck %s -DPREFIX=%/t -DCLANG=%clang -check-prefix=FULL -input-file %t/full.txt
30+
// RUN: cat %t/full.txt | %PathSanitizingFileCheck --sanitize PREFIX=%/t --sanitize CLANG=%/clang --enable-yaml-compatibility -check-prefix=FULL %s
3131

3232
// Capture the tree id from experimental-include-tree ; ensure that it matches
3333
// the result from experimental-full.
34-
// FULL: [[TREE_ID:llvmcas://[[:xdigit:]]+]] - [[PREFIX]]/t.c
34+
// FULL: [[TREE_ID:llvmcas://[[:xdigit:]]+]] - PREFIX{{/|\\}}t.c
3535
// FULL: FULL DEPS START
3636

3737
// FULL-NEXT: {
@@ -44,7 +44,7 @@
4444
// FULL: "command-line": [
4545
// FULL-NEXT: "-cc1"
4646
// FULL: "-fcas-path"
47-
// FULL-NEXT: "[[PREFIX]]/cas"
47+
// FULL-NEXT: "PREFIX{{/|\\\\}}cas"
4848
// FULL: "-disable-free"
4949
// FULL: "-fcas-include-tree"
5050
// FULL-NEXT: "[[TREE_ID]]"
@@ -57,13 +57,13 @@
5757
// FULL-NEXT: "t.c"
5858
// FULL-NOT: "t.c"
5959
// FULL: ]
60-
// FULL: "executable": "[[CLANG]]"
60+
// FULL: "executable": "CLANG"
6161
// FULL: "file-deps": [
62-
// FULL-NEXT: "[[PREFIX]]/t.c"
63-
// FULL-NEXT: "[[PREFIX]]/t.h"
64-
// FULL-NEXT: "[[PREFIX]]/prefix.pch"
62+
// FULL-NEXT: "PREFIX{{/|\\\\}}t.c"
63+
// FULL-NEXT: "PREFIX{{/|\\\\}}t.h"
64+
// FULL-NEXT: "PREFIX{{/|\\\\}}prefix.pch"
6565
// FULL-NEXT: ]
66-
// FULL: "input-file": "[[PREFIX]]/t.c"
66+
// FULL: "input-file": "PREFIX{{/|\\\\}}t.c"
6767
// FULL: }
6868
// FULL: ]
6969
// FULL: }

clang/tools/driver/cc1depscan_main.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,17 @@
5959
#if LLVM_ON_UNIX
6060
#include <sys/file.h> // FIXME: Unix-only. Not portable.
6161
#include <sys/signal.h> // FIXME: Unix-only. Not portable.
62+
#endif // LLVM_ON_UNIX
6263

6364
#ifdef CLANG_HAVE_RLIMITS
6465
#include <sys/resource.h>
6566
#endif
6667

6768
using namespace clang;
6869
using namespace llvm::opt;
70+
#if LLVM_ON_UNIX
6971
using cc1depscand::DepscanSharing;
72+
#endif // LLVM_ON_UNIX
7073
using llvm::Error;
7174

7275
#define DEBUG_TYPE "cc1depscand"
@@ -203,6 +206,7 @@ class SharedStream {
203206
};
204207
} // namespace
205208

209+
#ifdef LLVM_ON_UNIX
206210
namespace {
207211
/// FIXME: Move to LLVMSupport; probably llvm/Support/Process.h.
208212
///
@@ -354,6 +358,7 @@ makeDepscanDaemonPath(StringRef Mode, const DepscanSharing &Sharing) {
354358

355359
return std::nullopt;
356360
}
361+
#endif // LLVM_ON_UNIX
357362

358363
static int
359364
scanAndUpdateCC1Inline(const char *Exec, ArrayRef<const char *> InputArgs,
@@ -371,6 +376,7 @@ static Expected<llvm::cas::CASID> scanAndUpdateCC1InlineWithTool(
371376
SmallVectorImpl<const char *> &OutputArgs, llvm::cas::ObjectStore &DB,
372377
llvm::function_ref<const char *(const Twine &)> SaveArg);
373378

379+
#ifdef LLVM_ON_UNIX
374380
static int scanAndUpdateCC1UsingDaemon(
375381
const char *Exec, ArrayRef<const char *> OldArgs,
376382
StringRef WorkingDirectory, SmallVectorImpl<const char *> &NewArgs,
@@ -432,6 +438,7 @@ static int scanAndUpdateCC1UsingDaemon(
432438

433439
return 0;
434440
}
441+
#endif // LLVM_ON_UNIX
435442

436443
// FIXME: This is a copy of Command::writeResponseFile. Command is too deeply
437444
// tied with clang::Driver to use directly.
@@ -480,6 +487,7 @@ static int scanAndUpdateCC1(const char *Exec, ArrayRef<const char *> OldArgs,
480487
}
481488

482489
// Collect these before returning to ensure they're claimed.
490+
#ifdef LLVM_ON_UNIX
483491
DepscanSharing Sharing;
484492
if (Arg *A = Args.getLastArg(options::OPT_fdepscan_share_stop_EQ))
485493
Sharing.Stop = A->getValue();
@@ -515,9 +523,11 @@ static int scanAndUpdateCC1(const char *Exec, ArrayRef<const char *> OldArgs,
515523
}
516524
}
517525

526+
#endif // LLVM_ON_UNIX
518527
bool ProduceIncludeTree = Args.hasArg(options::OPT_fdepscan_include_tree);
519528

520529
auto SaveArg = [&Args](const Twine &T) { return Args.MakeArgString(T); };
530+
#ifdef LLVM_ON_UNIX
521531
CompilerInvocation::GenerateCASArgs(CASOpts, Sharing.CASArgs, SaveArg);
522532
if (ProduceIncludeTree)
523533
Sharing.CASArgs.push_back("-fdepscan-include-tree");
@@ -526,6 +536,7 @@ static int scanAndUpdateCC1(const char *Exec, ArrayRef<const char *> OldArgs,
526536
return scanAndUpdateCC1UsingDaemon(Exec, OldArgs, WorkingDirectory, NewArgs,
527537
*DaemonPath, Sharing, Diag, SaveArg,
528538
CASOpts, RootID);
539+
#endif // LLVM_ON_UNIX
529540

530541
return scanAndUpdateCC1Inline(Exec, OldArgs, WorkingDirectory, NewArgs,
531542
ProduceIncludeTree, SaveArg, CASOpts, Diag,
@@ -626,6 +637,7 @@ int cc1depscan_main(ArrayRef<const char *> Argv, const char *Argv0,
626637
return 0;
627638
}
628639

640+
#ifdef LLVM_ON_UNIX
629641
namespace {
630642
struct ScanServer {
631643
const char *Argv0 = nullptr;
@@ -1079,6 +1091,7 @@ int ScanServer::listen() {
10791091

10801092
return 0;
10811093
}
1094+
#endif // LLVM_ON_UNIX
10821095

10831096
static Expected<llvm::cas::CASID> scanAndUpdateCC1InlineWithTool(
10841097
tooling::dependencies::DependencyScanningTool &Tool,
@@ -1151,4 +1164,3 @@ scanAndUpdateCC1Inline(const char *Exec, ArrayRef<const char *> InputArgs,
11511164

11521165
return DiagsConsumer->getNumErrors() != 0;
11531166
}
1154-
#endif /* LLVM_ON_UNIX */

clang/tools/driver/driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ extern int cc1_main(ArrayRef<const char *> Argv, const char *Argv0,
9292
#if LLVM_ON_UNIX
9393
extern int cc1depscand_main(ArrayRef<const char *> Argv, const char *Argv0,
9494
void *MainAddr);
95+
#endif /* LLVM_ON_UNIX */
9596
extern int cc1depscan_main(ArrayRef<const char *> Argv, const char *Argv0,
9697
void *MainAddr);
97-
#endif /* LLVM_ON_UNIX */
9898
extern int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0,
9999
void *MainAddr);
100100
extern int cc1gen_reproducer_main(ArrayRef<const char *> Argv,
@@ -250,10 +250,10 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV,
250250
if (Tool == "-cc1depscand")
251251
return cc1depscand_main(ArrayRef(ArgV).slice(2), ArgV[0],
252252
GetExecutablePathVP);
253+
#endif /* LLVM_ON_UNIX */
253254
if (Tool == "-cc1depscan")
254255
return cc1depscan_main(ArrayRef(ArgV).slice(2), ArgV[0],
255256
GetExecutablePathVP);
256-
#endif /* LLVM_ON_UNIX */
257257
if (Tool == "-cc1as")
258258
return cc1as_main(ArrayRef(ArgV).slice(2), ArgV[0], GetExecutablePathVP);
259259
if (Tool == "-cc1gen-reproducer")

0 commit comments

Comments
 (0)