Skip to content

[DNM] Refactor Path APIs with SwiftSystem #219

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

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

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
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ let package = Package(
name: "TSCTestSupport",
targets: ["TSCTestSupport"]),
],
dependencies: [],
dependencies: [
.package(url: "https://github.com/apple/swift-system.git", .upToNextMinor(from: "0.0.1"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 0.0.1 or 0.0.2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be 0.0.3 given that the first two releases actually not compiles (0.0.2 only compiles with release config).

upToNextMinor() indicates the latest 0.0.x, once 0.0.3 is released it should resolve.

],
targets: [

// MARK: Tools support core targets
Expand All @@ -44,7 +46,8 @@ let package = Package(
.target(
/** TSCBasic support library */
name: "TSCBasic",
dependencies: ["TSCLibc", "TSCclibc"]),
dependencies: ["TSCLibc", "TSCclibc",
.product(name: "SystemPackage", package: "swift-system")]),
.target(
/** Abstractions for common operations, should migrate to TSCBasic */
name: "TSCUtility",
Expand Down Expand Up @@ -82,8 +85,5 @@ let package = Package(
TSCBasic.cxxSettings = [
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [.windows])),
]
TSCBasic.linkerSettings = [
.linkedLibrary("Pathcch", .when(platforms: [.windows])),
]
}
#endif
7 changes: 3 additions & 4 deletions Sources/TSCBasic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ target_compile_options(TSCBasic PUBLIC
# Ignore secure function warnings on Windows.
"$<$<PLATFORM_ID:Windows>:SHELL:-Xcc -D_CRT_SECURE_NO_WARNINGS>")
target_link_libraries(TSCBasic PUBLIC
TSCLibc)
TSCLibc
SwiftSystem)
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
14 changes: 7 additions & 7 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 @@ -377,7 +377,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 @@ -706,7 +706,7 @@ public class InMemoryFileSystem: FileSystem {

/// Virtualized current working directory.
public var currentWorkingDirectory: AbsolutePath? {
return AbsolutePath("/")
return AbsolutePath.withPOSIX(path: "/")
}

public func changeCurrentWorkingDirectory(to path: AbsolutePath) throws {
Expand All @@ -715,7 +715,7 @@ public class InMemoryFileSystem: FileSystem {

public var homeDirectory: AbsolutePath {
// FIXME: Maybe we should allow setting this when creating the fs.
return AbsolutePath("/home/user")
return AbsolutePath.withPOSIX(path: "/home/user")
}

public var cachesDirectory: AbsolutePath? {
Expand Down Expand Up @@ -803,7 +803,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 @@ -981,11 +981,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