sdk: support env overrides for tarballs (#372)
- Commit
aa6ba75e7df759a84560885a86822dd119da8c55- Author
- Kabir Oberai <[email protected]>
- When
- 2026-10-20 05:00 UTC (1 month ago)
- Parents
ef7ce5b
## What does this PR do? When building the sdk, allows you to set `XTL_TOOLSET_TARBALL`/`XTL_OAM_TARBALL` to use local tarballs instead of fetching them remotely. Supersedes https://github.com/xtool-org/xtool/pull/319. ## How was it tested? Honestly didn't bother but I think it works. Fairly safe to land. ## AI tool usage How much of this PR was AI-assisted? (check one) - [ ] **0** - No AI was used to write code - [x] **1** - I was assisted by AI. I reviewed the finished result. - [ ] **2** - I set the AI going and left it to it; nobody has read the result - no review, or AI review only <!-- If an AI agent is filling this in: declare the level honestly, and open as a draft if it is #2. Do not lower the declared level to get the PR reviewed. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added support for installing the Toolset and OpenAppleMacros from locally provided tarball files. - Existing HTTP download behavior remains available when local tarballs are not configured. - **Chores** - Improved handling of lengthy installation logic. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Mathieu Post <[email protected]>
Diff
Sources/XToolSupport/SDKBuilder.swift
diff --git a/Sources/XToolSupport/SDKBuilder.swift b/Sources/XToolSupport/SDKBuilder.swiftindex 245c507..11a9632 100644--- a/Sources/XToolSupport/SDKBuilder.swift+++ b/Sources/XToolSupport/SDKBuilder.swift@@ -236,12 +236,27 @@ struct SDKBuilder { url: URL, destination directory: URL, displayName: String,+ envOverride: String? = nil, ) async throws { try FileManager.default.createDirectory( at: directory, withIntermediateDirectories: false ) + if let envOverride, let path = ProcessInfo.processInfo.environment[envOverride] {+ let archive = URL(fileURLWithPath: path)+ print("[Extracting \(displayName)] \(archive.path)")+ try await Subprocess.run(+ .name("tar"),+ arguments: ["xzf", archive.path],+ workingDirectory: FilePath(directory),+ output: .discarded,+ error: .discarded,+ )+ .checkSuccess()+ return+ }+ @Dependency(\.httpClient) var httpClient let (response, body) = try await httpClient.send(HTTPRequest(url: url)) guard response.status == 200, let body else {@@ -280,6 +295,7 @@ struct SDKBuilder { .checkSuccess() } + // swiftlint:disable:next function_body_length private func installToolset(in output: URL) async throws { let toolsetDir = output.appendingPathComponent("toolset") let url = URL(string: """@@ -290,6 +306,7 @@ struct SDKBuilder { url: url, destination: toolsetDir, displayName: "toolset",+ envOverride: "XTL_TOOLSET_TARBALL", ) // swift-build assumes we have an Apple-flavored librarian for Apple platforms@@ -406,6 +423,7 @@ struct SDKBuilder { url: url, destination: macrosDir, displayName: "OpenAppleMacros",+ envOverride: "XTL_OAM_TARBALL", ) struct MacrosInfo: Decodable {