Skip to content

Commit 5afbddb

Browse files
committed
[Dependency Scanner] Ensure that Clang dependency scanner instances inherit the creating invocation's extra clang args.
This ensures that when the dependency scanner is invoked with additional clang (`-Xcc`) options, the Clang scanner is correctly configured using these options.
1 parent 9993875 commit 5afbddb

13 files changed

+70
-9
lines changed

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ Optional<ModuleDependencies> ClangImporter::getModuleDependencies(
308308
// Reform the Clang importer options.
309309
// FIXME: Just save a reference or copy so we can get this back.
310310
ClangImporterOptions importerOpts;
311+
importerOpts.ExtraArgs = getExtraClangArgs();
311312

312313
// Determine the command-line arguments for dependency scanning.
313314
auto &ctx = Impl.SwiftContext;
@@ -351,6 +352,7 @@ bool ClangImporter::addBridgingHeaderDependencies(
351352
// Reform the Clang importer options.
352353
// FIXME: Just save a reference or copy so we can get this back.
353354
ClangImporterOptions importerOpts;
355+
importerOpts.ExtraArgs = getExtraClangArgs();
354356

355357
// Retrieve the bridging header.
356358
std::string bridgingHeader = *targetModule.getBridgingHeader();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000
2+
#include "X.h"
3+
#endif
4+
15
void funcG(void);
6+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void funcX(void);

test/ScanDependencies/Inputs/CHeaders/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ module I {
3737
header "I.h"
3838
export *
3939
}
40+
41+
module X {
42+
header "X.h"
43+
export *
44+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/inputs)
3+
// RUN: %empty-directory(%t/outputs)
4+
// RUN: mkdir -p %t/clang-module-cache
5+
6+
// RUN: echo "[{" > %/t/inputs/input.json
7+
// RUN: echo "\"clangModuleName\": \"G\"," >> %/t/inputs/input.json
8+
// RUN: echo "\"arguments\": \"-Xcc -target -Xcc x86_64-apple-macosx10.9\"," >> %/t/inputs/input.json
9+
// RUN: echo "\"output\": \"%/t/outputs/G_109.pcm.json\"" >> %/t/inputs/input.json
10+
// RUN: echo "}," >> %/t/inputs/input.json
11+
// RUN: echo "{" >> %/t/inputs/input.json
12+
// RUN: echo "\"clangModuleName\": \"G\"," >> %/t/inputs/input.json
13+
// RUN: echo "\"arguments\": \"-Xcc -target -Xcc x86_64-apple-macosx11.0\"," >> %/t/inputs/input.json
14+
// RUN: echo "\"output\": \"%/t/outputs/G_110.pcm.json\"" >> %/t/inputs/input.json
15+
// RUN: echo "}]" >> %/t/inputs/input.json
16+
17+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -batch-scan-input-file %/t/inputs/input.json
18+
19+
// Check the contents of the JSON output
20+
// RUN: %FileCheck %s -check-prefix=CHECK-PCM109 < %t/outputs/G_109.pcm.json
21+
// RUN: %FileCheck %s -check-prefix=CHECK-PCM110 < %t/outputs/G_110.pcm.json
22+
23+
// CHECK-PCM109: {
24+
// CHECK-PCM109-NEXT: "mainModuleName": "G",
25+
// CHECK-PCM109-NEXT: "modules": [
26+
// CHECK-PCM109-NEXT: {
27+
// CHECK-PCM109-NEXT: "clang": "G"
28+
// CHECK-PCM109-NEXT: },
29+
// CHECK-PCM109-NEXT: {
30+
// CHECK-PCM109-NEXT: "modulePath": "G.pcm",
31+
// CHECK-PCM109: "directDependencies": [
32+
// CHECK-PCM109-NEXT: {
33+
// CHECK-PCM109-NEXT: "clang": "X"
34+
// CHECK-PCM109-NEXT: }
35+
// CHECK-PCM109-NEXT: ],
36+
// CHECK-PCM109: "-I
37+
38+
// CHECK-PCM110: {
39+
// CHECK-PCM110-NEXT: "mainModuleName": "G",
40+
// CHECK-PCM110-NEXT: "modules": [
41+
// CHECK-PCM110-NEXT: {
42+
// CHECK-PCM110-NEXT: "clang": "G"
43+
// CHECK-PCM110-NEXT: },
44+
// CHECK-PCM110-NEXT: {
45+
// CHECK-PCM110-NEXT: "modulePath": "G.pcm",
46+
// CHECK-PCM110: "directDependencies": [
47+
// CHECK-PCM110-NEXT: ],
48+
// CHECK-PCM110-NOT: "clang": "X"
49+
// CHECK-PCM110: "-I

test/ScanDependencies/can_import_placeholder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
2121
// RUN: echo "}]" >> %/t/inputs/map.json
2222

23-
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -placeholder-dependency-module-map-file %t/inputs/map.json -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -disable-implicit-swift-modules -Xcc -Xclang -Xcc -fno-implicit-modules
23+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -placeholder-dependency-module-map-file %t/inputs/map.json -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4
2424

2525
// Check the contents of the JSON output
2626
// RUN: %FileCheck %s < %t/deps.json

test/ScanDependencies/diagnose_dependency_cycle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: mkdir -p %t/clang-module-cache
33

4-
// RUN: not %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -disable-implicit-swift-modules -Xcc -Xclang -Xcc -fno-implicit-modules &> %t/out.txt
4+
// RUN: not %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 &> %t/out.txt
55

66
// RUN: %FileCheck %s < %t/out.txt
77

test/ScanDependencies/module_deps.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: mkdir -p %t/clang-module-cache
3-
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -disable-implicit-swift-modules -Xcc -Xclang -Xcc -fno-implicit-modules
3+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4
44

55
// Check the contents of the JSON output
66
// RUN: %FileCheck %s < %t/deps.json
@@ -105,7 +105,6 @@ import SubE
105105
// CHECK-NEXT: "-only-use-extra-clang-opts"
106106
// CHECK-NEXT: "-Xcc"
107107
// CHECK-NEXT: "clang"
108-
// CHECK: "-fno-implicit-modules"
109108

110109
/// --------Swift module E
111110
// CHECK: "swift": "E"

test/ScanDependencies/module_deps_clang_only.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: mkdir -p %t/clang-module-cache
3-
// RUN: %target-swift-frontend -scan-clang-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -disable-implicit-swift-modules -Xcc -Xclang -Xcc -fno-implicit-modules -module-name C
3+
// RUN: %target-swift-frontend -scan-clang-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -disable-implicit-swift-modules -module-name C
44

55
// Check the contents of the JSON output
66
// RUN: %FileCheck %s < %t/deps.json

test/ScanDependencies/module_deps_cross_import_overlay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: mkdir -p %t/clang-module-cache
3-
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -disable-implicit-swift-modules -Xcc -Xclang -Xcc -fno-implicit-modules
3+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4
44

55
// Check the contents of the JSON output
66
// RUN: %FileCheck %s < %t/deps.json

0 commit comments

Comments
 (0)