Skip to content

Basics: introduce some native path representation helpers #6454

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

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Sources/Basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add_library(Basics
ImportScanning.swift
JSON+Extensions.swift
JSONDecoder+Extensions.swift
NativePathExtensions.swift
Netrc.swift
Observability.swift
SQLite.swift
Expand Down
26 changes: 26 additions & 0 deletions Sources/Basics/NativePathExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2023 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
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Foundation
import struct TSCBasic.AbsolutePath

extension AbsolutePath {
public func _nativePathString(escaped: Bool) -> String {
return URL(fileURLWithPath: self.pathString).withUnsafeFileSystemRepresentation {
let repr = String(cString: $0!)
if escaped {
return repr.replacingOccurrences(of: "\\", with: "\\\\")
}
return repr
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ public final class SwiftTargetBuildDescription {
content +=
#"""
"dependencies": "\#(
self.tempsPath.appending(component: moduleName + ".d").nativePathString(escaped: true)
self.tempsPath.appending(component: moduleName + ".d")._nativePathString(escaped: true)
)",

"""#
Expand All @@ -690,15 +690,15 @@ public final class SwiftTargetBuildDescription {
content +=
#"""
"object": "\#(
self.tempsPath.appending(component: moduleName + ".o").nativePathString(escaped: true)
self.tempsPath.appending(component: moduleName + ".o")._nativePathString(escaped: true)
)",

"""#

}
content +=
#"""
"swift-dependencies": "\#(masterDepsPath.nativePathString(escaped: true))"
"swift-dependencies": "\#(masterDepsPath._nativePathString(escaped: true))"
},

"""#
Expand All @@ -716,15 +716,15 @@ public final class SwiftTargetBuildDescription {

content +=
#"""
"\#(source.nativePathString(escaped: true))": {
"\#(source._nativePathString(escaped: true))": {

"""#

if !self.buildParameters.useWholeModuleOptimization {
let depsPath = objectDir.appending(component: sourceFileName + ".d")
content +=
#"""
"dependencies": "\#(depsPath.nativePathString(escaped: true))",
"dependencies": "\#(depsPath._nativePathString(escaped: true))",

"""#
// FIXME: Need to record this deps file for processing it later.
Expand All @@ -735,9 +735,9 @@ public final class SwiftTargetBuildDescription {

content +=
#"""
"object": "\#(object.nativePathString(escaped: true))",
"swiftmodule": "\#(partialModulePath.nativePathString(escaped: true))",
"swift-dependencies": "\#(swiftDepsPath.nativePathString(escaped: true))"
"object": "\#(object._nativePathString(escaped: true))",
"swiftmodule": "\#(partialModulePath._nativePathString(escaped: true))",
"swift-dependencies": "\#(swiftDepsPath._nativePathString(escaped: true))"
}\#((idx + 1) < sources.count ? "," : "")

"""#
Expand Down
12 changes: 0 additions & 12 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ extension String {
}
}

extension AbsolutePath {
internal func nativePathString(escaped: Bool) -> String {
return URL(fileURLWithPath: self.pathString).withUnsafeFileSystemRepresentation {
let repr = String(cString: $0!)
if escaped {
return repr.replacingOccurrences(of: "\\", with: "\\\\")
}
return repr
}
}
}

extension BuildParameters {
/// Returns the directory to be used for module cache.
public var moduleCache: AbsolutePath {
Expand Down