Skip to content

Commit 09845ac

Browse files
committed
Some fixes to get tests building on windows
- fix up library serach path when looking for IndexStore library - fix up linker search path to find the testing libraries
1 parent 6bffad0 commit 09845ac

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

Sources/SWBUniversalPlatform/TestEntryPointGenerationTool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class TestEntryPointGenerationToolSpec: GenericCommandLineToolSpec, SpecId
2525
let format = cbc.scope.evaluate(BuiltinMacros.LINKER_FILE_LIST_FORMAT)
2626
args.append(contentsOf: ["--linker-file-list-format", .literal(.init(encodingAsUTF8: format.rawValue))])
2727

28-
for toolchainLibrarySearchPath in cbc.producer.toolchains.map({ $0.librarySearchPaths }) {
28+
for toolchainLibrarySearchPath in cbc.producer.toolchains.map({ StackedSearchPath(paths: $0.librarySearchPaths.paths + $0.fallbackLibrarySearchPaths.paths, fs: $0.librarySearchPaths.fs) } ) {
2929
if let path = toolchainLibrarySearchPath.findLibrary(operatingSystem: cbc.producer.hostOperatingSystem, basename: "IndexStore") {
3030
args.append(contentsOf: ["--index-store-library-path", .path(path)])
3131
break

Sources/SWBWindowsPlatform/Plugin.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct WindowsSDKRegistryExtension: SDKRegistryExtension {
161161
guard case let .plDict(dict) = windowsSDKSettingsPlist else {
162162
throw StubError.error("Unexpected top-level property list type in \(windowsSDKSettingsPlistPath.str) (expected dictionary)")
163163
}
164-
164+
let testingLibraryPath = windowsPlatform.path.join("Developer").join("Library")
165165
let defaultProperties: [String: PropertyListItem] = [
166166
"GCC_GENERATE_DEBUGGING_SYMBOLS": .plString("NO"),
167167
"LD_DEPENDENCY_INFO_FILE": .plString(""),
@@ -170,7 +170,7 @@ struct WindowsSDKRegistryExtension: SDKRegistryExtension {
170170
"GENERATE_INTERMEDIATE_TEXT_BASED_STUBS": "NO",
171171

172172
"LIBRARY_SEARCH_PATHS": "$(inherited) $(SDKROOT)/usr/lib/swift/windows/$(CURRENT_ARCH)",
173-
173+
"TEST_LIBRARY_SEARCH_PATHS": .plString("\(testingLibraryPath.strWithPosixSlashes)/Testing-$(SWIFT_TESTING_VERSION)/usr/lib/swift/windows/$(CURRENT_ARCH) \(testingLibraryPath.strWithPosixSlashes)/XCTest-$(XCTEST_VERSION)/usr/lib/swift/windows/$(CURRENT_ARCH)"),
174174
"OTHER_SWIFT_FLAGS": "$(inherited) -libc $(DEFAULT_USE_RUNTIME)",
175175

176176
"DEFAULT_USE_RUNTIME": "MD",

Tests/SWBTaskConstructionTests/UnitTestTaskConstructionTests.swift

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ fileprivate struct UnitTestTaskConstructionTests: CoreBasedTests {
299299
}
300300
}
301301

302-
@Test(.requireSDKs(.linux))
303-
func unitTestRunnerTarget_linux() async throws {
302+
@Test(.requireSDKs(.host), .skipHostOS(.macOS))
303+
func unitTestRunnerTarget() async throws {
304304
let swiftCompilerPath = try await self.swiftCompilerPath
305305
let swiftVersion = try await self.swiftVersion
306306
let testProject = TestProject(
@@ -317,43 +317,45 @@ fileprivate struct UnitTestTaskConstructionTests: CoreBasedTests {
317317
buildSettings: [
318318
"CODE_SIGN_IDENTITY": "",
319319
"PRODUCT_NAME": "$(TARGET_NAME)",
320-
"SDKROOT": "linux",
320+
"SDKROOT": "auto",
321321
"SWIFT_VERSION": swiftVersion,
322322
"INDEX_DATA_STORE_DIR": "/index",
323-
"LINKER_DRIVER": "swiftc"
324-
]),
323+
"LINKER_DRIVER": "swiftc",
324+
])
325325
],
326326
targets: [
327327
TestStandardTarget(
328328
"UnitTestRunner",
329329
type: .swiftpmTestRunner,
330330
buildConfigurations: [
331-
TestBuildConfiguration("Debug",
332-
buildSettings: [:]),
331+
TestBuildConfiguration(
332+
"Debug",
333+
buildSettings: [:])
333334
],
334335
buildPhases: [
335336
TestSourcesBuildPhase(),
336337
TestFrameworksBuildPhase([
337-
"UnitTestTarget.so"
338-
])
338+
TestBuildFile(.target("UnitTestTarget"))
339+
]),
339340
],
340341
dependencies: ["UnitTestTarget"],
341342
),
342343
TestStandardTarget(
343344
"UnitTestTarget",
344345
type: .unitTest,
345346
buildConfigurations: [
346-
TestBuildConfiguration("Debug",
347-
buildSettings: [:]),
347+
TestBuildConfiguration(
348+
"Debug",
349+
buildSettings: [:])
348350
],
349351
buildPhases: [
350352
TestSourcesBuildPhase([
351353
"TestOne.swift",
352354
"TestTwo.swift",
353-
]),
355+
])
354356
],
355357
dependencies: [],
356-
productReferenceName: "UnitTestTarget.so"
358+
productReferenceName: "$(EXCTABLE_NAME)"
357359
),
358360
])
359361
let core = try await getCore()
@@ -363,15 +365,28 @@ fileprivate struct UnitTestTaskConstructionTests: CoreBasedTests {
363365

364366
try await fs.writeFileContents(swiftCompilerPath) { $0 <<< "binary" }
365367

366-
await tester.checkBuild(runDestination: .linux, fs: fs) { results in
368+
await tester.checkBuild(runDestination: .host, fs: fs) { results in
367369
results.checkTarget("UnitTestRunner") { target in
368370
results.checkTask(.matchTarget(target), .matchRuleType("GenerateTestEntryPoint")) { task in
369-
task.checkCommandLineMatches([.suffix("builtin-generateTestEntryPoint"), "--output", .suffix("test_entry_point.swift"), "--discover-tests", "--linker-file-list-format", .any, "--index-store-library-path", .suffix("libIndexStore.so"), "--linker-filelist", .suffix("UnitTestTarget.LinkFileList"), "--index-store", "/index", "--index-unit-base-path", "/tmp/Test/aProject/build"])
371+
task.checkCommandLineMatches([
372+
.suffix("builtin-generateTestEntryPoint"),
373+
"--output",
374+
.suffix("test_entry_point.swift"),
375+
"--discover-tests",
376+
"--linker-file-list-format",
377+
.any,
378+
"--index-store-library-path",
379+
.or(.suffix("libIndexStore.so"), .suffix("libIndexStore.dll")),
380+
"--linker-filelist", .suffix("UnitTestTarget.LinkFileList"),
381+
"--index-store", .equal(Path("/index").str),
382+
"--index-unit-base-path",
383+
.equal(Path.root.join("/tmp/Test/aProject/build").str)
384+
])
370385
task.checkInputs([
371386
.pathPattern(.suffix("UnitTestTarget.LinkFileList")),
372-
.pathPattern(.suffix("UnitTestTarget.so")),
387+
.pathPattern(.or(.suffix("UnitTestTarget.so"), .suffix("UnitTestTarget.dll"))),
388+
.namePattern(.any),
373389
.namePattern(.any),
374-
.namePattern(.any)
375390
])
376391
task.checkOutputs([.pathPattern(.suffix("test_entry_point.swift"))])
377392
}

0 commit comments

Comments
 (0)