Skip to content

Generate entrypoints for test bundles on macOS #9018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ extension PackagePIFProjectBuilder {
on: moduleDependencyGUID,
platformFilters: packageConditions
.toPlatformFilter(toolsVersion: package.manifest.toolsVersion),
linkProduct: true
// Only link the testable version of executables which use Swift, as we do not currently support renaming entrypoints written in other languages.
linkProduct: moduleDependency.usesSwift
)
log(.debug, indent: 1, "Added linked dependency on target '\(moduleDependencyGUID)'")
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
settings["ARCHS"] = architectures.joined(separator: " ")
}

// When building with the CLI for macOS, test bundles should generate entrypoints for compatibility with swiftpm-testing-helper.
if buildParameters.triple.isMacOSX {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS, or all Darwin?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well we don't support command-line execution of tests on other Apple platforms anyway, so...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execution doesn't matter, this is about the build. The build system does not assume that the machine/tool building the tests is the one running them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay: we support neither building nor executing tests on iOS using SwiftPM.

settings["GENERATE_TEST_ENTRYPOINTS_FOR_BUNDLES"] = "YES"
}

func reportConflict(_ a: String, _ b: String) throws -> String {
throw StringError("Build parameters constructed conflicting settings overrides '\(a)' and '\(b)'")
}
Expand Down
9 changes: 3 additions & 6 deletions Tests/CommandsTests/TestCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct TestCommandTests {
}
} when: {
(buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .windows)
|| (buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .macOS)
|| (buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .linux && CiEnvironment.runningInSmokeTestPipeline)
|| (buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem == .linux && CiEnvironment.runningInSelfHostedPipeline) // error: SwiftCompile normal x86_64 /tmp/Miscellaneous_EchoExecutable.sxkNTX/Miscellaneous_EchoExecutable/.build/x86_64-unknown-linux-gnu/Intermediates.noindex/EchoExecutable.build/Debug-linux/TestSuite-test-runner.build/DerivedSources/test_entry_point.swift failed with a nonzero exit code
}
Expand Down Expand Up @@ -220,7 +221,6 @@ struct TestCommandTests {
}

@Test(
.issue("https://github.com/swiftlang/swift-package-manager/issues/8955", relationship: .defect),
arguments: SupportedBuildSystemOnAllPlatforms, BuildConfiguration.allCases,
)
func enableDisableTestabilityDefaultShouldRunWithTestability(
Expand Down Expand Up @@ -273,7 +273,7 @@ struct TestCommandTests {
}

#expect(
stderr.contains("was not compiled for testing"),
stderr.contains("was not compiled for testing") || stderr.contains("ignore swiftmodule built without '-enable-testing'"),
"got stdout: \(stdout), stderr: \(stderr)",
)
}
Expand Down Expand Up @@ -667,7 +667,6 @@ struct TestCommandTests {
} when: {
(buildSystem == .swiftbuild && .linux == ProcessInfo.hostOperatingSystem)
|| ProcessInfo.hostOperatingSystem == .windows
|| (buildSystem == .swiftbuild && .macOS == ProcessInfo.hostOperatingSystem && tcdata.testRunner == .SwiftTesting)
}
}

Expand Down Expand Up @@ -994,8 +993,6 @@ struct TestCommandTests {
}

@Test(
.SWBINTTODO("Fails to find test executable"),
.issue("https://github.com/swiftlang/swift-package-manager/pull/8722", relationship: .fixedBy),
arguments: SupportedBuildSystemOnAllPlatforms, BuildConfiguration.allCases,
)
func basicSwiftTestingIntegration(
Expand All @@ -1016,7 +1013,7 @@ struct TestCommandTests {
)
}
} when: {
buildSystem == .swiftbuild
buildSystem == .swiftbuild && ProcessInfo.hostOperatingSystem != .macOS
}
}

Expand Down