Skip to content

More swiftbuild testing #8333

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

Merged
merged 26 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fcaf11e
Tests: Augment Command Tests
bkhouri Feb 4, 2025
0620a2f
Attempt solution at a custom XFail for XCTest..
bkhouri Feb 6, 2025
d4b0761
Revert "Attempt solution at a custom XFail for XCTest.."
bkhouri Mar 3, 2025
ddc506e
Rebase and update the build system integration tests
cmcgee1024 Mar 6, 2025
7f24a48
Fix try XCTSkip with throw XCTSkip instead so that reasons show up in…
cmcgee1024 Mar 6, 2025
5129e96
Remove the PlatformCondition test for a follow-on PR
cmcgee1024 Mar 6, 2025
3b4fa57
Conditionally skip tests on non-macOS that are failing with a summary…
cmcgee1024 Mar 6, 2025
6dc555e
Remove additional test case referencing the platform conditional fixture
cmcgee1024 Mar 6, 2025
51d282b
Skip failing BuildCommandXcodeTests
cmcgee1024 Mar 6, 2025
1226ba8
Skip additional tests that fail on Linux
cmcgee1024 Mar 6, 2025
eb1b930
Apply SWBINTODO label to be able to query the codebase for swift-buil…
cmcgee1024 Mar 6, 2025
c3407d6
Skip the verification of the swift run of an executable from swiftbui…
cmcgee1024 Mar 6, 2025
0036cad
Normalize on tag SWBINTTODO
cmcgee1024 Mar 6, 2025
a280640
Skip the integration testing of swift test the output of a swiftbuild…
cmcgee1024 Mar 6, 2025
55d270b
Add a check in failing test if Swift Build is not being linked in.
cmcgee1024 Mar 7, 2025
d175cd0
Refine TODOs to provide more details about the specific test failures
cmcgee1024 Mar 7, 2025
f837cc3
Make another test conditional on swift-build support being available
cmcgee1024 Mar 8, 2025
9d412e9
Re-enable duplicate symbol checks and fill in test skip explanation f…
cmcgee1024 Mar 8, 2025
4fb9a12
Restore test cases and fix compile error
cmcgee1024 Mar 8, 2025
ea9f97f
Remove invalid test case
cmcgee1024 Mar 8, 2025
153eb90
Reword the skip message for the abstract test classes
cmcgee1024 Mar 10, 2025
7febe69
Merge branch 'main' of github.com:cmcgee1024/swift-package-manager in…
cmcgee1024 Mar 12, 2025
9427855
Remove remnants of the useXcodeBuildSystemPath property
cmcgee1024 Mar 12, 2025
62ec8e2
Tidy up formatting and unnecessary comment
cmcgee1024 Mar 12, 2025
9c4e25c
Merge branch 'main' of https://github.com/swiftlang/swift-package-man…
cmcgee1024 Mar 13, 2025
c5746ca
Merge branch 'main' of https://github.com/swiftlang/swift-package-man…
cmcgee1024 Mar 14, 2025
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
26 changes: 21 additions & 5 deletions IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,27 @@ final class SwiftPMTests: XCTestCase {
#endif

// Test SwiftBuildSystem
try withTemporaryDirectory { tmpDir in
let packagePath = tmpDir.appending(component: "foo")
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.

try withTemporaryDirectory { tmpDir in
let packagePath = tmpDir.appending(component: "foo")
try localFileSystem.createDirectory(packagePath)
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
try sh(swiftBuild, "--package-path", packagePath, "--build-system", "swiftbuild")
// SWBINTTODO: Path issues related to swift run of the output from swiftbuild buildsystem
//let (stdout, stderr) = try sh(swiftRun, "--package-path", packagePath, "--build-system", "swiftbuild")
//XCTAssertMatch(stdout, .contains("Hello, world!"))
}
}

do {
try withTemporaryDirectory { tmpDir in
let packagePath = tmpDir.appending(component: "foo")
try localFileSystem.createDirectory(packagePath)
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "library")
try sh(swiftBuild, "--package-path", packagePath, "--build-system", "swiftbuild")
// SWBINTTODO: Path issues related to swift test of the output from a swiftbuild buildsystem
//try sh(swiftTest, "--package-path", packagePath, "--build-system", "swiftbuild")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreCommands/SwiftCommandState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ extension BuildSystemProvider.Kind {
return false
}
}

fileprivate var additionalFileRules: [FileRuleDescription] {
switch self {
case .xcode, .swiftbuild:
Expand Down
22 changes: 12 additions & 10 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,18 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
header: ""
)

do {
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString) { session, _ in
// Load the workspace, and set the system information to the default
do {
try await session.loadWorkspace(containerPath: self.buildParameters.pifManifest.pathString)
try await session.setSystemInfo(.default())
} catch {
self.observabilityScope.emit(error: error.localizedDescription)
throw error
}
do {
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString) { session, _ in
self.outputStream.send("Building for \(self.buildParameters.configuration == .debug ? "debugging" : "production")...\n")

// Load the workspace, and set the system information to the default
do {
try await session.loadWorkspace(containerPath: self.buildParameters.pifManifest.pathString)
try await session.setSystemInfo(.default())
} catch {
self.observabilityScope.emit(error: error.localizedDescription)
throw error
}

// Find the targets to build.
let configuredTargets: [SWBConfiguredTarget]
Expand Down
23 changes: 15 additions & 8 deletions Sources/_InternalTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public func testWithTemporaryDirectory<Result>(
}
}

public enum TestError: Error {
case platformNotSupported
}

@discardableResult public func fixture<T>(
name: String,
createGitRepo: Bool = true,
Expand Down Expand Up @@ -252,7 +256,7 @@ public func getBuildSystemArgs(for buildSystem: BuildSystemProvider.Kind?) -> [S

@discardableResult
public func executeSwiftBuild(
_ packagePath: AbsolutePath,
_ packagePath: AbsolutePath?,
configuration: Configuration = .Debug,
extraArgs: [String] = [],
Xcc: [String] = [],
Expand All @@ -274,8 +278,8 @@ public func executeSwiftBuild(

@discardableResult
public func executeSwiftRun(
_ packagePath: AbsolutePath,
_ executable: String,
_ packagePath: AbsolutePath?,
_ executable: String?,
configuration: Configuration = .Debug,
extraArgs: [String] = [],
Xcc: [String] = [],
Expand All @@ -292,13 +296,15 @@ public func executeSwiftRun(
Xswiftc: Xswiftc,
buildSystem: buildSystem
)
args.append(executable)
if let executable {
args.append(executable)
}
return try await SwiftPM.Run.execute(args, packagePath: packagePath, env: env)
}

@discardableResult
public func executeSwiftPackage(
_ packagePath: AbsolutePath,
_ packagePath: AbsolutePath?,
configuration: Configuration = .Debug,
extraArgs: [String] = [],
Xcc: [String] = [],
Expand All @@ -320,7 +326,7 @@ public func executeSwiftPackage(

@discardableResult
public func executeSwiftPackageRegistry(
_ packagePath: AbsolutePath,
_ packagePath: AbsolutePath?,
configuration: Configuration = .Debug,
extraArgs: [String] = [],
Xcc: [String] = [],
Expand All @@ -342,13 +348,14 @@ public func executeSwiftPackageRegistry(

@discardableResult
public func executeSwiftTest(
_ packagePath: AbsolutePath,
_ packagePath: AbsolutePath?,
configuration: Configuration = .Debug,
extraArgs: [String] = [],
Xcc: [String] = [],
Xld: [String] = [],
Xswiftc: [String] = [],
env: Environment? = nil,
throwIfCommandFails: Bool = false,
buildSystem: BuildSystemProvider.Kind = .native
) async throws -> (stdout: String, stderr: String) {
let args = swiftArgs(
Expand All @@ -359,7 +366,7 @@ public func executeSwiftTest(
Xswiftc: Xswiftc,
buildSystem: buildSystem
)
return try await SwiftPM.Test.execute(args, packagePath: packagePath, env: env)
return try await SwiftPM.Test.execute(args, packagePath: packagePath, env: env, throwIfCommandFails: throwIfCommandFails)
}

private func swiftArgs(
Expand Down
2 changes: 1 addition & 1 deletion Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension Build.BuildPlan {

class BuildPlanTestCase: BuildSystemProviderTestCase {
override func setUpWithError() throws {
try XCTSkipIf(type(of: self) == BuildPlanTestCase.self, "Pay no attention to the class behind the curtain.")
try XCTSkipIf(type(of: self) == BuildPlanTestCase.self, "Skipping this test since it will be run in subclasses that will provide different build systems to test.")
}

let inputsDir = AbsolutePath(#file).parentDirectory.appending(components: "Inputs")
Expand Down
37 changes: 35 additions & 2 deletions Tests/CommandsTests/APIDiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import Basics
import Build
import Commands
import SPMBuildCore

@_spi(SwiftPMInternal)
import DriverSupport
Expand All @@ -24,7 +25,11 @@ import _InternalTestSupport
import Workspace
import XCTest

final class APIDiffTests: CommandsTestCase {
class APIDiffTestCase: CommandsBuildProviderTestCase {
override func setUpWithError() throws {
try XCTSkipIf(type(of: self) == APIDiffTestCase.self, "Skipping this test since it will be run in subclasses that will provide different build systems to test.")
}

@discardableResult
private func execute(
_ args: [String],
Expand All @@ -34,7 +39,12 @@ final class APIDiffTests: 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 executeSwiftPackage(
packagePath,
extraArgs: args,
env: environment,
buildSystem: buildSystemProvider
)
}

func skipIfApiDigesterUnsupportedOrUnset() throws {
Expand Down Expand Up @@ -444,3 +454,26 @@ final class APIDiffTests: CommandsTestCase {
}
}
}

class APIDiffNativeTests: APIDiffTestCase {

override open var buildSystemProvider: BuildSystemProvider.Kind {
return .native
}

override func skipIfApiDigesterUnsupportedOrUnset() throws {
try super.skipIfApiDigesterUnsupportedOrUnset()
}

}

class APIDiffSwiftBuildTests: APIDiffTestCase {

override open var buildSystemProvider: BuildSystemProvider.Kind {
return .swiftbuild
}

override func skipIfApiDigesterUnsupportedOrUnset() throws {
try super.skipIfApiDigesterUnsupportedOrUnset()
}
}
Loading