Skip to content

Commit d78246c

Browse files
authored
Inherit current environment in build tool plugin custom tasks (#8880)
The native build system is extending the calling environment, such as the PATH to the build tool invocations. Update the PIF Builder to do the same. Enable testing of vendored binary build tools on macOS with the swiftbuild build system.
1 parent 376414f commit d78246c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Sources/SwiftBuildSupport/PIFBuilder.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,16 @@ public final class PIFBuilder {
361361

362362
let runtimeLibPaths = buildParameters.toolchain.runtimeLibraryPaths
363363

364+
// Add paths to swift standard runtime libraries to the library path so that they can be found at runtime
364365
for libPath in runtimeLibPaths {
365366
newEnv.appendPath(key: .libraryPath, value: libPath.pathString)
366367
}
367368

369+
// Append the system path at the end so that necessary system tool paths can be found
370+
if let pathValue = Environment.current[EnvironmentKey.path] {
371+
newEnv.appendPath(key: .path, value: pathValue)
372+
}
373+
368374
let writableDirectories: [AbsolutePath] = [pluginOutputDir]
369375

370376
return PackagePIFBuilder.CustomBuildCommand(

Tests/FunctionalTests/PluginTests.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,20 @@ final class PluginTests {
299299

300300
@Test(
301301
.enabled(if: (try? UserToolchain.default)!.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency"),
302-
.enabled(if: ProcessInfo.hostOperatingSystem == .macOS, "Test is only supported on macOS")
302+
.enabled(if: ProcessInfo.hostOperatingSystem == .macOS, "Test is only supported on macOS"),
303+
arguments: [BuildSystemProvider.Kind.native, .swiftbuild]
303304
)
304-
func testUseOfVendedBinaryTool() async throws {
305+
func testUseOfVendedBinaryTool(buildSystem: BuildSystemProvider.Kind) async throws {
305306
try await fixture(name: "Miscellaneous/Plugins") { fixturePath in
306-
let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MyBinaryToolPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool"])
307-
#expect(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)")
308-
#expect(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)")
307+
let (stdout, _) = try await executeSwiftBuild(fixturePath.appending("MyBinaryToolPlugin"), configuration: .debug, extraArgs: ["--product", "MyLocalTool"], buildSystem: buildSystem)
308+
if buildSystem == .native {
309+
#expect(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)")
310+
#expect(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n(stdout)")
311+
} else if buildSystem == .swiftbuild {
312+
#expect(stdout.contains("Build complete!"), "stdout:\n\(stdout)")
313+
} else {
314+
Issue.record("Test has no expectation for \(buildSystem)")
315+
}
309316
}
310317
}
311318

0 commit comments

Comments
 (0)