Skip to content

Commit b6a7f10

Browse files
committed
Remove Foundation imports for NSString file path management.
1 parent 06deecd commit b6a7f10

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
13-
import Foundation
1412
import TSCBasic
1513
import TSCUtility
1614

@@ -1338,39 +1336,28 @@ extension Driver {
13381336
diagnosticEngine.emit(.error_bridging_header_module_interface)
13391337
}
13401338

1341-
let objcHeader = try VirtualPath(path: objcHeaderPathArg.asSingle)
1342-
1343-
if objcHeader.extension != FileType.objcHeader.rawValue {
1344-
diagnosticEngine.emit(.error_objc_header_not_header)
1345-
}
1346-
1347-
return objcHeader
1339+
return try VirtualPath(path: objcHeaderPathArg.asSingle)
13481340
}
1349-
1341+
13501342
/// Compute the path of the generated bridging PCH for the Objective-C header.
13511343
static func computeBridgingPrecompiledHeader(_ parsedOptions: inout ParsedOptions, importedObjCHeader: VirtualPath?) throws -> VirtualPath? {
13521344
guard let input = importedObjCHeader,
13531345
parsedOptions.hasFlag(positive: .enableBridgingPch, negative: .disableBridgingPch, default: true) else {
13541346
return nil
13551347
}
1348+
// FIXME: Check OutputFileMap?
1349+
13561350
// FIXME: should have '-.*' at the end of the filename, similar to llvm::sys::fs::createTemporaryFile
13571351
let pchFileName = input.basenameWithoutExt.appendingFileTypeExtension(.pch)
1358-
let output: VirtualPath
13591352
if let outputDirectory = parsedOptions.getLastArgument(.pchOutputDir)?.asSingle {
1360-
let outputPath = (outputDirectory as NSString).appendingPathComponent(pchFileName)
1361-
output = try VirtualPath(path: outputPath)
1353+
return try VirtualPath(path: outputDirectory).appending(component: pchFileName)
13621354
} else {
1363-
output = .temporary(RelativePath(pchFileName))
1355+
return .temporary(RelativePath(pchFileName))
13641356
}
1365-
return output
13661357
}
13671358
}
13681359

13691360
extension Diagnostic.Message {
1370-
static var error_objc_header_not_header: Diagnostic.Message {
1371-
.error("ObjC header needs to be .h file")
1372-
}
1373-
13741361
static var error_framework_bridging_header: Diagnostic.Message {
13751362
.error("using bridging headers with framework targets is unsupported")
13761363
}

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ extension Driver {
155155
// Pass through any subsystem flags.
156156
try commandLine.appendAll(.Xllvm, from: &parsedOptions)
157157
try commandLine.appendAll(.Xcc, from: &parsedOptions)
158-
158+
159159
if let importedObjCHeader = importedObjCHeader {
160160
commandLine.appendFlag(.importObjcHeader)
161161
if requestPrecompiledObjCHeader, let pch = bridgingPrecompiledHeader {
162162
if parsedOptions.contains(.pchOutputDir) {
163163
commandLine.appendPath(importedObjCHeader)
164-
if compilerMode != .singleCompile {
164+
switch compilerMode {
165+
case .standardCompile, .batchCompile, .repl, .immediate:
165166
commandLine.appendFlag(.pchDisableValidation)
167+
case .singleCompile:
168+
// Don't disable validation for single compile
169+
break
166170
}
167171
} else {
168172
commandLine.appendPath(pch)

Sources/SwiftDriver/Jobs/GeneratePCHJob.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Foundation
1413
import TSCBasic
1514
import TSCUtility
1615

@@ -31,17 +30,16 @@ extension Driver {
3130

3231
try commandLine.appendLast(.indexStorePath, from: &parsedOptions)
3332

33+
// TODO: Move this to Driver and check OutputFileMap
3434
// TODO: Should this just be pch output with extension changed?
3535
if parsedOptions.hasArgument(.serializeDiagnostics), let outputDirectory = parsedOptions.getLastArgument(.pchOutputDir)?.asSingle {
3636
commandLine.appendFlag(.serializeDiagnosticsPath)
3737
let path: VirtualPath
3838
if let modulePath = parsedOptions.getLastArgument(.emitModulePath) {
39-
var outputBase = (outputDirectory as NSString).appendingPathComponent(input.file.basenameWithoutExt)
40-
outputBase.append("-")
4139
// TODO: does this hash need to be persistent?
4240
let code = UInt(bitPattern: modulePath.asSingle.hashValue)
43-
outputBase.append(String(code, radix: 36))
44-
path = try VirtualPath(path: outputBase.appendingFileTypeExtension(.diagnostics))
41+
let outputName = input.file.basenameWithoutExt + "-" + String(code, radix: 36)
42+
path = try VirtualPath(path: outputDirectory).appending(component: outputName.appendingFileTypeExtension(.diagnostics))
4543
} else {
4644
// FIXME: should have '-.*' at the end of the filename, similar to llvm::sys::fs::createTemporaryFile
4745
path = .temporary(RelativePath(input.file.basenameWithoutExt.appendingFileTypeExtension(.diagnostics)))

Sources/SwiftDriver/Utilities/VirtualPath.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ public enum VirtualPath: Hashable {
9191
return ""
9292
}
9393
}
94+
95+
/// Returns the virtual path with an additional literal component appended.
96+
///
97+
/// This should not be used with `.standardInput` or `.standardOutput`.
98+
public func appending(component: String) -> VirtualPath {
99+
switch self {
100+
case .absolute(let path):
101+
return .absolute(path.appending(component: component))
102+
case .relative(let path):
103+
// FIXME: TSCBasic should probably have RelativePath.appending(component:)
104+
return .relative(RelativePath(path.pathString + "/" + component))
105+
case .temporary(let path):
106+
return .temporary(RelativePath(path.pathString + "/" + component))
107+
case .standardInput, .standardOutput:
108+
assertionFailure("Can't append path component to standard in/out")
109+
return self
110+
}
111+
}
94112
}
95113

96114
extension VirtualPath: Codable {

0 commit comments

Comments
 (0)