From 2132a9034dd823c5844792551cef81f3e86adaf3 Mon Sep 17 00:00:00 2001 From: Xi Ge Date: Wed, 28 Jul 2021 17:32:21 -0700 Subject: [PATCH] DependenciesScanner: include -sdk in Swift module building command Swift module building commands need -sdk because dependencies sometimes use sdk-relative paths (prebuilt modules for example). Without -sdk, the command will not be able to local these dependencies, leading to unnecessary rebuilding from textual interfaces. rdar://81177968 --- lib/Frontend/ModuleInterfaceLoader.cpp | 7 +++++++ test/ScanDependencies/include-sdk-in-command.swift | 11 +++++++++++ test/ScanDependencies/module_deps.swift | 1 - 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/ScanDependencies/include-sdk-in-command.swift diff --git a/lib/Frontend/ModuleInterfaceLoader.cpp b/lib/Frontend/ModuleInterfaceLoader.cpp index 8f3f1448f1b73..13ff2e7798313 100644 --- a/lib/Frontend/ModuleInterfaceLoader.cpp +++ b/lib/Frontend/ModuleInterfaceLoader.cpp @@ -1290,6 +1290,13 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface( genericSubInvocation.setImportSearchPaths(SearchPathOpts.ImportSearchPaths); genericSubInvocation.setFrameworkSearchPaths(SearchPathOpts.FrameworkSearchPaths); if (!SearchPathOpts.SDKPath.empty()) { + // Add -sdk arguments to the module building commands. + // Module building commands need this because dependencies sometimes use + // sdk-relative paths (prebuilt modules for example). Without -sdk, the command + // will not be able to local these dependencies, leading to unnecessary + // building from textual interfaces. + GenericArgs.push_back("-sdk"); + GenericArgs.push_back(ArgSaver.save(SearchPathOpts.SDKPath)); genericSubInvocation.setSDKPath(SearchPathOpts.SDKPath); } diff --git a/test/ScanDependencies/include-sdk-in-command.swift b/test/ScanDependencies/include-sdk-in-command.swift new file mode 100644 index 0000000000000..eefe5a51c21fb --- /dev/null +++ b/test/ScanDependencies/include-sdk-in-command.swift @@ -0,0 +1,11 @@ +// RUN: %empty-directory(%t) + +// RUN: %target-swift-frontend -scan-dependencies %s -o %t/deps.json -sdk %t/mysecretsdk.sdk + +// Check the contents of the JSON output +// RUN: %FileCheck %s < %t/deps.json + +func foo() { print(1) } + +// CHECK: "-sdk", +// CHECK-NEXT: mysecretsdk.sdk diff --git a/test/ScanDependencies/module_deps.swift b/test/ScanDependencies/module_deps.swift index e39f376020e5e..c9c46e435991e 100644 --- a/test/ScanDependencies/module_deps.swift +++ b/test/ScanDependencies/module_deps.swift @@ -213,7 +213,6 @@ import SubE /// --------Clang module SwiftShims // CHECK-LABEL: "modulePath": "SwiftShims.pcm", -// CHECK-NO-SEARCH-PATHS-NOT: "-sdk" // CHECK-NO-SEARCH-PATHS-NOT: "-prebuilt-module-cache-path" // Check make-style dependencies