Skip to content

Commit 7807570

Browse files
committed
[Build] Link XCTest with Foundation
In order to implement asynchronous tests, swift-corelibs-xctest will take on a dependency upon swift-corelibs-foundation. To properly link the two: - Allow the package manager to take a path to a Foundation build. - Extend the SWIFTPM_EXTRA_IMPORTS hack such that it can take a list of paths.
1 parent ec456c9 commit 7807570

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Sources/Build/describe().swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,20 @@ extension Product {
194194
}
195195

196196
private func extraImports() -> [String] {
197-
//FIXME HACK
198-
if let I = getenv("SWIFTPM_EXTRA_IMPORT") {
199-
return ["-I", I]
197+
// FIXME: This is a hack to allow -I include paths to be passed through to
198+
// swift-build and swift-test invocations. SWIFTPM_EXTRA_IMPORTS is
199+
// a semicolon-delineated list of absolute paths, for example:
200+
//
201+
// SWIFTPM_EXTRA_IMPORTS="/path/to/foo;/path/to/bar" swift-build
202+
//
203+
// This should be fixed such that it does not rely upon environment
204+
// variables.
205+
if let includes = getenv("SWIFTPM_EXTRA_IMPORTS") {
206+
var args = [String]()
207+
for include in includes.characters.split(";").map(String.init) {
208+
args += ["-I", include]
209+
}
210+
return args
200211
} else {
201212
return []
202213
}

Utilities/bootstrap

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,18 @@ def main():
544544
cmd.extend(["-Xlinker", "-rpath", "-Xlinker", embed_rpath])
545545

546546
cmd = [os.path.join(sandbox_path, "bin", "swift-build")]
547-
if args.xctest_path:
548-
env_cmd.append("SWIFTPM_EXTRA_IMPORT=" + args.xctest_path)
547+
if args.foundation_path and args.xctest_path:
548+
core_foundation_path = os.path.join(
549+
args.foundation_path, "usr", "lib", "swift")
550+
imports = ";".join([
551+
args.xctest_path, args.foundation_path, core_foundation_path])
552+
env_cmd.append("SWIFTPM_EXTRA_IMPORTS=" + imports)
549553
# Tell the linker where to look for XCTest, but autolinking
550554
# knows to pass -lXCTest.
551555
cmd.extend(["-Xlinker", "-L", "-Xlinker", args.xctest_path])
552556
# Add an RPATH, so that the tests can be run directly.
553557
cmd.extend(["-Xlinker", "-rpath", "-Xlinker", args.xctest_path])
558+
cmd.extend(["-Xlinker", "-rpath", "-Xlinker", args.foundation_path])
554559

555560
cmd = env_cmd + cmd
556561

0 commit comments

Comments
 (0)