Skip to content

Commit

Permalink
Use TSCRelativePath typealias included in Basics and reduce TSCBasic …
Browse files Browse the repository at this point in the history
…imports
  • Loading branch information
ikesyo committed Dec 11, 2024
1 parent 48d7e2d commit 828375e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
3 changes: 1 addition & 2 deletions Sources/ScipioKit/PackageLocator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Basics
import TSCBasic
import PackageModel

/// Holds the packageDirectory Scipio works on, and defines some path-related functionalities.
Expand All @@ -21,7 +20,7 @@ extension PackageLocator {
}

func generatedModuleMapPath(of target: ScipioResolvedModule, sdk: SDK) throws -> TSCAbsolutePath {
let relativePath = try TSCBasic.RelativePath(validating: "ModuleMapsForFramework/\(sdk.settingValue)")
let relativePath = try TSCRelativePath(validating: "ModuleMapsForFramework/\(sdk.settingValue)")
return workspaceDirectory
.appending(relativePath)
.appending(component: target.modulemapName)
Expand Down
13 changes: 7 additions & 6 deletions Sources/ScipioKit/Producer/PIF/PIFCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Foundation
import PackageModel
import SPMBuildCore
import PackageGraph
import TSCBasic
import Basics
import var TSCBasic.localFileSystem

struct PIFCompiler: Compiler {
let descriptionPackage: DescriptionPackage
Expand Down Expand Up @@ -31,11 +32,11 @@ struct PIFCompiler: Compiler {
self.buildParametersGenerator = .init(buildOptions: buildOptions, fileSystem: fileSystem)
}

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

Expand Down Expand Up @@ -93,13 +94,13 @@ struct PIFCompiler: Compiler {

// If there is existing framework, remove it
let frameworkName = target.xcFrameworkName
let outputXCFrameworkPath = try AbsolutePath(validating: outputDirectory.path).appending(component: frameworkName)
let outputXCFrameworkPath = try TSCAbsolutePath(validating: outputDirectory.path).appending(component: frameworkName)
if fileSystem.exists(outputXCFrameworkPath) && overwrite {
logger.info("💥 Delete \(frameworkName)", metadata: .color(.red))
try fileSystem.removeFileTree(outputXCFrameworkPath)
}

let debugSymbolPaths: [SDK: [AbsolutePath]]?
let debugSymbolPaths: [SDK: [TSCAbsolutePath]]?
if buildOptions.isDebugSymbolsEmbedded {
debugSymbolPaths = try await extractDebugSymbolPaths(target: target,
buildConfiguration: buildOptions.buildConfiguration,
Expand Down
31 changes: 20 additions & 11 deletions Sources/ScipioKit/Producer/PIF/XCBuildClient.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import TSCBasic
import Basics
import var TSCBasic.localFileSystem
import PackageGraph
import PackageModel

Expand All @@ -16,7 +17,7 @@ struct XCBuildClient {
buildOptions: BuildOptions,
configuration: BuildConfiguration,
packageLocator: some PackageLocator,
fileSystem: any FileSystem = localFileSystem,
fileSystem: any FileSystem = TSCBasic.localFileSystem,
executor: some Executor = ProcessExecutor(decoder: StandardOutputDecoder())
) {
self.buildProduct = buildProduct
Expand All @@ -27,19 +28,19 @@ struct XCBuildClient {
self.executor = executor
}

private func fetchXCBuildPath() async throws -> AbsolutePath {
private func fetchXCBuildPath() async throws -> TSCAbsolutePath {
let developerDirPath = try await fetchDeveloperDirPath()
let relativePath = try RelativePath(validating: "../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild")
let relativePath = try TSCRelativePath(validating: "../SharedFrameworks/XCBuild.framework/Versions/A/Support/xcbuild")
return developerDirPath.appending(relativePath)
}

private func fetchDeveloperDirPath() async throws -> AbsolutePath {
private func fetchDeveloperDirPath() async throws -> TSCAbsolutePath {
let result = try await executor.execute(
"/usr/bin/xcrun",
"xcode-select",
"-p"
)
return try AbsolutePath(validating: try result.unwrapOutput())
return try TSCAbsolutePath(validating: try result.unwrapOutput())
}

private var productTargetName: String {
Expand All @@ -49,8 +50,8 @@ struct XCBuildClient {

func buildFramework(
sdk: SDK,
pifPath: AbsolutePath,
buildParametersPath: AbsolutePath
pifPath: TSCAbsolutePath,
buildParametersPath: TSCAbsolutePath
) async throws {
let xcbuildPath = try await fetchXCBuildPath()

Expand Down Expand Up @@ -98,7 +99,7 @@ struct XCBuildClient {
try assembler.assemble()
}

private func assembledFrameworkPath(target: ScipioResolvedModule, of sdk: SDK) throws -> AbsolutePath {
private func assembledFrameworkPath(target: ScipioResolvedModule, of sdk: SDK) throws -> TSCAbsolutePath {
let assembledFrameworkDir = packageLocator.assembledFrameworksDirectory(
buildConfiguration: buildOptions.buildConfiguration,
sdk: sdk
Expand All @@ -107,7 +108,11 @@ struct XCBuildClient {
.appending(component: "\(buildProduct.target.c99name).framework")
}

func createXCFramework(sdks: Set<SDK>, debugSymbols: [SDK: [AbsolutePath]]?, outputPath: AbsolutePath) async throws {
func createXCFramework(
sdks: Set<SDK>,
debugSymbols: [SDK: [TSCAbsolutePath]]?,
outputPath: TSCAbsolutePath
) async throws {
let xcbuildPath = try await fetchXCBuildPath()

let additionalArguments = try buildCreateXCFrameworkArguments(
Expand All @@ -124,7 +129,11 @@ struct XCBuildClient {
try await executor.execute(arguments)
}

private func buildCreateXCFrameworkArguments(sdks: Set<SDK>, debugSymbols: [SDK: [AbsolutePath]]?, outputPath: AbsolutePath) throws -> [String] {
private func buildCreateXCFrameworkArguments(
sdks: Set<SDK>,
debugSymbols: [SDK: [TSCAbsolutePath]]?,
outputPath: TSCAbsolutePath
) throws -> [String] {
let frameworksWithDebugSymbolArguments: [String] = try sdks.reduce([]) { arguments, sdk in
let path = try assembledFrameworkPath(target: buildProduct.target, of: sdk)
var result = arguments + ["-framework", path.pathString]
Expand Down

0 comments on commit 828375e

Please sign in to comment.