Skip to content
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

Task / Configurable runner environment #140

Merged
merged 23 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b8afb4b
Make runner environment configurable
dmhts Aug 27, 2024
52d04d8
Avoid environment affecting final hash
dmhts Sep 5, 2024
413a5c9
Exclude environment from CodingKeys
dmhts Sep 6, 2024
b6f27fc
Revert "Exclude environment from CodingKeys"
dmhts Sep 6, 2024
5c0f81e
Reapply "Exclude environment from CodingKeys"
dmhts Sep 6, 2024
7eab940
Add test ensuring environment not encoded in cache key
dmhts Sep 6, 2024
3fc23b1
Adapt default build options
dmhts Sep 8, 2024
913dafd
Add proper conformance of Environment to Hashable
dmhts Sep 9, 2024
12dfd7c
Xcode Beta 6 changes
dmhts Sep 9, 2024
28c0db1
Make linter happy
dmhts Sep 9, 2024
bd0a035
Support Swift <= 6.0
dmhts Sep 10, 2024
9d60543
Revert "Support Swift <= 6.0"
dmhts Sep 23, 2024
9b50517
Merge remote-tracking branch 'upstream/main' into task/configurable-r…
dmhts Sep 23, 2024
c3ac051
Use `[String: String]` instead of `Environment`
dmhts Sep 23, 2024
b3b0219
Remove extra new line
dmhts Sep 23, 2024
b5d5b57
Add compiler check for environment extension
dmhts Sep 23, 2024
24289cf
Remove extra import
dmhts Sep 23, 2024
834467e
Remove one more extra import
dmhts Sep 23, 2024
d171e0c
environment -> toolchainEnvironment
dmhts Sep 25, 2024
ef8fb17
Move environment from build to runner options
dmhts Sep 25, 2024
b8adc6c
Environment doesn't need to be hashable anymore
dmhts Sep 25, 2024
3ca0227
Remove environment leftovers from TargetBuildOptions
dmhts Sep 25, 2024
eaa8f2c
Keep dependencies at end of parameter list
dmhts Sep 25, 2024
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
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)
dmhts marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading