189 lines · c
1// Most likely platform specific sed differences2// UNSUPPORTED: system-windows3// Test current directory pruning when computing the context hash.4 5// RUN: rm -rf %t6// RUN: split-file %s %t7// RUN: sed -e "s|DIR|%/t|g" %t/cdb0.json.in > %t/cdb0.json8// RUN: sed -e "s|DIR|%/t|g" %t/cdb1.json.in > %t/cdb1.json9// RUN: sed -e "s|DIR|%/t|g" %t/cdb3.json.in > %t/cdb3.json10// RUN: sed -e "s|DIR|%/t|g" %t/cdb4.json.in > %t/cdb4.json11// RUN: sed -e "s|DIR|%/t|g" %t/cdb5.json.in > %t/cdb5.json12// RUN: clang-scan-deps -compilation-database %t/cdb0.json -format experimental-full -optimize-args=all > %t/result0.json13// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full -optimize-args=all > %t/result1.json14// It is not a typo to use cdb1.json for result2. We intend to use the same15// compilation database, but different clang-scan-deps optimize-args options.16// RUN: clang-scan-deps -compilation-database %t/cdb1.json -format experimental-full -optimize-args=header-search,system-warnings,vfs,canonicalize-macros > %t/result2.json17// RUN: clang-scan-deps -compilation-database %t/cdb3.json -format experimental-full -optimize-args=all > %t/result3.json18// RUN: clang-scan-deps -compilation-database %t/cdb4.json -format experimental-full -optimize-args=all > %t/result4.json19// RUN: clang-scan-deps -compilation-database %t/cdb5.json -format experimental-full -optimize-args=all > %t/result5.json20// RUN: cat %t/result0.json %t/result1.json | FileCheck %s21// RUN: cat %t/result0.json %t/result2.json | FileCheck %s -check-prefix=SKIPOPT22// RUN: cat %t/result3.json %t/result4.json | FileCheck %s -check-prefix=RELPATH23// RUN: cat %t/result0.json %t/result5.json | FileCheck %s24 25//--- cdb0.json.in26[{27 "directory": "DIR",28 "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/include/ -o DIR/tu.o",29 "file": "DIR/tu.c"30}]31 32//--- cdb1.json.in33[{34 "directory": "DIR/a",35 "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/include/ -o DIR/tu.o",36 "file": "DIR/tu.c"37}]38 39// cdb2 is skipped because we reuse cdb1.40 41//--- cdb3.json.in42[{43 "directory": "DIR",44 "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fprebuilt-module-path=.././module -IDIR/include/ -o DIR/tu.o ",45 "file": "DIR/tu.c"46}]47 48//--- cdb4.json.in49[{50 "directory": "DIR/a/",51 "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -fprebuilt-module-path=.././module -IDIR/include/ -o DIR/tu.o ",52 "file": "DIR/tu.c"53}]54 55//--- cdb5.json.in56[{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 62//--- include/module.modulemap63module mod {64 header "mod.h"65}66 67//--- include/mod.h68 69//--- tu.c70#include "mod.h"71 72// Check that result0 and result1/result5 compute the same hash with73// optimization on. The only difference between result0 and result1/result5 is74// the compiler's working directory.75// CHECK: {76// CHECK-NEXT: "modules": [77// CHECK-NEXT: {78// CHECK-NEXT: "clang-module-deps": [],79// CHECK: "context-hash": "[[HASH:.*]]",80// CHECK: }81// CHECK: "translation-units": [82// CHECK: {83// CHECK: "commands": [84// CHECK: {85// CHECK-NEXT: "clang-context-hash": "{{.*}}",86// CHECK-NEXT: "clang-module-deps": [87// CHECK-NEXT: {88// CHECK-NEXT: "context-hash": "[[HASH]]",89// CHECK-NEXT: "module-name": "mod"90// CHECK: }91// CHECK: ],92// CHECK: {93// CHECK-NEXT: "modules": [94// CHECK-NEXT: {95// CHECK-NEXT: "clang-module-deps": [],96// CHECK: "context-hash": "[[HASH]]",97// CHECK: }98// CHECK: "translation-units": [99// CHECK: {100// CHECK: "commands": [101// CHECK: {102// CHECK-NEXT: "clang-context-hash": "{{.*}}",103// CHECK-NEXT: "clang-module-deps": [104// CHECK-NEXT: {105// CHECK-NEXT: "context-hash": "[[HASH]]",106// CHECK-NEXT: "module-name": "mod"107// CHECK: }108// CHECK: ],109 110// Check that result0 and result2 compute different hashes because111// the working directory optmization is turned off for result2.112// SKIPOPT: {113// SKIPOPT-NEXT: "modules": [114// SKIPOPT-NEXT: {115// SKIPOPT-NEXT: "clang-module-deps": [],116// SKIPOPT: "context-hash": "[[HASH0:.*]]",117// SKIPOPT: }118// SKIPOPT: "translation-units": [119// SKIPOPT: {120// SKIPOPT: "commands": [121// SKIPOPT: {122// SKIPOPT-NEXT: "clang-context-hash": "{{.*}}",123// SKIPOPT-NEXT: "clang-module-deps": [124// SKIPOPT-NEXT: {125// SKIPOPT-NEXT: "context-hash": "[[HASH0]]",126// SKIPOPT-NEXT: "module-name": "mod"127// SKIPOPT: }128// SKIPOPT: ],129// SKIPOPT: {130// SKIPOPT-NEXT: "modules": [131// SKIPOPT-NEXT: {132// SKIPOPT-NEXT: "clang-module-deps": [],133// SKIPOPT-NOT: "context-hash": "[[HASH0]]",134// SKIPOPT: "context-hash": "[[HASH2:.*]]",135// SKIPOPT: }136// SKIPOPT: "translation-units": [137// SKIPOPT: {138// SKIPOPT: "commands": [139// SKIPOPT: {140// SKIPOPT-NEXT: "clang-context-hash": "{{.*}}",141// SKIPOPT-NEXT: "clang-module-deps": [142// SKIPOPT-NEXT: {143// SKIPOPT-NOT: "context-hash": "[[HASH0]]",144// SKIPOPT-NEXT: "context-hash": "[[HASH2]]"145// SKIPOPT-NEXT: "module-name": "mod"146// SKIPOPT: }147// SKIPOPT: ],148 149// Check that result3 and result4 contain different hashes because150// both have a same relative path as a command line input, and151// they are produced using different compiler working directories.152// RELPATH: {153// RELPATH-NEXT: "modules": [154// RELPATH-NEXT: {155// RELPATH-NEXT: "clang-module-deps": [],156// RELPATH: "context-hash": "[[HASH3:.*]]",157// RELPATH: }158// RELPATH: "translation-units": [159// RELPATH: {160// RELPATH: "commands": [161// RELPATH: {162// RELPATH-NEXT: "clang-context-hash": "{{.*}}",163// RELPATH-NEXT: "clang-module-deps": [164// RELPATH-NEXT: {165// RELPATH-NEXT: "context-hash": "[[HASH3]]",166// RELPATH-NEXT: "module-name": "mod"167// RELPATH: }168// RELPATH: ],169// RELPATH: {170// RELPATH-NEXT: "modules": [171// RELPATH-NEXT: {172// RELPATH-NEXT: "clang-module-deps": [],173// RELPATH-NOT: "context-hash": "[[HASH3]]",174// RELPATH: "context-hash": "[[HASH4:.*]]",175// RELPATH: }176// RELPATH: "translation-units": [177// RELPATH: {178// RELPATH: "commands": [179// RELPATH: {180// RELPATH-NEXT: "clang-context-hash": "{{.*}}",181// RELPATH-NEXT: "clang-module-deps": [182// RELPATH-NEXT: {183// RELPATH-NOT: "context-hash": "[[HASH3]]",184// RELPATH-NEXT: "context-hash": "[[HASH4]]"185// RELPATH-NEXT: "module-name": "mod"186// RELPATH: }187// RELPATH: ],188 189