Skip to content

Commit df127be

Browse files
committed
[XcodeprojTests] Override SWIFT_LIBRARY_PATH in tests
This will keep the compiler and Swift library consistent during the tests. - <rdar://problem/34791474> Use the built Swift standard library in the generated Xcode project tests
1 parent 7a174c0 commit df127be

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Tests/XcodeprojTests/FunctionalTests.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FunctionalTests: XCTestCase {
3232
}
3333

3434
func testSwiftExecWithCDep() {
35-
#if false
35+
#if os(macOS)
3636
fixture(name: "ClangModules/SwiftCMixed") { prefix in
3737
// This will also test Modulemap generation for xcodeproj.
3838
XCTAssertXcodeprojGen(prefix)
@@ -51,7 +51,7 @@ class FunctionalTests: XCTestCase {
5151
}
5252

5353
func testXcodeProjWithPkgConfig() {
54-
#if false
54+
#if os(macOS)
5555
fixture(name: "Miscellaneous/PkgConfig") { prefix in
5656
let systemModule = prefix.appending(component: "SystemModule")
5757
// Create a shared library.
@@ -101,7 +101,7 @@ class FunctionalTests: XCTestCase {
101101
}
102102

103103
func testSystemModule() {
104-
#if false
104+
#if os(macOS)
105105
// Because there isn't any one system target that we can depend on for testing purposes, we build our own.
106106
try! write(path: AbsolutePath("/tmp/fake.h")) { stream in
107107
stream <<< "extern const char GetFakeString(void);\n"
@@ -147,10 +147,19 @@ func XCTAssertXcodeBuild(project: AbsolutePath, file: StaticString = #file, line
147147
env["TOOLCHAINS"] = "default"
148148
}
149149
let xcconfig = project.appending(component: "overrides.xcconfig")
150-
let swiftCompilerPath = Resources.default.swiftCompiler.asString
151-
try localFileSystem.writeFileContents(xcconfig) {
152-
$0 <<< "SWIFT_EXEC = " <<< swiftCompilerPath
150+
let swiftCompilerPath = Resources.default.swiftCompiler
151+
152+
// Override path to the Swift compiler.
153+
let stream = BufferedOutputByteStream()
154+
stream <<< "SWIFT_EXEC = " <<< swiftCompilerPath.asString <<< "\n"
155+
156+
// Override Swift libary path, if present.
157+
let swiftLibraryPath = resolveSymlinks(swiftCompilerPath).appending(components: "..", "..", "lib", "swift", "macosx")
158+
if localFileSystem.exists(swiftCompilerPath) {
159+
stream <<< "SWIFT_LIBRARY_PATH = " <<< swiftLibraryPath.asString <<< "\n"
153160
}
161+
try localFileSystem.writeFileContents(xcconfig, bytes: stream.bytes)
162+
154163
try Process.checkNonZeroExit(
155164
args: "xcodebuild", "-project", project.asString, "-alltargets", "-xcconfig", xcconfig.asString, environment: env)
156165
} catch {

0 commit comments

Comments
 (0)