Skip to content

Commit 735ddd9

Browse files
cmcgee1024bkhouri
andauthored
More swiftbuild testing (#8333)
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. --------- Co-authored-by: Sam Khouri <[email protected]>
1 parent efde1c6 commit 735ddd9

File tree

14 files changed

+698
-220
lines changed

14 files changed

+698
-220
lines changed

IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift

+21-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,27 @@ final class SwiftPMTests: XCTestCase {
5757
#endif
5858

5959
// Test SwiftBuildSystem
60-
try withTemporaryDirectory { tmpDir in
61-
let packagePath = tmpDir.appending(component: "foo")
62-
try localFileSystem.createDirectory(packagePath)
63-
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
64-
try sh(swiftBuild, "--package-path", packagePath, "--build-system", "swiftbuild")
60+
do {
61+
try withTemporaryDirectory { tmpDir in
62+
let packagePath = tmpDir.appending(component: "foo")
63+
try localFileSystem.createDirectory(packagePath)
64+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
65+
try sh(swiftBuild, "--package-path", packagePath, "--build-system", "swiftbuild")
66+
// SWBINTTODO: Path issues related to swift run of the output from swiftbuild buildsystem
67+
//let (stdout, stderr) = try sh(swiftRun, "--package-path", packagePath, "--build-system", "swiftbuild")
68+
//XCTAssertMatch(stdout, .contains("Hello, world!"))
69+
}
70+
}
71+
72+
do {
73+
try withTemporaryDirectory { tmpDir in
74+
let packagePath = tmpDir.appending(component: "foo")
75+
try localFileSystem.createDirectory(packagePath)
76+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "library")
77+
try sh(swiftBuild, "--package-path", packagePath, "--build-system", "swiftbuild")
78+
// SWBINTTODO: Path issues related to swift test of the output from a swiftbuild buildsystem
79+
//try sh(swiftTest, "--package-path", packagePath, "--build-system", "swiftbuild")
80+
}
6581
}
6682
}
6783

Sources/CoreCommands/SwiftCommandState.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ extension BuildSystemProvider.Kind {
10291029
return false
10301030
}
10311031
}
1032-
1032+
10331033
fileprivate var additionalFileRules: [FileRuleDescription] {
10341034
switch self {
10351035
case .xcode, .swiftbuild:

Sources/SwiftBuildSupport/SwiftBuildSystem.swift

+12-10
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,18 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
256256
header: ""
257257
)
258258

259-
do {
260-
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString) { session, _ in
261-
// Load the workspace, and set the system information to the default
262-
do {
263-
try await session.loadWorkspace(containerPath: self.buildParameters.pifManifest.pathString)
264-
try await session.setSystemInfo(.default())
265-
} catch {
266-
self.observabilityScope.emit(error: error.localizedDescription)
267-
throw error
268-
}
259+
do {
260+
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString) { session, _ in
261+
self.outputStream.send("Building for \(self.buildParameters.configuration == .debug ? "debugging" : "production")...\n")
262+
263+
// Load the workspace, and set the system information to the default
264+
do {
265+
try await session.loadWorkspace(containerPath: self.buildParameters.pifManifest.pathString)
266+
try await session.setSystemInfo(.default())
267+
} catch {
268+
self.observabilityScope.emit(error: error.localizedDescription)
269+
throw error
270+
}
269271

270272
// Find the targets to build.
271273
let configuredTargets: [SWBConfiguredTarget]

Sources/_InternalTestSupport/misc.swift

+15-8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public func testWithTemporaryDirectory<Result>(
117117
}
118118
}
119119

120+
public enum TestError: Error {
121+
case platformNotSupported
122+
}
123+
120124
@discardableResult public func fixture<T>(
121125
name: String,
122126
createGitRepo: Bool = true,
@@ -252,7 +256,7 @@ public func getBuildSystemArgs(for buildSystem: BuildSystemProvider.Kind?) -> [S
252256

253257
@discardableResult
254258
public func executeSwiftBuild(
255-
_ packagePath: AbsolutePath,
259+
_ packagePath: AbsolutePath?,
256260
configuration: Configuration = .Debug,
257261
extraArgs: [String] = [],
258262
Xcc: [String] = [],
@@ -274,8 +278,8 @@ public func executeSwiftBuild(
274278

275279
@discardableResult
276280
public func executeSwiftRun(
277-
_ packagePath: AbsolutePath,
278-
_ executable: String,
281+
_ packagePath: AbsolutePath?,
282+
_ executable: String?,
279283
configuration: Configuration = .Debug,
280284
extraArgs: [String] = [],
281285
Xcc: [String] = [],
@@ -292,13 +296,15 @@ public func executeSwiftRun(
292296
Xswiftc: Xswiftc,
293297
buildSystem: buildSystem
294298
)
295-
args.append(executable)
299+
if let executable {
300+
args.append(executable)
301+
}
296302
return try await SwiftPM.Run.execute(args, packagePath: packagePath, env: env)
297303
}
298304

299305
@discardableResult
300306
public func executeSwiftPackage(
301-
_ packagePath: AbsolutePath,
307+
_ packagePath: AbsolutePath?,
302308
configuration: Configuration = .Debug,
303309
extraArgs: [String] = [],
304310
Xcc: [String] = [],
@@ -320,7 +326,7 @@ public func executeSwiftPackage(
320326

321327
@discardableResult
322328
public func executeSwiftPackageRegistry(
323-
_ packagePath: AbsolutePath,
329+
_ packagePath: AbsolutePath?,
324330
configuration: Configuration = .Debug,
325331
extraArgs: [String] = [],
326332
Xcc: [String] = [],
@@ -342,13 +348,14 @@ public func executeSwiftPackageRegistry(
342348

343349
@discardableResult
344350
public func executeSwiftTest(
345-
_ packagePath: AbsolutePath,
351+
_ packagePath: AbsolutePath?,
346352
configuration: Configuration = .Debug,
347353
extraArgs: [String] = [],
348354
Xcc: [String] = [],
349355
Xld: [String] = [],
350356
Xswiftc: [String] = [],
351357
env: Environment? = nil,
358+
throwIfCommandFails: Bool = false,
352359
buildSystem: BuildSystemProvider.Kind = .native
353360
) async throws -> (stdout: String, stderr: String) {
354361
let args = swiftArgs(
@@ -359,7 +366,7 @@ public func executeSwiftTest(
359366
Xswiftc: Xswiftc,
360367
buildSystem: buildSystem
361368
)
362-
return try await SwiftPM.Test.execute(args, packagePath: packagePath, env: env)
369+
return try await SwiftPM.Test.execute(args, packagePath: packagePath, env: env, throwIfCommandFails: throwIfCommandFails)
363370
}
364371

365372
private func swiftArgs(

Tests/BuildTests/BuildPlanTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension Build.BuildPlan {
4747

4848
class BuildPlanTestCase: BuildSystemProviderTestCase {
4949
override func setUpWithError() throws {
50-
try XCTSkipIf(type(of: self) == BuildPlanTestCase.self, "Pay no attention to the class behind the curtain.")
50+
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.")
5151
}
5252

5353
let inputsDir = AbsolutePath(#file).parentDirectory.appending(components: "Inputs")

Tests/CommandsTests/APIDiffTests.swift

+35-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import Basics
1414
import Build
1515
import Commands
16+
import SPMBuildCore
1617

1718
@_spi(SwiftPMInternal)
1819
import DriverSupport
@@ -24,7 +25,11 @@ import _InternalTestSupport
2425
import Workspace
2526
import XCTest
2627

27-
final class APIDiffTests: CommandsTestCase {
28+
class APIDiffTestCase: CommandsBuildProviderTestCase {
29+
override func setUpWithError() throws {
30+
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.")
31+
}
32+
2833
@discardableResult
2934
private func execute(
3035
_ args: [String],
@@ -34,7 +39,12 @@ final class APIDiffTests: CommandsTestCase {
3439
var environment = env ?? [:]
3540
// don't ignore local packages when caching
3641
environment["SWIFTPM_TESTS_PACKAGECACHE"] = "1"
37-
return try await SwiftPM.Package.execute(args, packagePath: packagePath, env: environment)
42+
return try await executeSwiftPackage(
43+
packagePath,
44+
extraArgs: args,
45+
env: environment,
46+
buildSystem: buildSystemProvider
47+
)
3848
}
3949

4050
func skipIfApiDigesterUnsupportedOrUnset() throws {
@@ -444,3 +454,26 @@ final class APIDiffTests: CommandsTestCase {
444454
}
445455
}
446456
}
457+
458+
class APIDiffNativeTests: APIDiffTestCase {
459+
460+
override open var buildSystemProvider: BuildSystemProvider.Kind {
461+
return .native
462+
}
463+
464+
override func skipIfApiDigesterUnsupportedOrUnset() throws {
465+
try super.skipIfApiDigesterUnsupportedOrUnset()
466+
}
467+
468+
}
469+
470+
class APIDiffSwiftBuildTests: APIDiffTestCase {
471+
472+
override open var buildSystemProvider: BuildSystemProvider.Kind {
473+
return .swiftbuild
474+
}
475+
476+
override func skipIfApiDigesterUnsupportedOrUnset() throws {
477+
try super.skipIfApiDigesterUnsupportedOrUnset()
478+
}
479+
}

0 commit comments

Comments
 (0)