File: loading-order.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (47 lines) | stat: -rw-r--r-- 2,737 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// Test the loading order of module interfaces between the SDK and the
/// prebuilt cache. The order should be:
///
/// 1. swiftmodule in the local cache (not tested here)
/// 2. swiftmodule next to the swiftinterface file
/// 3. If it's a private swiftinterface, rebuild the swiftmodule from the private swiftinterface
/// 4. swiftmodule in the prebuilt-module cache
/// 5. Rebuild the swiftmodule from the swiftinterface file and keep in the local cache

/// Create folders for a) our Swift module, b) the module cache, and c) a
/// fake resource dir with a default prebuilt module cache inside.
// RUN: %empty-directory(%t/MyModule.swiftmodule)
// RUN: %empty-directory(%t/ModuleCache)
// RUN: %empty-directory(%t/ResourceDir/%target-sdk-name/prebuilt-modules/MyModule.swiftmodule)

/// Define two sets of public API.
// RUN: echo 'public func nextToSwiftinterface() {}' > %t/NextToSwiftinterface.swift
// RUN: echo 'public func prebuiltModule() {}' > %t/PrebuiltModule.swift

/// Compile this into a module in the SDK.
// RUN: %target-swift-frontend -emit-module %t/NextToSwiftinterface.swift -o %t/MyModule.swiftmodule/%target-swiftmodule-name -module-name MyModule -parse-stdlib -emit-module-interface-path %t/MyModule.swiftmodule/%target-swiftinterface-name -emit-private-module-interface-path %t/MyModule.swiftmodule/%target-private-swiftinterface-name

/// Also put a module with a different API into the default prebuilt cache under the same name to detect when its picked.
// RUN: %target-swift-frontend -emit-module %t/PrebuiltModule.swift -o %t/ResourceDir/%target-sdk-name/prebuilt-modules/MyModule.swiftmodule/%target-swiftmodule-name -module-name MyModule -parse-stdlib

/// Import this module and expect to use the swiftmodule next to the swiftinterface.
// RUN: %target-swift-frontend -typecheck -resource-dir %t/ResourceDir -I %t %s -parse-stdlib -module-cache-path %t/ModuleCache -sdk %t -D FIRST_NEXT_TO_SWIFTINTERFACE

/// Remove the swiftmodule next to the swiftinterface, the compiler should rebuild from the private swiftinterface.
// RUN: rm %t/MyModule.swiftmodule/%target-swiftmodule-name
// RUN: %target-swift-frontend -typecheck -resource-dir %t/ResourceDir -I %t %s -parse-stdlib -module-cache-path %t/ModuleCache -sdk %t -D FIRST_NEXT_TO_SWIFTINTERFACE

/// Remove the private swiftinterface and import again to use the prebuilt swiftmodule.
// RUN: rm %t/MyModule.swiftmodule/%target-private-swiftinterface-name
// RUN: %target-swift-frontend -typecheck -resource-dir %t/ResourceDir -I %t %s -parse-stdlib -module-cache-path %t/ModuleCache -sdk %t -D THEN_PREBUILT_MODULE

import MyModule

#if FIRST_NEXT_TO_SWIFTINTERFACE

nextToSwiftinterface()

#elseif THEN_PREBUILT_MODULE

prebuiltModule()

#endif