mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Improve swift dependency scanner by validating and selecting dependency module into scanner. This provides benefits that: * Build system does not need to schedule interface compilation task if the candidate module is picked, it can just use the candidate module directly. * There is no need for forwarding module in the explicit module build. Since the build system is coordinating the build, there is no need for the forwarding module in the module cache to avoid duplicated work, * This also correctly supports all the module loading modes in the dependency scanner. This is achieved by only adding validate and up-to-date binary module as the candidate module for swift interface module dependency. This allows caching build to construct the correct dependency in the CAS. If there is a candidate module for the interface module, dependency scanner will return a binary module dependency in the dependency graph. The legacy behavior is mostly preserved with a hidden frontend flag `-no-scanner-module-validation`, while the scanner output is mostly interchangeable with new scanner behavior with `prefer-interface` module loading mode except the candidate module will not be returned. rdar://123711823
54 lines
3.7 KiB
Swift
54 lines
3.7 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %empty-directory(%t/Foo.swiftmodule)
|
|
// RUN: %empty-directory(%t/ResourceDir/%target-sdk-name/prebuilt-modules/Foo.swiftmodule)
|
|
// RUN: echo "public func foo() {}" > %t/Foo.swift
|
|
|
|
import Foo
|
|
|
|
// HAS_COMPILED: "compiledModuleCandidates": [
|
|
// HAS_COMPILED-NEXT: "{{.*}}Foo.swiftmodule{{.*}}.swiftmodule"
|
|
|
|
// HAS_BINARY: "swiftPrebuiltExternal": "Foo"
|
|
|
|
// HAS_NO_COMPILED-NOT: "{{.*}}Foo.swiftmodule{{.*}}.swiftmodule"
|
|
|
|
// Step 1: build swift interface and swift module side by side
|
|
// RUN: %target-swift-frontend -emit-module %t/Foo.swift -emit-module-path %t/Foo.swiftmodule/%target-swiftmodule-name -module-name Foo -emit-module-interface-path %t/Foo.swiftmodule/%target-swiftinterface-name
|
|
|
|
// Step 2: scan dependency should give us the binary module adjacent to the interface file.
|
|
// RUN: %target-swift-frontend -scan-dependencies -no-scanner-module-validation %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d
|
|
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix=HAS_COMPILED
|
|
|
|
/// Check scanner picked binary dependency if not requesting raw scan output.
|
|
// RUN: %target-swift-frontend -scan-dependencies %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d
|
|
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix=HAS_BINARY
|
|
|
|
// Step 3: remove the adjacent module.
|
|
// RUN: rm %t/Foo.swiftmodule/%target-swiftmodule-name
|
|
|
|
// Step 4: scan dependency should give us the interface file.
|
|
// RUN: %target-swift-frontend -scan-dependencies -no-scanner-module-validation %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d
|
|
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix=HAS_NO_COMPILED
|
|
|
|
// Step 4: build prebuilt module cache using the interface.
|
|
// RUN: %target-swift-frontend -compile-module-from-interface -o %t/ResourceDir/%target-sdk-name/prebuilt-modules/Foo.swiftmodule/%target-swiftmodule-name -module-name Foo -disable-interface-lock %t/Foo.swiftmodule/%target-swiftinterface-name
|
|
|
|
// Step 5: scan dependency now should give us the prebuilt module cache
|
|
// RUN: %target-swift-frontend -scan-dependencies -no-scanner-module-validation %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d -sdk %t -prebuilt-module-cache-path %t/ResourceDir/%target-sdk-name/prebuilt-modules
|
|
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix=HAS_COMPILED
|
|
|
|
/// Check scanner picked binary dependency if not requesting raw scan output.
|
|
// RUN: %target-swift-frontend -scan-dependencies %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d -sdk %t -prebuilt-module-cache-path %t/ResourceDir/%target-sdk-name/prebuilt-modules
|
|
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix=HAS_BINARY
|
|
|
|
// Step 6: update the interface file from where the prebuilt module cache was built.
|
|
// RUN: touch %t/Foo.swiftmodule/%target-swiftinterface-name
|
|
|
|
// Step 7: scan dependency should give us the prebuilt module file even though it's out-of-date.
|
|
// RUN: %target-swift-frontend -scan-dependencies -no-scanner-module-validation %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d -sdk %t -prebuilt-module-cache-path %t/ResourceDir/%target-sdk-name/prebuilt-modules
|
|
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix=HAS_COMPILED
|
|
|
|
// Step 8: The new scanner behavior should not give use prebuilt module file because it is out-of-date.
|
|
// RUN: %target-swift-frontend -scan-dependencies %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d -sdk %t -prebuilt-module-cache-path %t/ResourceDir/%target-sdk-name/prebuilt-modules
|
|
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix=HAS_NO_COMPILED
|