Skip to content

Commit

Permalink
Search for SwiftShims in SDK (#23287) (#23317)
Browse files Browse the repository at this point in the history
…but only if the compiler resource directory doesn’t have them. These will move to the SDK soon.
  • Loading branch information
beccadax committed Mar 15, 2019
1 parent 9fd211d commit 1c47784
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Expand Up @@ -424,6 +424,17 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
});
}

// If there are no shims in the resource dir, add a search path in the SDK.
SmallString<128> shimsPath(searchPathOpts.RuntimeResourcePath);
llvm::sys::path::append(shimsPath, "shims");
if (!llvm::sys::fs::exists(shimsPath)) {
shimsPath = searchPathOpts.SDKPath;
llvm::sys::path::append(shimsPath, "usr", "lib", "swift", "shims");
invocationArgStrs.insert(invocationArgStrs.end(), {
"-isystem", shimsPath.str()
});
}

// Construct the invocation arguments for the current target.
// Add target-independent options first.
invocationArgStrs.insert(invocationArgStrs.end(), {
Expand Down
23 changes: 21 additions & 2 deletions test/Serialization/runtime-import-from-sdk.swift
Expand Up @@ -5,19 +5,26 @@
// resource directory will contain a swiftmodule for the standard library.

// %t/good-sdk contains a loadable standard library.
// RUN: %empty-directory(%t/good-sdk)
// RUN: %empty-directory(%t/good-sdk/usr/lib/swift)
// RUN: cp -r %platform-module-dir/Swift.swiftmodule %t/good-sdk/usr/lib/swift/Swift.swiftmodule

// %t/bad-sdk contains an invalid standard library that cannot be loaded.
// RUN: %empty-directory(%t/bad-sdk)
// RUN: %empty-directory(%t/bad-sdk/usr/lib/swift/Swift.swiftmodule)
// RUN: touch %t/bad-sdk/usr/lib/swift/Swift.swiftmodule/garbage-garbage-garbage.swiftmodule

// %t/empty-toolchain does not contain a standard library.
// RUN: %empty-directory(%t/empty-toolchain)
// RUN: %empty-directory(%t/empty-toolchain/usr/lib/swift)

// FIXME: Until we have private imports, we need SwiftShims in the toolchain.
// RUN: cp -r %test-resource-dir/shims %t/empty-toolchain/usr/lib/swift/shims

// %t/really-empty-toolchain does not contain a standard library or SwiftShims.
// RUN: %empty-directory(%t/really-empty-toolchain)
// RUN: %empty-directory(%t/really-empty-toolchain/usr/lib/swift)

// If the compiler's resource directory does not contain a runtime swiftmodule,
// we should fall back to the SDK.

Expand All @@ -34,14 +41,26 @@
// If neither the resource directory nor the SDK contains a runtime swiftmodule,
// loading should fail. This just proves that we aren't getting runtime imports
// some other way.
//
// We also check that ClangImporter noticed SwiftShims in the toolchain and
// didn't add a -isystem flag to look in the SDK.

// FIXME: We can't properly test this on a non-Darwin platform because we'll get
// the same error message for "unloadable standard library" and "no standard
// library". (SR-10097)
// REQUIRES: objc_interop

// RUN: %empty-directory(%t/mcp)
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/bad-sdk) -resource-dir %t/empty-toolchain/usr/lib/swift -module-cache-path %t/mcp -typecheck %s 2>&1 | %FileCheck %s
// CHECK: error: could not find module 'Swift' for target '{{.*}}'; found: garbage-garbage-garbage
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/bad-sdk) -resource-dir %t/empty-toolchain/usr/lib/swift -module-cache-path %t/mcp -typecheck %s -dump-clang-diagnostics 2>&1 | %FileCheck --check-prefix CHECK-EMPTY %s
// CHECK-EMPTY-NOT: '-isystem' '{{.*}}/bad-sdk/usr/lib/swift/shims'
// CHECK-EMPTY: error: could not find module 'Swift' for target '{{.*}}'; found: garbage-garbage-garbage

// Check that, when the toolchain *doesn't* have SwiftShims in it, ClagImporter
// *does* add a -I flag to look in the SDK.

// RUN: %empty-directory(%t/mcp)
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/bad-sdk) -resource-dir %t/really-empty-toolchain/usr/lib/swift -module-cache-path %t/mcp -typecheck %s -dump-clang-diagnostics 2>&1 | %FileCheck --check-prefix CHECK-REALLY-EMPTY %s
// CHECK-REALLY-EMPTY: '-isystem' '{{.*}}/bad-sdk/usr/lib/swift/shims'
// CHECK-REALLY-EMPTY: error: could not find module 'Swift' for target '{{.*}}'; found: garbage-garbage-garbage

let x: Int = 1

0 comments on commit 1c47784

Please sign in to comment.