|
| 1 | +/// Tests the fallback behavior for runtime library import paths. These should |
| 2 | +/// prefer the resource directory, but fall back to the SDK. |
| 3 | + |
| 4 | +// Assumption: We build the standard library with the compiler, so the default |
| 5 | +// resource directory will contain a swiftmodule for the standard library. |
| 6 | + |
| 7 | +// %t/good-sdk contains a loadable standard library. |
| 8 | +// RUN: %empty-directory(%t/good-sdk/usr/lib/swift) |
| 9 | +// RUN: cp -r %platform-module-dir/Swift.swiftmodule %t/good-sdk/usr/lib/swift/Swift.swiftmodule |
| 10 | + |
| 11 | +// %t/bad-sdk contains an invalid standard library that cannot be loaded. |
| 12 | +// RUN: %empty-directory(%t/bad-sdk/usr/lib/swift/Swift.swiftmodule) |
| 13 | +// RUN: touch %t/bad-sdk/usr/lib/swift/Swift.swiftmodule/garbage-garbage-garbage.swiftmodule |
| 14 | + |
| 15 | +// %t/empty-toolchain does not contain a standard library. |
| 16 | +// RUN: %empty-directory(%t/empty-toolchain/usr/lib/swift) |
| 17 | + |
| 18 | +// FIXME: Until we have private imports, we need SwiftShims in the toolchain. |
| 19 | +// RUN: cp -r %test-resource-dir/shims %t/empty-toolchain/usr/lib/swift/shims |
| 20 | + |
| 21 | +// If the compiler's resource directory does not contain a runtime swiftmodule, |
| 22 | +// we should fall back to the SDK. |
| 23 | + |
| 24 | +// RUN: %empty-directory(%t/mcp) |
| 25 | +// RUN: %target-swift-frontend(mock-sdk: -sdk %t/good-sdk) -resource-dir %t/empty-toolchain/usr/lib/swift -module-cache-path %t/mcp -typecheck -verify %s |
| 26 | + |
| 27 | +// If the compiler's resource directory *does* contain a runtime swiftmodule, we |
| 28 | +// should *not* use the one in the SDK. (We assume that the resource directory |
| 29 | +// built with this compiler does contain a standard library.) |
| 30 | + |
| 31 | +// RUN: %empty-directory(%t/mcp) |
| 32 | +// RUN: %target-swift-frontend(mock-sdk: -sdk %t/bad-sdk) -module-cache-path %t/mcp -typecheck -verify %s |
| 33 | + |
| 34 | +// If neither the resource directory nor the SDK contains a runtime swiftmodule, |
| 35 | +// loading should fail. This just proves that we aren't getting runtime imports |
| 36 | +// some other way. |
| 37 | + |
| 38 | +// FIXME: We can't properly test this on a non-Darwin platform because we'll get |
| 39 | +// the same error message for "unloadable standard library" and "no standard |
| 40 | +// library". (SR-10097) |
| 41 | +// REQUIRES: objc_interop |
| 42 | + |
| 43 | +// RUN: %empty-directory(%t/mcp) |
| 44 | +// 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 |
| 45 | +// CHECK: error: could not find module 'Swift' for target '{{.*}}'; found: garbage-garbage-garbage |
| 46 | + |
| 47 | +let x: Int = 1 |
0 commit comments