From 93f5107b390f35e5dce2bd0edcd50ca609ce6daf Mon Sep 17 00:00:00 2001 From: Hiroshi Yamauchi Date: Tue, 26 Aug 2025 13:35:19 -0700 Subject: [PATCH] Implement more precise path matching in some CAS tests --- clang/test/ClangScanDeps/include-tree.c | 26 ++-- .../ClangScanDeps/modules-cas-context-hash.c | 6 +- .../modules-cas-full-by-mod-name.c | 22 ++-- .../modules-include-tree-submodules.c | 16 +-- .../modules-include-tree-with-pch.c | 28 ++--- .../test/ClangScanDeps/modules-include-tree.c | 112 ++++++++--------- clang/test/lit.cfg.py | 12 ++ clang/utils/PathSanitizingFileCheck | 115 ++++++++++++++++++ llvm/utils/lit/lit/llvm/config.py | 3 + 9 files changed, 235 insertions(+), 105 deletions(-) create mode 100644 clang/utils/PathSanitizingFileCheck diff --git a/clang/test/ClangScanDeps/include-tree.c b/clang/test/ClangScanDeps/include-tree.c index 9778b979ac7f7..5d9fbf8d06926 100644 --- a/clang/test/ClangScanDeps/include-tree.c +++ b/clang/test/ClangScanDeps/include-tree.c @@ -34,13 +34,13 @@ // RUN: cat %t/result1.txt > %t/full.txt // RUN: echo "FULL DEPS START" >> %t/full.txt -// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' >> %t/full.txt +// RUN: cat %t/deps.json >> %t/full.txt -// RUN: FileCheck %s -DPREFIX=%/t -DCLANG=%clang -check-prefix=FULL -input-file %t/full.txt +// RUN: cat %t/full.txt | %PathSanitizingFileCheck --sanitize PREFIX=%/t --sanitize CLANG=%/clang --enable-yaml-compatibility %s -check-prefix=FULL // Capture the tree id from experimental-include-tree ; ensure that it matches // the result from experimental-full. -// FULL: [[TREE_ID:llvmcas://[[:xdigit:]]+]] - [[PREFIX]]{{[/\\]}}t.c +// FULL: [[TREE_ID:llvmcas://[[:xdigit:]]+]] - PREFIX{{/|\\}}t.c // FULL: FULL DEPS START // FULL-NEXT: { @@ -54,7 +54,7 @@ // FULL: "command-line": [ // FULL-NEXT: "-cc1" // FULL: "-fcas-path" -// FULL-NEXT: "[[PREFIX]]/cas" +// FULL-NEXT: "PREFIX{{/|\\\\}}cas" // FULL: "-disable-free" // FULL: "-fcas-include-tree" // FULL-NEXT: "[[TREE_ID]]" @@ -67,17 +67,17 @@ // FULL-NEXT: "t.c" // FULL-NOT: "t.c" // FULL: ] -// FULL: "{{.*[\\/]clang(\.exe)?}}", +// FULL: "executable": "CLANG", // FULL: "file-deps": [ -// FULL-NEXT: "[[PREFIX]]/t.c" -// FULL-NEXT: "[[PREFIX]]/top.h" -// FULL-NEXT: "[[PREFIX]]/n1.h" -// FULL-NEXT: "[[PREFIX]]/n2.h" -// FULL-NEXT: "[[PREFIX]]/n3.h" -// FULL-NEXT: "[[PREFIX]]/n3.h" -// FULL-NEXT: "[[PREFIX]]/n2.h" +// FULL-NEXT: "PREFIX{{/|\\\\}}t.c" +// FULL-NEXT: "PREFIX{{/|\\\\}}top.h" +// FULL-NEXT: "PREFIX{{/|\\\\}}n1.h" +// FULL-NEXT: "PREFIX{{/|\\\\}}n2.h" +// FULL-NEXT: "PREFIX{{/|\\\\}}n3.h" +// FULL-NEXT: "PREFIX{{/|\\\\}}n3.h" +// FULL-NEXT: "PREFIX{{/|\\\\}}n2.h" // FULL-NEXT: ] -// FULL: "input-file": "[[PREFIX]]/t.c" +// FULL: "input-file": "PREFIX{{/|\\\\}}t.c" // FULL: } // FULL: ] // FULL: } diff --git a/clang/test/ClangScanDeps/modules-cas-context-hash.c b/clang/test/ClangScanDeps/modules-cas-context-hash.c index 859c5f63c9820..3ff42bbe08743 100644 --- a/clang/test/ClangScanDeps/modules-cas-context-hash.c +++ b/clang/test/ClangScanDeps/modules-cas-context-hash.c @@ -12,7 +12,7 @@ // RUN: -cas-path %t/cas2 -format experimental-include-tree-full \ // RUN: >> %t/result.json -// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t +// RUN: cat %t/result.json | %PathSanitizingFileCheck --sanitize PREFIX=%/t --enable-yaml-compatibility %s // CHECK: "modules": [ // CHECK: { @@ -33,7 +33,7 @@ // CHECK: ], // CHECK: "command-line": [ // CHECK: "-fmodule-file-cache-key" -// CHECK: "[[PREFIX]]/outputs/[[HASH]]/Mod-[[HASH]].pcm" +// CHECK: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}[[HASH]]{{/|\\\\}}Mod-[[HASH]].pcm" // CHECK: "llvmcas://[[KEY]]" // CHECK: ] @@ -57,7 +57,7 @@ // CHECK: ], // CHECK: "command-line": [ // CHECK: "-fmodule-file-cache-key" -// CHECK: "[[PREFIX]]/outputs/[[HASH]]/Mod-[[HASH]].pcm" +// CHECK: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}[[HASH]]{{/|\\\\}}Mod-[[HASH]].pcm" // CHECK: "llvmcas://[[KEY]]" // CHECK: ] diff --git a/clang/test/ClangScanDeps/modules-cas-full-by-mod-name.c b/clang/test/ClangScanDeps/modules-cas-full-by-mod-name.c index 957e383e2cb99..4a6603641d4c7 100644 --- a/clang/test/ClangScanDeps/modules-cas-full-by-mod-name.c +++ b/clang/test/ClangScanDeps/modules-cas-full-by-mod-name.c @@ -30,7 +30,7 @@ module transitive { header "transitive.h" } // RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json // RUN: clang-scan-deps -compilation-database %t/cdb.json \ // RUN: -cas-path %t/cas -format experimental-full -module-name=root > %t/result.json -// RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck -DPREFIX=%/t %s +// RUN: cat %t/result.json | %PathSanitizingFileCheck --sanitize PREFIX=%/t --enable-yaml-compatibility %s // CHECK: { // CHECK-NEXT: "modules": [ @@ -43,7 +43,7 @@ module transitive { header "transitive.h" } // CHECK-NEXT: "module-name": "transitive" // CHECK-NEXT: } // CHECK-NEXT: ], -// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap", +// CHECK-NEXT: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap", // CHECK-NEXT: "command-line": [ // CHECK: "-fmodule-file-cache-key" // CHECK-NEXT: "{{.*transitive-.*\.pcm}}" @@ -51,8 +51,8 @@ module transitive { header "transitive.h" } // CHECK: ], // CHECK-NEXT: "context-hash": "{{.*}}", // CHECK-NEXT: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/direct.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}direct.h" // CHECK-NEXT: ], // CHECK-NEXT: "link-libraries": [], // CHECK-NEXT: "name": "direct" @@ -66,7 +66,7 @@ module transitive { header "transitive.h" } // CHECK-NEXT: "module-name": "direct" // CHECK-NEXT: } // CHECK-NEXT: ], -// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap", +// CHECK-NEXT: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap", // CHECK-NEXT: "command-line": [ // CHECK: "-fmodule-file-cache-key" // CHECK-NEXT: "{{.*direct-.*\.pcm}}" @@ -74,9 +74,9 @@ module transitive { header "transitive.h" } // CHECK: ], // CHECK-NEXT: "context-hash": "{{.*}}", // CHECK-NEXT: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/root.h" -// CHECK-NEXT: "[[PREFIX]]/root/textual.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}root.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}root{{/|\\\\}}textual.h" // CHECK-NEXT: ], // CHECK-NEXT: "link-libraries": [], // CHECK-NEXT: "name": "root" @@ -85,13 +85,13 @@ module transitive { header "transitive.h" } // CHECK-NEXT: "cache-key": "[[TRANSITIVE_CACHE_KEY]]" // CHECK-NEXT: "casfs-root-id": "[[LEFT_ROOT_ID]]" // CHECK-NEXT: "clang-module-deps": [], -// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap", +// CHECK-NEXT: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap", // CHECK-NEXT: "command-line": [ // CHECK: ], // CHECK-NEXT: "context-hash": "{{.*}}", // CHECK-NEXT: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/transitive.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}transitive.h" // CHECK-NEXT: ], // CHECK-NEXT: "link-libraries": [], // CHECK-NEXT: "name": "transitive" diff --git a/clang/test/ClangScanDeps/modules-include-tree-submodules.c b/clang/test/ClangScanDeps/modules-include-tree-submodules.c index 772400ac9705a..d6963dff9edcf 100644 --- a/clang/test/ClangScanDeps/modules-include-tree-submodules.c +++ b/clang/test/ClangScanDeps/modules-include-tree-submodules.c @@ -30,7 +30,7 @@ // RUN: echo "TRANSLATION UNIT 2" >> %t/result.txt // RUN: clang-cas-test -cas %t/cas -print-include-tree @%t/tu2.casid >> %t/result.txt -// RUN: cat %t/result.txt | sed 's/\\/\//g' | FileCheck %s -DPREFIX=%/t +// RUN: cat %t/result.txt | %PathSanitizingFileCheck --sanitize PREFIX=%/t %s // Build the include-tree commands // RUN: %clang @%t/TwoSubs.rsp @@ -39,27 +39,27 @@ // RUN: not %clang @%t/tu2.rsp 2>&1 | FileCheck %s -check-prefix=TU2 // CHECK: MODULE TwoSubs -// CHECK: 2:1 [[PREFIX]]/Sub1.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: 2:1 PREFIX{{/|\\}}Sub1.h llvmcas://{{[[:xdigit:]]+}} // CHECK: Submodule: TwoSubs.Sub1 -// CHECK: 3:1 [[PREFIX]]/Sub2.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: 3:1 PREFIX{{/|\\}}Sub2.h llvmcas://{{[[:xdigit:]]+}} // CHECK: Submodule: TwoSubs.Sub2 // CHECK: MODULE WithExplicit -// CHECK: 2:1 [[PREFIX]]/TopLevel.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: 2:1 PREFIX{{/|\\}}TopLevel.h llvmcas://{{[[:xdigit:]]+}} // CHECK: Submodule: WithExplicit -// CHECK: 3:1 [[PREFIX]]/Implicit.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: 3:1 PREFIX{{/|\\}}Implicit.h llvmcas://{{[[:xdigit:]]+}} // CHECK: Submodule: WithExplicit.Implicit -// CHECK: 4:1 [[PREFIX]]/Explicit.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: 4:1 PREFIX{{/|\\}}Explicit.h llvmcas://{{[[:xdigit:]]+}} // CHECK: Submodule: WithExplicit.Explicit // CHECK: TRANSLATION UNIT 1 -// CHECK: [[PREFIX]]/tu1.c llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}tu1.c llvmcas://{{[[:xdigit:]]+}} // CHECK: 1:1 llvmcas://{{[[:xdigit:]]+}} // CHECK: 2:1 (Module) TwoSubs.Sub1 // CHECK: 3:1 (Module) WithExplicit // CHECK: TRANSLATION UNIT 2 -// CHECK: [[PREFIX]]/tu2.c llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}tu2.c llvmcas://{{[[:xdigit:]]+}} // CHECK: 1:1 llvmcas://{{[[:xdigit:]]+}} // CHECK: 2:1 (Module) TwoSubs.Sub2 // CHECK: 3:1 (Module) WithExplicit.Explicit diff --git a/clang/test/ClangScanDeps/modules-include-tree-with-pch.c b/clang/test/ClangScanDeps/modules-include-tree-with-pch.c index 8f247be56bba3..c9300de986180 100644 --- a/clang/test/ClangScanDeps/modules-include-tree-with-pch.c +++ b/clang/test/ClangScanDeps/modules-include-tree-with-pch.c @@ -34,28 +34,28 @@ // RUN: rm -rf %t/outputs // RUN: %clang @%t/tu.rsp -// RUN: cat %t/deps.json | sed 's/\\\\/\//g' | FileCheck %s -DPREFIX=%/t +// RUN: cat %t/deps.json | %PathSanitizingFileCheck --sanitize PREFIX=%/t --enable-yaml-compatibility %s // CHECK: { // CHECK-NEXT: "modules": [ // CHECK-NEXT: { // CHECK: "clang-module-deps": [] -// CHECK: "clang-modulemap-file": "[[PREFIX]]/module.modulemap" +// CHECK: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap" // CHECK: "command-line": [ // CHECK-NEXT: "-cc1" // CHECK: "-fcas-path" -// CHECK-NEXT: "[[PREFIX]]/cas" +// CHECK-NEXT: "PREFIX{{/|\\\\}}cas" // CHECK: "-o" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Right-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Right-{{.*}}.pcm" // CHECK: "-disable-free" // CHECK: "-fno-pch-timestamp" // CHECK: "-fcas-include-tree" // CHECK-NEXT: "[[RIGHT_TREE:llvmcas://[[:xdigit:]]+]]" // CHECK: "-fcache-compile-job" // CHECK: "-emit-module" -// CHECK: "-fmodule-file=[[PREFIX]]/outputs/{{.*}}/Top-{{.*}}.pcm" +// CHECK: "-fmodule-file=PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Top-{{.*}}.pcm" // CHECK: "-fmodule-file-cache-key" -// CHECK-NEXT: "[[PREFIX]]/{{.*}}/Top-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}{{.*}}{{/|\\\\}}Top-{{.*}}.pcm" // CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}" // CHECK: "-x" // CHECK-NEXT: "c" @@ -64,8 +64,8 @@ // CHECK: "-fno-implicit-modules" // CHECK: ] // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/Right.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}Right.h" // CHECK-NEXT: ] // CHECK: "name": "Right" // CHECK: } @@ -83,7 +83,7 @@ // CHECK: "command-line": [ // CHECK-NEXT: "-cc1" // CHECK: "-fcas-path" -// CHECK-NEXT: "[[PREFIX]]/cas" +// CHECK-NEXT: "PREFIX{{/|\\\\}}cas" // CHECK-NOT: -fmodule-map-file= // CHECK: "-disable-free" // CHECK: "-fcas-include-tree" @@ -91,19 +91,19 @@ // CHECK: "-fcache-compile-job" // CHECK: "-fsyntax-only" // CHECK: "-fmodule-file-cache-key" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Right-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Right-{{.*}}.pcm" // CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}" // CHECK: "-x" // CHECK-NEXT: "c" -// CHECK: "-fmodule-file=Right=[[PREFIX]]/outputs/{{.*}}/Right-{{.*}}.pcm" +// CHECK: "-fmodule-file=Right=PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Right-{{.*}}.pcm" // CHECK: "-fmodules" // CHECK: "-fno-implicit-modules" // CHECK: ] // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/tu.c" -// CHECK-NEXT: "[[PREFIX]]/prefix.h.pch" +// CHECK-NEXT: "PREFIX{{/|\\\\}}tu.c" +// CHECK-NEXT: "PREFIX{{/|\\\\}}prefix.h.pch" // CHECK-NEXT: ] -// CHECK: "input-file": "[[PREFIX]]/tu.c" +// CHECK: "input-file": "PREFIX{{/|\\\\}}tu.c" // CHECK: } // CHECK-NEXT: ] // CHECK-NEXT: } diff --git a/clang/test/ClangScanDeps/modules-include-tree.c b/clang/test/ClangScanDeps/modules-include-tree.c index b29aabecffd5f..46485b1f99ff0 100644 --- a/clang/test/ClangScanDeps/modules-include-tree.c +++ b/clang/test/ClangScanDeps/modules-include-tree.c @@ -33,50 +33,50 @@ // RUN: clang-cas-test -cas %t/cas -print-include-tree @%t/tu.casid >> %t/result.txt // RUN: cat %t/deps.json >> %t/result.txt -// RUN: cat %t/result.txt | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t +// RUN: cat %t/result.txt | %PathSanitizingFileCheck --sanitize PREFIX=%/t --enable-yaml-compatibility %s // CHECK-LABEL: MODULE Top // CHECK: llvmcas://{{[[:xdigit:]]+}} // CHECK: 1:1 llvmcas://{{[[:xdigit:]]+}} -// CHECK: 2:1 [[PREFIX]]/Top.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: 2:1 PREFIX{{/|\\}}Top.h llvmcas://{{[[:xdigit:]]+}} // CHECK: Module Map: // CHECK: Top // CHECK: export * // CHECK: Files: -// CHECK-NOT: [[PREFIX]]/module.modulemap -// CHECK: [[PREFIX]]/Top.h llvmcas://{{[[:xdigit:]]+}} -// CHECK-NOT: [[PREFIX]]/module.modulemap +// CHECK-NOT: PREFIX{{/|\\}}module.modulemap +// CHECK: PREFIX{{/|\\}}Top.h llvmcas://{{[[:xdigit:]]+}} +// CHECK-NOT: PREFIX{{/|\\}}module.modulemap // CHECK-LABEL: MODULE Left // CHECK: llvmcas://{{[[:xdigit:]]+}} // CHECK: 1:1 llvmcas://{{[[:xdigit:]]+}} -// CHECK: 2:1 [[PREFIX]]/Left.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: 2:1 PREFIX{{/|\\}}Left.h llvmcas://{{[[:xdigit:]]+}} // CHECK: 2:1 (Module) Top // CHECK: Module Map: // CHECK: Left // CHECK: export * // CHECK: Files: -// CHECK-NOT: [[PREFIX]]/module.modulemap llvmcas://{{[[:xdigit:]]+}} -// CHECK: [[PREFIX]]/Left.h llvmcas://{{[[:xdigit:]]+}} -// CHECK-NOT: [[PREFIX]]/module.modulemap llvmcas://{{[[:xdigit:]]+}} -// CHECK: [[PREFIX]]/Top.h llvmcas://{{[[:xdigit:]]+}} +// CHECK-NOT: PREFIX{{/|\\}}module.modulemap llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}Left.h llvmcas://{{[[:xdigit:]]+}} +// CHECK-NOT: PREFIX{{/|\\}}module.modulemap llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}Top.h llvmcas://{{[[:xdigit:]]+}} // CHECK-LABEL: MODULE Right // CHECK: llvmcas://{{[[:xdigit:]]+}} // CHECK: 1:1 llvmcas://{{[[:xdigit:]]+}} -// CHECK: 2:1 [[PREFIX]]/Right.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: 2:1 PREFIX{{/|\\}}Right.h llvmcas://{{[[:xdigit:]]+}} // CHECK: 2:1 (Module) Top // CHECK: Module Map: // CHECK: Right // CHECK: export * // CHECK: Files: -// CHECK-NOT: [[PREFIX]]/module.modulemap llvmcas://{{[[:xdigit:]]+}} -// CHECK: [[PREFIX]]/Right.h llvmcas://{{[[:xdigit:]]+}} -// CHECK-NOT: [[PREFIX]]/module.modulemap llvmcas://{{[[:xdigit:]]+}} -// CHECK: [[PREFIX]]/Top.h llvmcas://{{[[:xdigit:]]+}} +// CHECK-NOT: PREFIX{{/|\\}}module.modulemap llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}Right.h llvmcas://{{[[:xdigit:]]+}} +// CHECK-NOT: PREFIX{{/|\\}}module.modulemap llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}Top.h llvmcas://{{[[:xdigit:]]+}} // CHECK-LABEL: TRANSLATION UNIT -// CHECK: [[PREFIX]]/tu.m llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}tu.m llvmcas://{{[[:xdigit:]]+}} // CHECK: 1:1 llvmcas://{{[[:xdigit:]]+}} // CHECK: 2:1 (Module) Left // CHECK: 3:1 (Module) Right @@ -87,10 +87,10 @@ // CHECK-NOT: Module Map // CHECK: Files: -// CHECK-NOT: [[PREFIX]]/module.modulemap llvmcas://{{[[:xdigit:]]+}} -// CHECK: [[PREFIX]]/Left.h llvmcas://{{[[:xdigit:]]+}} -// CHECK: [[PREFIX]]/Top.h llvmcas://{{[[:xdigit:]]+}} -// CHECK: [[PREFIX]]/Right.h llvmcas://{{[[:xdigit:]]+}} +// CHECK-NOT: PREFIX{{/|\\}}module.modulemap llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}Left.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}Top.h llvmcas://{{[[:xdigit:]]+}} +// CHECK: PREFIX{{/|\\}}Right.h llvmcas://{{[[:xdigit:]]+}} // CHECK: { // CHECK-NEXT "modules": [ @@ -101,14 +101,14 @@ // CHECK: "module-name": "Top" // CHECK: } // CHECK-NEXT: ] -// CHECK: "clang-modulemap-file": "[[PREFIX]]/module.modulemap" +// CHECK: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap" // CHECK: "command-line": [ // CHECK-NEXT: "-cc1" // CHECK: "-fcas-path" -// CHECK-NEXT: "[[PREFIX]]/cas" +// CHECK-NEXT: "PREFIX{{/|\\\\}}cas" // CHECK-NOT: -fmodule-map-file // CHECK: "-o" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Left-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Left-{{.*}}.pcm" // CHECK: "-disable-free" // CHECK: "-fno-pch-timestamp" // CHECK: "-fcas-include-tree" @@ -116,16 +116,16 @@ // CHECK: "-fcache-compile-job" // CHECK: "-emit-module" // CHECK: "-fmodule-file-cache-key" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Top-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Top-{{.*}}.pcm" // CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}" -// CHECK: "-fmodule-file=Top=[[PREFIX]]/outputs/{{.*}}/Top-{{.*}}.pcm" +// CHECK: "-fmodule-file=Top=PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Top-{{.*}}.pcm" // CHECK: "-fmodules" // CHECK: "-fmodule-name=Left" // CHECK: "-fno-implicit-modules" // CHECK: ] // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/Left.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}Left.h" // CHECK: ] // CHECK: "name": "Left" // CHECK: } @@ -136,14 +136,14 @@ // CHECK: "module-name": "Top" // CHECK: } // CHECK-NEXT: ] -// CHECK: "clang-modulemap-file": "[[PREFIX]]/module.modulemap" +// CHECK: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap" // CHECK: "command-line": [ // CHECK-NEXT: "-cc1" // CHECK: "-fcas-path" -// CHECK-NEXT: "[[PREFIX]]/cas" +// CHECK-NEXT: "PREFIX{{/|\\\\}}cas" // CHECK-NOT: -fmodule-map-file // CHECK: "-o" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Right-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Right-{{.*}}.pcm" // CHECK: "-disable-free" // CHECK: "-fno-pch-timestamp" // CHECK: "-fcas-include-tree" @@ -151,29 +151,29 @@ // CHECK: "-fcache-compile-job" // CHECK: "-emit-module" // CHECK: "-fmodule-file-cache-key -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Top-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Top-{{.*}}.pcm" // CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}" -// CHECK: "-fmodule-file=Top=[[PREFIX]]/outputs/{{.*}}/Top-{{.*}}.pcm" +// CHECK: "-fmodule-file=Top=PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Top-{{.*}}.pcm" // CHECK: "-fmodules" // CHECK: "-fmodule-name=Right" // CHECK: "-fno-implicit-modules" // CHECK: ] // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/Right.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}Right.h" // CHECK-NEXT: ] // CHECK: "name": "Right" // CHECK: } // CHECK-NEXT: { // CHECK: "cas-include-tree-id": "[[TOP_TREE:llvmcas://[[:xdigit:]]+]]" // CHECK: "clang-module-deps": [] -// CHECK: "clang-modulemap-file": "[[PREFIX]]/module.modulemap" +// CHECK: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap" // CHECK: "command-line": [ // CHECK-NEXT: "-cc1" // CHECK: "-fcas-path" -// CHECK-NEXT: "[[PREFIX]]/cas" +// CHECK-NEXT: "PREFIX{{/|\\\\}}cas" // CHECK: "-o" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Top-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Top-{{.*}}.pcm" // CHECK: "-disable-free" // CHECK: "-fno-pch-timestamp" // CHECK: "-fcas-include-tree" @@ -185,21 +185,21 @@ // CHECK: "-fno-implicit-modules" // CHECK: ] // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/Top.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}Top.h" // CHECK-NEXT: ] // CHECK: "name": "Top" // CHECK: } // CHECK-NEXT: { // CHECK: "cas-include-tree-id": "[[AT_IMPORT_TREE:llvmcas://[[:xdigit:]]+]]" // CHECK: "clang-module-deps": [] -// CHECK: "clang-modulemap-file": "[[PREFIX]]/module.modulemap" +// CHECK: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap" // CHECK: "command-line": [ // CHECK-NEXT: "-cc1" // CHECK: "-fcas-path" -// CHECK-NEXT: "[[PREFIX]]/cas" +// CHECK-NEXT: "PREFIX{{/|\\\\}}cas" // CHECK: "-o" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/ZAtImport-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}ZAtImport-{{.*}}.pcm" // CHECK: "-disable-free" // CHECK: "-fno-pch-timestamp" // CHECK: "-fcas-include-tree" @@ -211,21 +211,21 @@ // CHECK: "-fno-implicit-modules" // CHECK: ] // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/AtImport.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}AtImport.h" // CHECK-NEXT: ] // CHECK: "name": "ZAtImport" // CHECK: } // CHECK-NEXT: { // CHECK: "cas-include-tree-id": "[[PRAGMA_IMPORT_TREE:llvmcas://[[:xdigit:]]+]]" // CHECK: "clang-module-deps": [] -// CHECK: "clang-modulemap-file": "[[PREFIX]]/module.modulemap" +// CHECK: "clang-modulemap-file": "PREFIX{{/|\\\\}}module.modulemap" // CHECK: "command-line": [ // CHECK-NEXT: "-cc1" // CHECK: "-fcas-path" -// CHECK-NEXT: "[[PREFIX]]/cas" +// CHECK-NEXT: "PREFIX{{/|\\\\}}cas" // CHECK: "-o" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/ZPragmaImport-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}ZPragmaImport-{{.*}}.pcm" // CHECK: "-disable-free" // CHECK: "-fno-pch-timestamp" // CHECK: "-fcas-include-tree" @@ -237,8 +237,8 @@ // CHECK: "-fno-implicit-modules" // CHECK: ] // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/module.modulemap" -// CHECK-NEXT: "[[PREFIX]]/PragmaImport.h" +// CHECK-NEXT: "PREFIX{{/|\\\\}}module.modulemap" +// CHECK-NEXT: "PREFIX{{/|\\\\}}PragmaImport.h" // CHECK-NEXT: ] // CHECK: "name": "ZPragmaImport" // CHECK: } @@ -265,7 +265,7 @@ // CHECK: "command-line": [ // CHECK-NEXT: "-cc1" // CHECK: "-fcas-path" -// CHECK-NEXT: "[[PREFIX]]/cas" +// CHECK-NEXT: "PREFIX{{/|\\\\}}cas" // CHECK-NOT: -fmodule-map-file // CHECK: "-disable-free" // CHECK: "-fcas-include-tree" @@ -273,20 +273,20 @@ // CHECK: "-fcache-compile-job" // CHECK: "-fsyntax-only" // CHECK: "-fmodule-file-cache-key" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Left-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Left-{{.*}}.pcm" // CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}" // CHECK: "-fmodule-file-cache-key" -// CHECK-NEXT: "[[PREFIX]]/outputs/{{.*}}/Right-{{.*}}.pcm" +// CHECK-NEXT: "PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Right-{{.*}}.pcm" // CHECK-NEXT: "llvmcas://{{[[:xdigit:]]+}}" -// CHECK: "-fmodule-file=Left=[[PREFIX]]/outputs/{{.*}}/Left-{{.*}}.pcm" -// CHECK: "-fmodule-file=Right=[[PREFIX]]/outputs/{{.*}}/Right-{{.*}}.pcm" +// CHECK: "-fmodule-file=Left=PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Left-{{.*}}.pcm" +// CHECK: "-fmodule-file=Right=PREFIX{{/|\\\\}}outputs{{/|\\\\}}{{.*}}{{/|\\\\}}Right-{{.*}}.pcm" // CHECK: "-fmodules" // CHECK: "-fno-implicit-modules" // CHECK: ] // CHECK: "file-deps": [ -// CHECK-NEXT: "[[PREFIX]]/tu.m" +// CHECK-NEXT: "PREFIX{{/|\\\\}}tu.m" // CHECK-NEXT: ] -// CHECK: "input-file": "[[PREFIX]]/tu.m" +// CHECK: "input-file": "PREFIX{{/|\\\\}}tu.m" // CHECK: } // CHECK-NEXT: ] // CHECK-NEXT: } diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py index 9c44ec316c782..4c15673a23b1b 100644 --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -250,6 +250,18 @@ def have_host_clang_repl_cuda(): ) ) +config.substitutions.append( + ( + "%PathSanitizingFileCheck", + '"%s" %s %s' + % ( + config.python_executable, + os.path.join(config.clang_src_dir, "utils", "PathSanitizingFileCheck"), + '--enable-windows-compatibility' if platform.system() == 'Windows' else '', + ), + ) +) + # Determine whether the test target is compatible with execution on the host. if "aarch64" in config.host_arch: config.available_features.add("aarch64-host") diff --git a/clang/utils/PathSanitizingFileCheck b/clang/utils/PathSanitizingFileCheck new file mode 100644 index 0000000000000..eaf8a67a18c06 --- /dev/null +++ b/clang/utils/PathSanitizingFileCheck @@ -0,0 +1,115 @@ +#!/usr/bin/env python3 +# utils/PathSanitizingFileCheck -*- python -*- +# +# This source file is part of the Swift.org open source project +# +# Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +# Licensed under Apache License v2.0 with Runtime Library Exception +# +# See https://swift.org/LICENSE.txt for license information +# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors + +import argparse +import io +import re +import subprocess +import sys + + +def main(): + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description=""" +PathSanitizingFileCheck is a wrapper around LLVM's FileCheck. In addition +to all FileCheck features, PathSanitizingFileCheck can replace given +strings in the input with other strings. This feature is used to replace +paths to the source and build directories with path-independent +constants.""") + + parser.add_argument( + "--sanitize", + help="replace the given string with another string", + metavar="REPLACEMENT=SOURCE", + action="append", + dest="sanitize_strings", + default=[]) + + parser.add_argument( + "--use-filecheck", + help="path to LLVM FileCheck executable", + metavar="PATH", + action="store", + dest="file_check_path", + default="FileCheck") + + parser.add_argument( + "--enable-windows-compatibility", + help="Enable Windows path compatibility, which checks against both " + "forward slashes and backward slashes.", + action="store_true") + + parser.add_argument( + "--enable-yaml-compatibility", + help="Enable YAML path compatibility. Since YAML double escapes " + "backward slashes, we need to check for them escaped. Only " + "available if Windows compatibility is enabled.", + action="store_true") + + parser.add_argument( + "--dry-run", + help="Apply the replacements to the input and print the result " + "to standard output", + action="store_true") + + parser.add_argument( + "--ignore-runtime-warnings", + help="Ignore warnings from the Swift runtime", + action="store_true") + + args, unknown_args = parser.parse_known_args() + + if args.enable_windows_compatibility: + if args.enable_yaml_compatibility: + slashes_re = r'(/|\\\\|\\\\\\\\)' + else: + slashes_re = r'(/|\\\\)' + else: + slashes_re = r'/' + + stdin = io.open(sys.stdin.fileno(), 'r', encoding='utf-8', errors='ignore').read() + + for s in args.sanitize_strings: + replacement, pattern = s.split('=', 1) + # Since we want to use pattern as a regex in some platforms, we need + # to escape it first, and then replace the escaped slash + # literal (r'\\/') for our platform-dependent slash regex. + stdin = re.sub(re.sub(r'\\/' if sys.version_info[0] < 3 else r'/', + slashes_re, re.escape(pattern)), + replacement, stdin) + + # Because we force the backtracer on in the tests, we can get runtime + # warnings about privileged programs. Suppress those, and also the + # warning it might emit if backtracing isn't supported on the test platform. + # Additionally, suppress warnings about unknown backtracer options, since + # we might want to add new ones to the lit tests and we should ignore + # messages from the system copy of the runtime in that case. + if args.ignore_runtime_warnings: + stdin = re.sub(r'^swift runtime: (backtrace-on-crash is not ' + r'supported|unknown) .*\n', "", stdin, flags=re.M) + + if args.dry_run: + print(stdin) + return 0 + else: + p = subprocess.Popen( + [args.file_check_path] + unknown_args, stdin=subprocess.PIPE) + stdout, stderr = p.communicate(stdin.encode('utf-8')) + if stdout is not None: + print(stdout) + if stderr is not None: + print(stderr, file=sys.stderr) + return p.wait() + + +if __name__ == '__main__': + exit(main()) diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py index 56aa5eb64fa36..718a930b32fd2 100644 --- a/llvm/utils/lit/lit/llvm/config.py +++ b/llvm/utils/lit/lit/llvm/config.py @@ -712,6 +712,9 @@ def use_clang( ToolSubst( "%clang", command=self.config.clang, extra_args=additional_flags ), + ToolSubst( + "%/clang", command=self.config.clang.replace("\\", "/"), extra_args=additional_flags + ), ToolSubst( "%clang_analyze_cc1", command="%clang_cc1",