Skip to content
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

More swiftbuild testing #8333

Merged
merged 26 commits into from
Mar 14, 2025
Merged

Conversation

cmcgee1024
Copy link
Member

@cmcgee1024 cmcgee1024 commented Mar 6, 2025

Add more verifications of the swiftbuild build system to ensure correctness moving forward. Tag various discovered swift-build integration issues with the tag SWBINTTODO with a general description of the problem encountered to enable categorization for further exploration activities.

Motivation:

The swiftbuild integration has only the most basic smoke testing of its functionality. Add more automated tests, and explicit skips where there are functionality gaps that need to be addressed.

try localFileSystem.createDirectory(packagePath)
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
try sh(swiftBuild, "--package-path", packagePath, "--build-system", "swiftbuild")
do {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these do blocks intended to swallow all errors? Seems like this test should be skipped instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

These do blocks seem to throw errors, and that's why I had to comment out the assert at the bottom. The original intent is unclear. You can see them in #8276 too.

The goal is to increase test coverage, even if the assert/test at the end don't currently work. I think that these do exercise the build function.

final class APIDiffTests: CommandsTestCase {
class APIDiffTestCase: CommandsBuildProviderTestCase {
override func setUpWithError() throws {
try XCTSkipIf(type(of: self) == APIDiffTestCase.self, "Pay no attention to the class behind the curtain.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to make sure this class is "abstract" and ensure its always extended? I don't want to be a wet paper bag, but a more clear message would help clarify the intent.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's correct. I've updated this message to help clarify that.

@@ -173,7 +173,7 @@ extension BuildSystemProvider.Kind {
public var usesXcodeBuildEngine: Bool {
switch self {
case .native: return false
case .swiftbuild: return false
case .swiftbuild: return true
Copy link
Member

Choose a reason for hiding this comment

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

Don't change this. I am removing this calculated boolean in my swift run/test PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, is that change going in imminently? If not, this change really improves the test success rates until that other PR lands.

@@ -191,3 +191,16 @@ public enum BuildSystemUtilities {
return try AbsolutePath(validating: env, relativeTo: workingDir)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Same with this. I am revamping how this path is calculated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same comment as above. Which PR will be merged first?

bkhouri and others added 16 commits March 10, 2025 18:23
Augment Commands Tests to run against the Native and Swift Build build
systems.

- BuildCommandTests
- TestCommandTests
- RunCommandTests
- APIDiffTests
- PackageCommandTests

Also,
  - Add a new BuildCommandTest and RunCommandTest test case that ensures
    a package with target conditionals builds and runs successfully
  - update BuildSystemProvider.Kind to define a "useXcodeBuildSystemPath"
    variable instead of sprinkling the `buildSystem == .xcode` all over
    the place
  - Augment the Swift Build integration test to run `swift test`

TODO:
  - Instead of marking test failures as  "Skipped", See if we can mark
    them as "expected fail" so we are forced to update the test once the
    production code has been update to support the "feature".

more update'
This reverts commit 3e06c8f497b33b24aefc18290d9226dea01525e6.
Remove the duplicate symbol checks for use in a future enhancement

Refactor xcode specific tests into the new build system matrix
Skip Xcode build system variant of tests that are failing
Fix double-override in BuildCommandTests
@cmcgee1024 cmcgee1024 force-pushed the more_swiftbuild_testing branch from 02771e2 to 153eb90 Compare March 10, 2025 22:23
@cmcgee1024
Copy link
Member Author

@swift-ci please test

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024
Copy link
Member Author

Please test with following pull request:
swiftlang/swift-build#300

@swift-ci test Windows

@cmcgee1024
Copy link
Member Author

@swift-ci please test

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024 cmcgee1024 enabled auto-merge (squash) March 14, 2025 12:00
@@ -89,12 +108,6 @@ final class BuildCommandTests: CommandsTestCase {
XCTAssertMatch(stdout, .contains("SEE ALSO: swift run, swift package, swift test"))
}

func testCommandDoesNotEmitDuplicateSymbols() async throws {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: why was this test removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This test was removed because it doesn't work with the new framework. The --help option isn't accepted by the executable it tries to run.

Copy link
Contributor

Choose a reason for hiding this comment

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

we may need to replace try await execute(["--help"]) with try await SwiftPM.Build.execute(....)

// Print correct path when building with XCBuild.
#if os(macOS)
let xcodeDebugOutput = try await execute(["--build-system", "xcode", "--show-bin-path"], packagePath: fullPath)
guard buildSystemProvider == .xcode || buildSystemProvider == .swiftbuild else {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: in order to make the intent more clear, can we move this considitional to a property/attribute in BuildSystemProvider.Kind so that we could do guard buildSystemProvider.supportsBinarySymLinks else { return } (or similar)

#if os(macOS)
let xcodeDebugOutput = try await execute(["--build-system", "xcode", "--show-bin-path"], packagePath: fullPath)
guard buildSystemProvider == .xcode || buildSystemProvider == .swiftbuild else {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

thought (blocking): Can we call this guard as the very first step in the test implementation, and "Skip" the test in the else block so we don't get a "false positive".

e.g.

func testBinSymlink() async throws {
    guard buildSystemProvider.supportsBinarySymlink {
        XCTSkip("Build Provider \(buildSystemProvider) does not support binary symbolic links")
        return
    }

    try await fixture (.....) {
        ...
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

According to conventionalcomments.org "[thoughts] are non-blocking by nature..."

If this is non-blocking then a follow-up PR could address this.

@@ -204,8 +220,16 @@ final class BuildCommandTests: CommandsTestCase {
xcodeReleaseOutput,
"\(xcbuildTargetPath.appending(components: "Products", "Release").pathString)\n"
)
#endif
}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (blocking): can we add an assertion on the debug bin path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Can this be done in a follow-up PR?


// In the case of the native build system check for the cross-compile target, only for macOS
#if os(macOS)
if buildSystem == "native" {
if buildSystemProvider == .native {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (blocking): This test only has assertions for the native build system.

Can we document the intent of this test for the other build systems? If we want to ensure the package builds successfully, can we use the XCTAssertBuilds helper function in XCTAssertHelpers.swift .

Copy link
Member Author

Choose a reason for hiding this comment

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

While this doesn't have an assertion for the non-native build system case, there is an implicit assertion that the build succeeds, which increases test coverage for the other build systems. There does not appear to be an analog to the text that this is looking for with the other build systems. So, the question is do we want more test coverage, or not because of one less assert in this test case?

@@ -40,7 +45,13 @@ final class PackageCommandTests: CommandsTestCase {
var environment = env ?? [:]
// don't ignore local packages when caching
environment["SWIFTPM_TESTS_PACKAGECACHE"] = "1"
return try await SwiftPM.Package.execute(args, packagePath: packagePath, env: environment)
// return try await self.execute(args, packagePath: packagePath, env: environment)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove commented line

Copy link
Member Author

Choose a reason for hiding this comment

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

Removing the commented line requires another 4 hour turnaround waiting on CI, and that assumes that CI doesn't break for external reasons, and there are no conflicts introduced in the interim.

@@ -40,7 +45,13 @@ final class PackageCommandTests: CommandsTestCase {
var environment = env ?? [:]
// don't ignore local packages when caching
environment["SWIFTPM_TESTS_PACKAGECACHE"] = "1"
Copy link
Contributor

Choose a reason for hiding this comment

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

question: out of curiosity, what behavioural changes does setting this environment variable have?

Copy link
Member Author

Choose a reason for hiding this comment

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

This seems out of scope of this PR. I don't know the answer.

@cmcgee1024
Copy link
Member Author

@swift-ci test Windows

@cmcgee1024 cmcgee1024 merged commit 735ddd9 into swiftlang:main Mar 14, 2025
5 checks passed
cmcgee1024 added a commit that referenced this pull request Mar 17, 2025
This is a followup to #8333 based on feedback from there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants