From 890ea04b096194ec3598f62fa5ad986be62ccd43 Mon Sep 17 00:00:00 2001 From: ikesyo Date: Wed, 11 Dec 2024 17:46:19 +0900 Subject: [PATCH] Remove ScipioAbsolutePath and use TSCAbsolutePath typealias instead - https://github.com/swiftlang/swift-package-manager/blob/bc689418acad746af6f2e24e6bef640e411d9bd7/Sources/Basics/FileSystem/AbsolutePath.swift#L16-L17 - https://github.com/swiftlang/swift-package-manager/blob/bc689418acad746af6f2e24e6bef640e411d9bd7/Sources/Basics/FileSystem/AbsolutePath.swift#L45-L48 --- Sources/ScipioKit/DescriptionPackage.swift | 6 +-- Sources/ScipioKit/PackageLocator.swift | 17 +++++---- .../PIF/FrameworkComponentsCollector.swift | 38 +++++++++---------- Sources/ScipioKit/Runner.swift | 12 +++--- Sources/ScipioKit/SwiftPM+Compatibility.swift | 10 ++--- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/Sources/ScipioKit/DescriptionPackage.swift b/Sources/ScipioKit/DescriptionPackage.swift index 3bf44ed2..d2b8a04a 100644 --- a/Sources/ScipioKit/DescriptionPackage.swift +++ b/Sources/ScipioKit/DescriptionPackage.swift @@ -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 @@ -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 @@ -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 diff --git a/Sources/ScipioKit/PackageLocator.swift b/Sources/ScipioKit/PackageLocator.swift index 41024d46..e23d6a27 100644 --- a/Sources/ScipioKit/PackageLocator.swift +++ b/Sources/ScipioKit/PackageLocator.swift @@ -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) @@ -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 @@ -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) diff --git a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift index 52a7ccb9..00927b3a 100644 --- a/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift +++ b/Sources/ScipioKit/Producer/PIF/FrameworkComponentsCollector.swift @@ -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? - var bridgingHeaderPath: AbsolutePath? - var modulemapPath: AbsolutePath? - var resourceBundlePath: AbsolutePath? + var binaryPath: TSCAbsolutePath + var infoPlistPath: TSCAbsolutePath + var swiftModulesPath: TSCAbsolutePath? + var includeDir: TSCAbsolutePath? + var publicHeaderPaths: Set? + 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 { @@ -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) @@ -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 @@ -120,7 +120,7 @@ struct FrameworkComponentsCollector { return frameworkModuleMapPath } - private func generatedFrameworkPath() -> AbsolutePath { + private func generatedFrameworkPath() -> TSCAbsolutePath { packageLocator.productsDirectory( buildConfiguration: buildOptions.buildConfiguration, sdk: sdk @@ -128,7 +128,7 @@ struct FrameworkComponentsCollector { .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"), @@ -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" ) @@ -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" ) @@ -167,7 +167,7 @@ struct FrameworkComponentsCollector { } /// Collects public headers of clangTarget - private func collectPublicHeaders() throws -> Set? { + private func collectPublicHeaders() throws -> Set? { guard let clangModule = buildProduct.target.underlying as? ScipioClangModule else { return nil } @@ -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) } } diff --git a/Sources/ScipioKit/Runner.swift b/Sources/ScipioKit/Runner.swift index d6e4340f..b35405da 100644 --- a/Sources/ScipioKit/Runner.swift +++ b/Sources/ScipioKit/Runner.swift @@ -1,6 +1,6 @@ import Foundation import ScipioStorage -import struct TSCBasic.AbsolutePath +import Basics import protocol TSCBasic.FileSystem import var TSCBasic.localFileSystem @@ -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) } } diff --git a/Sources/ScipioKit/SwiftPM+Compatibility.swift b/Sources/ScipioKit/SwiftPM+Compatibility.swift index f933bf12..b8ebb3c4 100644 --- a/Sources/ScipioKit/SwiftPM+Compatibility.swift +++ b/Sources/ScipioKit/SwiftPM+Compatibility.swift @@ -1,6 +1,5 @@ import Foundation import PackageGraph -import TSCBasic import Basics import PackageModel @@ -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) } }