Skip to content

Commit

Permalink
Merge pull request #140 from dmhts/task/configurable-runner-environment
Browse files Browse the repository at this point in the history
Task / Configurable runner environment
  • Loading branch information
giginet authored Sep 27, 2024
2 parents 74083a5 + eaa8f2c commit 62c122e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Sources/ScipioKit/BuildOptions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation
import OrderedCollections
import Basics

struct BuildOptions: Hashable, Codable, Sendable {

init(
buildConfiguration: BuildConfiguration,
isDebugSymbolsEmbedded: Bool,
Expand Down
3 changes: 3 additions & 0 deletions Sources/ScipioKit/Producer/FrameworkProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct FrameworkProducer {
private let overwrite: Bool
private let outputDir: URL
private let fileSystem: any FileSystem
private let toolchainEnvironment: [String: String]?

private var cacheStorage: (any CacheStorage)? {
switch cacheMode {
Expand Down Expand Up @@ -51,6 +52,7 @@ struct FrameworkProducer {
cacheMode: Runner.Options.CacheMode,
overwrite: Bool,
outputDir: URL,
toolchainEnvironment: [String: String]? = nil,
fileSystem: any FileSystem = localFileSystem
) {
self.descriptionPackage = descriptionPackage
Expand All @@ -59,6 +61,7 @@ struct FrameworkProducer {
self.cacheMode = cacheMode
self.overwrite = overwrite
self.outputDir = outputDir
self.toolchainEnvironment = toolchainEnvironment
self.fileSystem = fileSystem
}

Expand Down
7 changes: 5 additions & 2 deletions Sources/ScipioKit/Producer/PIF/PIFCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,38 @@ struct PIFCompiler: Compiler {
private let fileSystem: any FileSystem
private let executor: any Executor
private let buildOptionsMatrix: [String: BuildOptions]
private let toolchainEnvironment: [String: String]?

private let buildParametersGenerator: BuildParametersGenerator

init(
descriptionPackage: DescriptionPackage,
buildOptions: BuildOptions,
buildOptionsMatrix: [String: BuildOptions],
toolchainEnvironment: [String: String]? = nil,
fileSystem: any FileSystem = TSCBasic.localFileSystem,
executor: any Executor = ProcessExecutor()
) {
self.descriptionPackage = descriptionPackage
self.buildOptions = buildOptions
self.buildOptionsMatrix = buildOptionsMatrix
self.toolchainEnvironment = toolchainEnvironment
self.fileSystem = fileSystem
self.executor = executor
self.buildParametersGenerator = .init(buildOptions: buildOptions, fileSystem: fileSystem)
}

private func fetchDefaultToolchainBinPath() async throws -> AbsolutePath {
let result = try await executor.execute("/usr/bin/xcrun", "xcode-select", "-p")
let rawString = try result.unwrapOutput()
let rawString = try result.unwrapOutput().trimmingCharacters(in: .whitespacesAndNewlines)
let developerDirPath = try AbsolutePath(validating: rawString)
let toolchainPath = try RelativePath(validating: "./Toolchains/XcodeDefault.xctoolchain/usr/bin")
return developerDirPath.appending(toolchainPath)
}

private func makeToolchain(for sdk: SDK) async throws -> UserToolchain {
let toolchainDirPath = try await fetchDefaultToolchainBinPath()
let toolchainGenerator = ToolchainGenerator(toolchainDirPath: toolchainDirPath)
let toolchainGenerator = ToolchainGenerator(toolchainDirPath: toolchainDirPath, environment: toolchainEnvironment)
return try await toolchainGenerator.makeToolChain(sdk: sdk)
}

Expand Down
16 changes: 14 additions & 2 deletions Sources/ScipioKit/Producer/PIF/ToolchainGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Foundation
import TSCUtility
#if compiler(>=6.0)
@_spi(SwiftPMInternal) import PackageModel
@_spi(SwiftPMInternal) import struct Basics.Environment
#else
import PackageModel
#endif
Expand All @@ -10,16 +11,27 @@ import struct Basics.Triple

struct ToolchainGenerator {
private let toolchainDirPath: AbsolutePath
private let environment: [String: String]?
private let executor: any Executor

init(toolchainDirPath: AbsolutePath, executor: any Executor = ProcessExecutor()) {
init(
toolchainDirPath: AbsolutePath,
environment: [String: String]? = nil,
executor: any Executor = ProcessExecutor()
) {
self.toolchainDirPath = toolchainDirPath
self.environment = environment
self.executor = executor
}

func makeToolChain(sdk: SDK) async throws -> UserToolchain {
let destination: SwiftSDK = try await makeDestination(sdk: sdk)
#if swift(>=5.10)
#if compiler(>=6.0)
return try UserToolchain(
swiftSDK: destination,
environment: environment.map(Environment.init) ?? .current
)
#elseif swift(>=5.10)
return try UserToolchain(swiftSDK: destination)
#else
return try UserToolchain(destination: destination)
Expand Down
5 changes: 4 additions & 1 deletion Sources/ScipioKit/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,16 @@ extension Runner {
public var cacheMode: CacheMode
public var overwrite: Bool
public var verbose: Bool
public var toolchainEnvironment: [String: String]?

public init(
baseBuildOptions: BuildOptions = .init(),
buildOptionsMatrix: [String: TargetBuildOptions] = [:],
shouldOnlyUseVersionsFromResolvedFile: Bool = false,
cacheMode: CacheMode = .project,
overwrite: Bool = false,
verbose: Bool = false
verbose: Bool = false,
toolchainEnvironment: [String: String]? = nil
) {
self.buildOptionsContainer = BuildOptionsContainer(
baseBuildOptions: baseBuildOptions,
Expand All @@ -251,6 +253,7 @@ extension Runner {
self.cacheMode = cacheMode
self.overwrite = overwrite
self.verbose = verbose
self.toolchainEnvironment = toolchainEnvironment
}
}
}
Expand Down

0 comments on commit 62c122e

Please sign in to comment.