Files
swift-mirror/test/ScanDependencies/compiled_swift_modules.swift
Xi Ge 84dd4db0b1 Dependencies Scanner: report compiled Swift module paths if they are available
For the explicit module mode, swift-driver uses -compile-module-from-interface to
generate modules from interfaces found by the dependency scanner. However, we don't
need to build the binary module if up-to-date modules are available, either adjacent
to the interface file or in the prebuilt module cache directory. This patch teaches
dependencies scanner to report these ready-to-use binary modules.
2020-07-01 11:54:15 -07:00

38 lines
2.3 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: "compiledModulePath": "{{.*}}Foo.swiftmodule{{.*}}.swiftmodule"
// HAS_NO_COMPILED-NOT: "compiledModulePath": "{{.*}}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 %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d
// RUN: %FileCheck %s -check-prefix=HAS_COMPILED < %t/deps.json
// 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 %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d
// RUN: %FileCheck %s -check-prefix=HAS_NO_COMPILED < %t/deps.json
// 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 %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: %FileCheck %s -check-prefix=HAS_COMPILED < %t/deps.json
// Step 6: update the interface file from where the prebuilt module cache was built.
// RUN: touch %t/Foo.swiftmodule/%target-swiftinterface-name
// Step 4: scan dependency should give us the interface file.
// RUN: %target-swift-frontend -scan-dependencies %s -o %t/deps.json -I %t -emit-dependencies -emit-dependencies-path %t/deps.d
// RUN: %FileCheck %s -check-prefix=HAS_NO_COMPILED < %t/deps.json