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

[DNM] Refactor Path APIs with SwiftSystem #219

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD YES)

option(BUILD_SHARED_LIBS "Build shared libraries by default" YES)

if(FIND_PM_DEPS)
find_package(SwiftSystem CONFIG REQUIRED)
endif()

find_package(dispatch QUIET)
find_package(Foundation QUIET)
find_package(Threads QUIET)
Expand Down
35 changes: 11 additions & 24 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ let package = Package(
name: "TSCTestSupport",
targets: ["TSCTestSupport"]),
],
dependencies: [],
targets: [

// MARK: Tools support core targets
Expand All @@ -67,7 +66,8 @@ let package = Package(
"TSCclibc",
.product(name: "SystemPackage", package: "swift-system"),
],
exclude: CMakeFiles + ["README.md"]),
exclude: CMakeFiles + ["README.md"],
cxxSettings: [.define("_CRT_SECURE_NO_WARNINGS")]),
.target(
/** Abstractions for common operations, should migrate to TSCBasic */
name: "TSCUtility",
Expand Down Expand Up @@ -102,27 +102,14 @@ let package = Package(
)

/// When not using local dependencies, the branch to use for llbuild and TSC repositories.
let relatedDependenciesBranch = "main"

if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [
.package(url: "https://github.com/apple/swift-system.git", .upToNextMinor(from: "1.1.1")),
]
} else {
package.dependencies += [
.package(path: "../swift-system"),
]
}

// FIXME: conditionalise these flags since SwiftPM 5.3 and earlier will crash
// for platforms they don't know about.
#if os(Windows)
if let TSCBasic = package.targets.first(where: { $0.name == "TSCBasic" }) {
TSCBasic.cxxSettings = [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
let relatedDependenciesBranch = "main"

if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [
.package(url: "https://github.com/apple/swift-system.git", .upToNextMinor(from: "1.1.1")),
]
TSCBasic.linkerSettings = [
.linkedLibrary("Pathcch", .when(platforms: [.windows])),
} else {
package.dependencies += [
.package(path: "../swift-system"),
]
}
#endif
}
4 changes: 1 addition & 3 deletions Sources/TSCBasic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@ target_link_libraries(TSCBasic PUBLIC
SwiftSystem::SystemPackage
TSCLibc)
target_link_libraries(TSCBasic PRIVATE
TSCclibc)
TSCclibc)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
if(Foundation_FOUND)
target_link_libraries(TSCBasic PUBLIC
Foundation)
endif()
endif()
target_link_libraries(TSCBasic PRIVATE
$<$<PLATFORM_ID:Windows>:Pathcch>)
# NOTE(compnerd) workaround for CMake not setting up include flags yet
set_target_properties(TSCBasic PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
Expand Down
10 changes: 5 additions & 5 deletions Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -409,7 +409,7 @@ private class LocalFileSystem: FileSystem {
}

func createSymbolicLink(_ path: AbsolutePath, pointingAt destination: AbsolutePath, relative: Bool) throws {
let destString = relative ? destination.relative(to: path.parentDirectory).pathString : destination.pathString
let destString = relative ? try destination.relative(to: path.parentDirectory).pathString : destination.pathString
try FileManager.default.createSymbolicLink(atPath: path.pathString, withDestinationPath: destString)
}

Expand Down Expand Up @@ -846,7 +846,7 @@ public class InMemoryFileSystem: FileSystem {
throw FileSystemError(.alreadyExistsAtDestination, path)
}

let destination = relative ? destination.relative(to: path.parentDirectory).pathString : destination.pathString
let destination = relative ? try destination.relative(to: path.parentDirectory).pathString : destination.pathString

contents.entries[path.basename] = Node(.symlink(destination))
}
Expand Down Expand Up @@ -1024,11 +1024,11 @@ public class RerootedFileSystemView: FileSystem {

/// Adjust the input path for the underlying file system.
private func formUnderlyingPath(_ path: AbsolutePath) -> AbsolutePath {
if path == AbsolutePath.root {
if path.isRoot {
return root
} else {
// FIXME: Optimize?
return root.appending(RelativePath(String(path.pathString.dropFirst(1))))
return root.appending(RelativePath(path.filepath.removingRoot()))
}
}

Expand Down
Loading