Skip to content

Commit

Permalink
Merge pull request #166 from ikesyo/remove-scipioabsolutepath-typealias
Browse files Browse the repository at this point in the history
Remove ScipioAbsolutePath and use TSCAbsolutePath typealias instead
  • Loading branch information
ikesyo authored Dec 11, 2024
2 parents fe972a7 + 890ea04 commit 48d7e2d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
6 changes: 3 additions & 3 deletions Sources/ScipioKit/DescriptionPackage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Basics

struct DescriptionPackage: PackageLocator {
let mode: Runner.Mode
let packageDirectory: ScipioAbsolutePath
let packageDirectory: TSCAbsolutePath
private let toolchain: UserToolchain
let workspace: Workspace
let graph: ModulesGraph
Expand Down Expand Up @@ -41,7 +41,7 @@ struct DescriptionPackage: PackageLocator {

// MARK: Initializer

private static func makeWorkspace(toolchain: UserToolchain, packagePath: ScipioAbsolutePath) throws -> Workspace {
private static func makeWorkspace(toolchain: UserToolchain, packagePath: TSCAbsolutePath) throws -> Workspace {
var workspaceConfiguration: WorkspaceConfiguration = .default
// override default configuration to treat XIB files
workspaceConfiguration.additionalFileRules = FileRuleDescription.xcbuildFileTypes
Expand All @@ -67,7 +67,7 @@ struct DescriptionPackage: PackageLocator {
/// If it is `true`, Package.resolved never be updated.
/// Instead, the resolving will fail if the Package.resolved is mis-matched with the workspace.
init(
packageDirectory: ScipioAbsolutePath,
packageDirectory: TSCAbsolutePath,
mode: Runner.Mode,
onlyUseVersionsFromResolvedFile: Bool,
toolchainEnvironment: ToolchainEnvironment? = nil
Expand Down
17 changes: 9 additions & 8 deletions Sources/ScipioKit/PackageLocator.swift
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import Basics
import TSCBasic
import PackageModel

/// Holds the packageDirectory Scipio works on, and defines some path-related functionalities.
protocol PackageLocator {
var packageDirectory: ScipioAbsolutePath { get }
var packageDirectory: TSCAbsolutePath { get }
}

extension PackageLocator {
var buildDirectory: ScipioAbsolutePath {
var buildDirectory: TSCAbsolutePath {
packageDirectory.appending(component: ".build")
}

var workspaceDirectory: ScipioAbsolutePath {
var workspaceDirectory: TSCAbsolutePath {
buildDirectory.appending(component: "scipio")
}

var derivedDataPath: ScipioAbsolutePath {
var derivedDataPath: TSCAbsolutePath {
workspaceDirectory.appending(component: "DerivedData")
}

func generatedModuleMapPath(of target: ScipioResolvedModule, sdk: SDK) throws -> ScipioAbsolutePath {
func generatedModuleMapPath(of target: ScipioResolvedModule, sdk: SDK) throws -> TSCAbsolutePath {
let relativePath = try TSCBasic.RelativePath(validating: "ModuleMapsForFramework/\(sdk.settingValue)")
return workspaceDirectory
.appending(relativePath)
Expand All @@ -28,7 +29,7 @@ extension PackageLocator {

/// Returns an Products directory path
/// It should be the default setting of `TARGET_BUILD_DIR`
func productsDirectory(buildConfiguration: BuildConfiguration, sdk: SDK) -> ScipioAbsolutePath {
func productsDirectory(buildConfiguration: BuildConfiguration, sdk: SDK) -> TSCAbsolutePath {
let intermediateDirectoryName = productDirectoryName(
buildConfiguration: buildConfiguration,
sdk: sdk
Expand All @@ -37,12 +38,12 @@ extension PackageLocator {
}

/// Returns a directory path which contains assembled frameworks
var assembledFrameworksRootDirectory: ScipioAbsolutePath {
var assembledFrameworksRootDirectory: TSCAbsolutePath {
workspaceDirectory.appending(component: "AssembledFrameworks")
}

/// Returns a directory path of the assembled frameworks path for the specific Configuration/Platform
func assembledFrameworksDirectory(buildConfiguration: BuildConfiguration, sdk: SDK) -> ScipioAbsolutePath {
func assembledFrameworksDirectory(buildConfiguration: BuildConfiguration, sdk: SDK) -> TSCAbsolutePath {
let intermediateDirName = productDirectoryName(buildConfiguration: buildConfiguration, sdk: sdk)
return assembledFrameworksRootDirectory
.appending(component: intermediateDirName)
Expand Down
38 changes: 19 additions & 19 deletions Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import Foundation
import TSCBasic
import Basics
import PackageModel

/// FileLists to assemble a framework bundle
struct FrameworkComponents {
var frameworkName: String
var binaryPath: AbsolutePath
var infoPlistPath: AbsolutePath
var swiftModulesPath: AbsolutePath?
var includeDir: AbsolutePath?
var publicHeaderPaths: Set<AbsolutePath>?
var bridgingHeaderPath: AbsolutePath?
var modulemapPath: AbsolutePath?
var resourceBundlePath: AbsolutePath?
var binaryPath: TSCAbsolutePath
var infoPlistPath: TSCAbsolutePath
var swiftModulesPath: TSCAbsolutePath?
var includeDir: TSCAbsolutePath?
var publicHeaderPaths: Set<TSCAbsolutePath>?
var bridgingHeaderPath: TSCAbsolutePath?
var modulemapPath: TSCAbsolutePath?
var resourceBundlePath: TSCAbsolutePath?
}

/// A collector to collect framework components from a DerivedData dir
struct FrameworkComponentsCollector {
enum Error: LocalizedError {
case infoPlistNotFound(frameworkBundlePath: AbsolutePath)
case infoPlistNotFound(frameworkBundlePath: TSCAbsolutePath)

var errorDescription: String? {
switch self {
Expand Down Expand Up @@ -49,7 +49,7 @@ struct FrameworkComponentsCollector {
}

func collectComponents(sdk: SDK) throws -> FrameworkComponents {
let frameworkModuleMapPath: AbsolutePath?
let frameworkModuleMapPath: TSCAbsolutePath?
if let customFrameworkModuleMapContents = buildOptions.customFrameworkModuleMapContents {
logger.info("📝 Using custom modulemap for \(buildProduct.target.name)(\(sdk.displayName))")
frameworkModuleMapPath = try copyModuleMapContentsToBuildArtifacts(customFrameworkModuleMapContents)
Expand Down Expand Up @@ -96,14 +96,14 @@ struct FrameworkComponentsCollector {
}

/// Copy content data to the build artifacts
private func copyModuleMapContentsToBuildArtifacts(_ data: Data) throws -> ScipioAbsolutePath {
private func copyModuleMapContentsToBuildArtifacts(_ data: Data) throws -> TSCAbsolutePath {
let generatedModuleMapPath = try packageLocator.generatedModuleMapPath(of: buildProduct.target, sdk: sdk)

try fileSystem.writeFileContents(generatedModuleMapPath.spmAbsolutePath, data: data)
return generatedModuleMapPath
}

private func generateFrameworkModuleMap() throws -> AbsolutePath? {
private func generateFrameworkModuleMap() throws -> TSCAbsolutePath? {
let modulemapGenerator = FrameworkModuleMapGenerator(
packageLocator: packageLocator,
fileSystem: fileSystem
Expand All @@ -120,15 +120,15 @@ struct FrameworkComponentsCollector {
return frameworkModuleMapPath
}

private func generatedFrameworkPath() -> AbsolutePath {
private func generatedFrameworkPath() -> TSCAbsolutePath {
packageLocator.productsDirectory(
buildConfiguration: buildOptions.buildConfiguration,
sdk: sdk
)
.appending(component: "\(buildProduct.target.c99name).framework")
}

private func collectInfoPlist(in frameworkBundlePath: AbsolutePath) throws -> AbsolutePath {
private func collectInfoPlist(in frameworkBundlePath: TSCAbsolutePath) throws -> TSCAbsolutePath {
let infoPlistLocationCandidates = [
// In a regular framework bundle, Info.plist should be on its root
frameworkBundlePath.appending(component: "Info.plist"),
Expand All @@ -142,7 +142,7 @@ struct FrameworkComponentsCollector {
}

/// Collects *.swiftmodules* in a generated framework bundle
private func collectSwiftModules(of targetName: String, in frameworkPath: AbsolutePath) throws -> AbsolutePath? {
private func collectSwiftModules(of targetName: String, in frameworkPath: TSCAbsolutePath) throws -> TSCAbsolutePath? {
let swiftModulesPath = frameworkPath.appending(
components: "Modules", "\(targetName).swiftmodule"
)
Expand All @@ -154,7 +154,7 @@ struct FrameworkComponentsCollector {
}

/// Collects a bridging header in a generated framework bundle
private func collectBridgingHeader(of targetName: String, in frameworkPath: AbsolutePath) throws -> AbsolutePath? {
private func collectBridgingHeader(of targetName: String, in frameworkPath: TSCAbsolutePath) throws -> TSCAbsolutePath? {
let generatedBridgingHeader = frameworkPath.appending(
components: "Headers", "\(targetName)-Swift.h"
)
Expand All @@ -167,7 +167,7 @@ struct FrameworkComponentsCollector {
}

/// Collects public headers of clangTarget
private func collectPublicHeaders() throws -> Set<AbsolutePath>? {
private func collectPublicHeaders() throws -> Set<TSCAbsolutePath>? {
guard let clangModule = buildProduct.target.underlying as? ScipioClangModule else {
return nil
}
Expand All @@ -194,7 +194,7 @@ struct FrameworkComponentsCollector {
return Set(notSymlinks + notDuplicatedSymlinks)
}

private func collectResourceBundle(of targetName: String, in frameworkPath: AbsolutePath) throws -> AbsolutePath? {
private func collectResourceBundle(of targetName: String, in frameworkPath: TSCAbsolutePath) throws -> TSCAbsolutePath? {
let bundleFileName = try fileSystem.getDirectoryContents(frameworkPath).first { $0.hasSuffix(".bundle") }
return bundleFileName.flatMap { frameworkPath.appending(component: $0) }
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/ScipioKit/Runner.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation
import ScipioStorage
import struct TSCBasic.AbsolutePath
import Basics
import protocol TSCBasic.FileSystem
import var TSCBasic.localFileSystem

Expand Down Expand Up @@ -40,14 +40,14 @@ public struct Runner {
self.fileSystem = fileSystem
}

private func resolveURL(_ fileURL: URL) throws -> ScipioAbsolutePath {
private func resolveURL(_ fileURL: URL) throws -> TSCAbsolutePath {
if fileURL.path.hasPrefix("/") {
return try AbsolutePath(validating: fileURL.path)
return try TSCAbsolutePath(validating: fileURL.path)
} else if let currentDirectory = fileSystem.currentWorkingDirectory {
let scipioCurrentDirectory = try ScipioAbsolutePath(validating: currentDirectory.pathString)
return try ScipioAbsolutePath(scipioCurrentDirectory, validating: fileURL.path)
let scipioCurrentDirectory = try TSCAbsolutePath(validating: currentDirectory.pathString)
return try TSCAbsolutePath(scipioCurrentDirectory, validating: fileURL.path)
} else {
return try! AbsolutePath(validating: fileURL.path)
return try! TSCAbsolutePath(validating: fileURL.path)
}
}

Expand Down
10 changes: 4 additions & 6 deletions Sources/ScipioKit/SwiftPM+Compatibility.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Foundation
import PackageGraph
import TSCBasic
import Basics
import PackageModel

Expand All @@ -10,18 +9,17 @@ import PackageModel
// These has almost identical feature and interface. Unfortunately, Scipio still uses TSC versions of them
// so It's better to remove TSC dependencies from Scipio.
// At this moment, we just provides utils to bridge them at this time as below.
typealias ScipioAbsolutePath = TSCBasic.AbsolutePath
typealias SwiftPMAbsolutePath = Basics.AbsolutePath

extension ScipioAbsolutePath {
extension TSCAbsolutePath {
var spmAbsolutePath: SwiftPMAbsolutePath {
try! SwiftPMAbsolutePath(validating: pathString)
SwiftPMAbsolutePath(self)
}
}

extension SwiftPMAbsolutePath {
var scipioAbsolutePath: ScipioAbsolutePath {
try! ScipioAbsolutePath(validating: pathString)
var scipioAbsolutePath: TSCAbsolutePath {
try! TSCAbsolutePath(validating: pathString)
}
}

Expand Down

0 comments on commit 48d7e2d

Please sign in to comment.