Skip to content

Commit bbe452f

Browse files
committed
[test] Add same-package host tool dependency to withHostToolsPackages
This exposes the issue where `isTargetSuitableForPlatformForIndex` returns `false` in the target and package build. Also change `testHostToolsAndDependenciesAreBuiltDuringIndexingPreparationForPackage` to use a dependency package and test both the target and package build descriptions.
1 parent 1634c00 commit bbe452f

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

Sources/SWBTestSupport/BuildOperationTester.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,7 @@ package final class BuildOperationTester {
15531553
/// Construct 'prepare' index build operation, and test the result.
15541554
package func checkIndexBuild<T>(
15551555
prepareTargets: [String],
1556+
buildTargets: [any TestTarget]? = nil,
15561557
workspaceOperation: Bool = true,
15571558
runDestination: RunDestinationInfo? = nil,
15581559
persistent: Bool = false,
@@ -1561,6 +1562,7 @@ package final class BuildOperationTester {
15611562
) async throws -> T {
15621563
let buildRequest = try Self.buildRequestForIndexOperation(
15631564
workspace: workspace,
1565+
buildTargets: buildTargets,
15641566
prepareTargets: prepareTargets,
15651567
workspaceOperation: workspaceOperation,
15661568
runDestination: runDestination,

Tests/SWBBuildSystemTests/HostBuildToolBuildOperationTests.swift

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
214214
let hostToolsPackage = try await TestPackageProject(
215215
"HostToolsPackage",
216216
groupTree: TestGroup("Foo", children: [
217+
TestFile("tooldep.swift"),
217218
TestFile("tool.swift"),
218219
TestFile("lib.swift"),
219220
]),
@@ -230,11 +231,18 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
230231
]),
231232
],
232233
targets: [
234+
TestStandardTarget("HostToolDep", type: .objectFile, buildPhases: [
235+
TestSourcesBuildPhase(["tooldep.swift"]),
236+
]),
233237
TestStandardTarget("HostTool", type: .hostBuildTool, buildPhases: [
234238
TestSourcesBuildPhase(["tool.swift"]),
235-
TestFrameworksBuildPhase([TestBuildFile(.target("PackageDepProduct"))])
239+
TestFrameworksBuildPhase([
240+
TestBuildFile(.target("PackageDepProduct")),
241+
TestBuildFile(.target("HostToolDep")),
242+
]),
236243
], dependencies: [
237-
"PackageDepProduct"
244+
"PackageDepProduct",
245+
"HostToolDep",
238246
]),
239247
TestStandardTarget("HostToolClientLib", type: .objectFile, buildPhases: [
240248
TestSourcesBuildPhase(["lib.swift"]),
@@ -274,14 +282,22 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
274282
"""
275283
}
276284

285+
try await fs.writeFileContents(root.join("HostToolsPackage/tooldep.swift")) { stream in
286+
stream <<<
287+
"""
288+
public let samePackageMsg = "Hello from host tool same-package dependency!"
289+
"""
290+
}
291+
277292
try await fs.writeFileContents(root.join("HostToolsPackage/tool.swift")) { stream in
278293
stream <<<
279294
"""
280295
import PackageDep
296+
import HostToolDep
281297
282298
@main struct Foo {
283299
static func main() {
284-
print("Hello from host tool! " + dependencyMessage)
300+
print("Hello from host tool! " + dependencyMessage + samePackageMsg)
285301
}
286302
}
287303
"""
@@ -405,15 +421,57 @@ fileprivate struct HostBuildToolBuildOperationTests: CoreBasedTests {
405421
}
406422
}
407423

408-
@Test(.requireSDKs(.macOS, .iOS), arguments: [RunDestinationInfo.anyMac, .anyMacCatalyst, .anyiOSDevice])
409-
func testHostToolsAndDependenciesAreBuiltDuringIndexingPreparationForPackage(destination: RunDestinationInfo) async throws {
410-
try await withHostToolsPackages { tester, testWorkspace in
411-
try await tester.checkIndexBuild(prepareTargets: testWorkspace.projects[1].targets.map(\.guid), workspaceOperation: false, runDestination: destination, persistent: true) { results in
424+
@Test(.requireSDKs(.macOS, .iOS), arguments: [RunDestinationInfo.anyMac, .anyMacCatalyst, .anyiOSDevice], [true, false])
425+
func testHostToolsAndDependenciesAreBuiltDuringIndexingPreparationForPackage(
426+
destination: RunDestinationInfo, targetBuild: Bool
427+
) async throws {
428+
let clientPackage = try await TestPackageProject(
429+
"ClientPackage",
430+
groupTree: TestGroup("Client", children: [
431+
TestFile("main.swift"),
432+
]),
433+
buildConfigurations: [
434+
TestBuildConfiguration(
435+
"Debug",
436+
buildSettings: [
437+
"SWIFT_VERSION": swiftVersion,
438+
"GENERATE_INFOPLIST_FILE": "YES",
439+
"PRODUCT_NAME": "$(TARGET_NAME)",
440+
"CODE_SIGNING_ALLOWED": "NO",
441+
"SDKROOT": "auto",
442+
"SUPPORTED_PLATFORMS": "$(AVAILABLE_PLATFORMS)",
443+
]),
444+
],
445+
targets: [
446+
TestStandardTarget("HostToolClient", type: .objectFile, buildPhases: [
447+
TestSourcesBuildPhase(["main.swift"]),
448+
TestFrameworksBuildPhase([TestBuildFile(.target("HostToolClientLibProduct"))]),
449+
], dependencies: [
450+
"HostToolClientLibProduct"
451+
]),
452+
])
453+
454+
try await withHostToolsPackages(clients: clientPackage) { tester, testWorkspace in
455+
try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("ClientPackage/main.swift")) { stream in
456+
stream <<<
457+
"""
458+
print("Hello, world!")
459+
"""
460+
}
461+
462+
let clientTarget = try #require(clientPackage.targets.first)
463+
try await tester.checkIndexBuild(
464+
prepareTargets: [clientTarget.guid],
465+
buildTargets: targetBuild ? [clientTarget] : nil,
466+
workspaceOperation: false, runDestination: destination,
467+
persistent: true
468+
) { results in
412469
results.checkNoDiagnostics()
413470

414471
results.checkTaskExists(.matchTargetName("HostTool"), .matchRuleType("Ld"))
415472
try results.checkTask(.matchTargetName("HostTool"), .matchRuleType(ProductPlan.preparedForIndexPreCompilationRuleName)) { task in
416473
try results.checkTaskFollows(task, .matchTargetName("PackageDep"), .matchRuleType("Libtool"))
474+
try results.checkTaskFollows(task, .matchTargetName("HostToolDep"), .matchRuleType("SwiftDriver Compilation"))
417475
}
418476
}
419477
}

0 commit comments

Comments
 (0)