@@ -45,12 +45,15 @@ private var testInputsPath: AbsolutePath {
45
45
}
46
46
}
47
47
48
- func toPath( _ path: String , base: AbsolutePath = localFileSystem. currentWorkingDirectory!) throws -> VirtualPath {
49
- return try VirtualPath ( path: path) . resolvedRelativePath ( base: base)
48
+ func toPath( _ path: String , isRelative: Bool = true ) throws -> VirtualPath {
49
+ if isRelative {
50
+ return VirtualPath . relative ( try . init( validating: path) )
51
+ }
52
+ return try VirtualPath ( path: path) . resolvedRelativePath ( base: localFileSystem. currentWorkingDirectory!)
50
53
}
51
54
52
- func toPathOption( _ path: String , base : AbsolutePath = localFileSystem . currentWorkingDirectory! ) throws -> Job . ArgTemplate {
53
- return . path( try toPath ( path, base : base ) )
55
+ func toPathOption( _ path: String , isRelative : Bool = true ) throws -> Job . ArgTemplate {
56
+ return . path( try toPath ( path, isRelative : isRelative ) )
54
57
}
55
58
56
59
final class SwiftDriverTests : XCTestCase {
@@ -351,7 +354,7 @@ final class SwiftDriverTests: XCTestCase {
351
354
] )
352
355
XCTAssertEqual ( driver. recordedInputModificationDates, [
353
356
. init( file: VirtualPath . absolute ( main) . intern ( ) , type: . swift) : mainMDate,
354
- . init( file: VirtualPath . absolute ( util ) . intern ( ) , type: . swift) : utilMDate,
357
+ . init( file: VirtualPath . relative ( utilRelative ) . intern ( ) , type: . swift) : utilMDate,
355
358
] )
356
359
}
357
360
}
@@ -1295,12 +1298,11 @@ final class SwiftDriverTests: XCTestCase {
1295
1298
let plannedJobs = try driver. planBuild ( ) . removingAutolinkExtractJobs ( )
1296
1299
XCTAssertEqual ( plannedJobs. count, 3 )
1297
1300
XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
1298
- XCTAssertTrue ( plannedJobs [ 0 ] . primaryInputs. map { $0. file. description } . elementsEqual ( [ rebase ( " foo.swift " ) ,
1299
- rebase ( " bar.swift " ) ] ) )
1301
+ XCTAssertTrue ( plannedJobs [ 0 ] . primaryInputs. map { $0. file. description } . elementsEqual ( [ " foo.swift " , " bar.swift " ] ) )
1300
1302
XCTAssertTrue ( plannedJobs [ 0 ] . commandLine. contains ( " -emit-const-values-path " ) )
1301
1303
XCTAssertEqual ( plannedJobs [ 0 ] . outputs. filter ( { $0. type == . swiftConstValues } ) . count, 2 )
1302
1304
XCTAssertEqual ( plannedJobs [ 1 ] . kind, . compile)
1303
- XCTAssertTrue ( plannedJobs [ 1 ] . primaryInputs. map { $0. file. description } . elementsEqual ( [ rebase ( " baz.swift " ) ] ) )
1305
+ XCTAssertTrue ( plannedJobs [ 1 ] . primaryInputs. map { $0. file. description } . elementsEqual ( [ " baz.swift " ] ) )
1304
1306
XCTAssertTrue ( plannedJobs [ 1 ] . commandLine. contains ( " -emit-const-values-path " ) )
1305
1307
XCTAssertEqual ( plannedJobs [ 1 ] . outputs. filter ( { $0. type == . swiftConstValues } ) . count, 1 )
1306
1308
XCTAssertEqual ( plannedJobs [ 2 ] . kind, . link)
@@ -1331,13 +1333,12 @@ final class SwiftDriverTests: XCTestCase {
1331
1333
let plannedJobs = try driver. planBuild ( ) . removingAutolinkExtractJobs ( )
1332
1334
XCTAssertEqual ( plannedJobs. count, 3 )
1333
1335
XCTAssertEqual ( plannedJobs [ 0 ] . kind, . compile)
1334
- XCTAssertTrue ( plannedJobs [ 0 ] . primaryInputs. map { $0. file. description } . elementsEqual ( [ rebase ( " foo.swift " ) ,
1335
- rebase ( " bar.swift " ) ] ) )
1336
+ XCTAssertTrue ( plannedJobs [ 0 ] . primaryInputs. map { $0. file. description } . elementsEqual ( [ " foo.swift " , " bar.swift " ] ) )
1336
1337
XCTAssertTrue ( plannedJobs [ 0 ] . commandLine. contains ( subsequence: [ . flag( " -emit-const-values-path " ) , . path( . absolute( try . init( validating: " /tmp/foo.build/foo.swiftconstvalues " ) ) ) ] ) )
1337
1338
XCTAssertTrue ( plannedJobs [ 0 ] . commandLine. contains ( subsequence: [ . flag( " -emit-const-values-path " ) , . path( . absolute( try . init( validating: " /tmp/foo.build/bar.swiftconstvalues " ) ) ) ] ) )
1338
1339
XCTAssertEqual ( plannedJobs [ 0 ] . outputs. filter ( { $0. type == . swiftConstValues } ) . count, 2 )
1339
1340
XCTAssertEqual ( plannedJobs [ 1 ] . kind, . compile)
1340
- XCTAssertTrue ( plannedJobs [ 1 ] . primaryInputs. map { $0. file. description } . elementsEqual ( [ rebase ( " baz.swift " ) ] ) )
1341
+ XCTAssertTrue ( plannedJobs [ 1 ] . primaryInputs. map { $0. file. description } . elementsEqual ( [ " baz.swift " ] ) )
1341
1342
XCTAssertTrue ( plannedJobs [ 1 ] . commandLine. contains ( " -emit-const-values-path " ) )
1342
1343
XCTAssertEqual ( plannedJobs [ 1 ] . outputs. filter ( { $0. type == . swiftConstValues } ) . count, 1 )
1343
1344
XCTAssertTrue ( plannedJobs [ 1 ] . commandLine. contains ( subsequence: [ . flag( " -emit-const-values-path " ) , . path( . absolute( try . init( validating: " /tmp/foo.build/baz.swiftconstvalues " ) ) ) ] ) )
@@ -3039,10 +3040,10 @@ final class SwiftDriverTests: XCTestCase {
3039
3040
XCTAssertEqual ( emitModuleJob. outputs [ 0 ] . file, try toPath ( " Test.swiftmodule " ) )
3040
3041
XCTAssertEqual ( emitModuleJob. outputs [ 1 ] . file, try toPath ( " Test.swiftdoc " ) )
3041
3042
XCTAssertEqual ( emitModuleJob. outputs [ 2 ] . file, try toPath ( " Test.swiftsourceinfo " ) )
3042
- XCTAssertEqual ( emitModuleJob. outputs [ 3 ] . file, try toPath ( " Test.swiftinterface " ) )
3043
+ XCTAssertEqual ( emitModuleJob. outputs [ 3 ] . file, try VirtualPath ( path : " ./ Test.swiftinterface" ) )
3043
3044
XCTAssertEqual ( emitModuleJob. outputs [ 4 ] . file, try toPath ( " Test.private.swiftinterface " ) )
3044
3045
XCTAssertEqual ( emitModuleJob. outputs [ 5 ] . file, try toPath ( " Test-Swift.h " ) )
3045
- XCTAssertEqual ( emitModuleJob. outputs [ 6 ] . file, try toPath ( " Test.tbd " ) )
3046
+ XCTAssertEqual ( emitModuleJob. outputs [ 6 ] . file, try VirtualPath ( path : " ./ Test.tbd" ) )
3046
3047
if driver1. targetTriple. isDarwin {
3047
3048
XCTAssertEqual ( emitModuleJob. outputs [ 7 ] . file, try toPath ( " Test.abi.json " ) )
3048
3049
}
@@ -5188,7 +5189,7 @@ final class SwiftDriverTests: XCTestCase {
5188
5189
// Reset the temporary store to ensure predictable results.
5189
5190
VirtualPath . resetTemporaryFileStore ( )
5190
5191
var driver = try Driver ( args: [
5191
- " swiftc " , " -emit-executable " , " test.swift " , " -emit-module " , " -avoid-emit-module-source-info " , " -experimental-emit-module-separately "
5192
+ " swiftc " , " -emit-executable " , " test.swift " , " -emit-module " , " -avoid-emit-module-source-info " , " -experimental-emit-module-separately " , " -working-directory " , localFileSystem . currentWorkingDirectory! . description
5192
5193
] )
5193
5194
let plannedJobs = try driver. planBuild ( )
5194
5195
@@ -7234,6 +7235,83 @@ final class SwiftDriverTests: XCTestCase {
7234
7235
} )
7235
7236
}
7236
7237
}
7238
+
7239
+ func testRelativeInputs( ) throws {
7240
+ do {
7241
+ // Inputs with relative paths with no -working-directory flag should remain relative
7242
+ var driver = try Driver ( args: [ " swiftc " ,
7243
+ " -target " , " arm64-apple-ios13.1 " ,
7244
+ " foo.swift " ] )
7245
+ let plannedJobs = try driver. planBuild ( )
7246
+ let compileJob = plannedJobs [ 0 ]
7247
+ XCTAssertEqual ( compileJob. kind, . compile)
7248
+ XCTAssertTrue ( compileJob. commandLine. contains ( subsequence: [ " -primary-file " , try toPathOption ( " foo.swift " , isRelative: true ) ] ) )
7249
+ }
7250
+
7251
+ do {
7252
+ // Inputs with relative paths with -working-directory flag should prefix all inputs
7253
+ var driver = try Driver ( args: [ " swiftc " ,
7254
+ " -target " , " arm64-apple-ios13.1 " ,
7255
+ " foo.swift " ,
7256
+ " -working-directory " , " /foo/bar " ] )
7257
+ let plannedJobs = try driver. planBuild ( )
7258
+ let compileJob = plannedJobs [ 0 ]
7259
+ XCTAssertEqual ( compileJob. kind, . compile)
7260
+ XCTAssertTrue ( compileJob. commandLine. contains ( subsequence: [ " -primary-file " , try toPathOption ( " /foo/bar/foo.swift " , isRelative: false ) ] ) )
7261
+ }
7262
+
7263
+ try withTemporaryFile { fileMapFile in
7264
+ let outputMapContents : ByteString = """
7265
+ {
7266
+ " " : {
7267
+ " diagnostics " : " /tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.dia " ,
7268
+ " emit-module-diagnostics " : " /tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.dia "
7269
+ },
7270
+ " foo.swift " : {
7271
+ " object " : " /tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.o "
7272
+ }
7273
+ }
7274
+ """
7275
+ try localFileSystem. writeFileContents ( fileMapFile. path, bytes: outputMapContents)
7276
+
7277
+ // Inputs with relative paths should be found in output file maps
7278
+ var driver = try Driver ( args: [ " swiftc " ,
7279
+ " -target " , " arm64-apple-ios13.1 " ,
7280
+ " foo.swift " ,
7281
+ " -output-file-map " , fileMapFile. path. description] )
7282
+ let plannedJobs = try driver. planBuild ( )
7283
+ let compileJob = plannedJobs [ 0 ]
7284
+ XCTAssertEqual ( compileJob. kind, . compile)
7285
+ XCTAssertTrue ( compileJob. commandLine. contains ( subsequence: [ " -o " , try toPathOption ( " /tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.o " , isRelative: false ) ] ) )
7286
+ }
7287
+
7288
+ try withTemporaryFile { fileMapFile in
7289
+ let outputMapContents : ByteString = """
7290
+ {
7291
+ " " : {
7292
+ " diagnostics " : " /tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.dia " ,
7293
+ " emit-module-diagnostics " : " /tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/master.emit-module.dia "
7294
+ },
7295
+ " /some/workingdir/foo.swift " : {
7296
+ " object " : " /tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.o "
7297
+ }
7298
+ }
7299
+ """
7300
+ try localFileSystem. writeFileContents ( fileMapFile. path, bytes: outputMapContents)
7301
+
7302
+ // Inputs with relative paths and working-dir should use absolute paths in output file maps
7303
+ var driver = try Driver ( args: [ " swiftc " ,
7304
+ " -target " , " arm64-apple-ios13.1 " ,
7305
+ " foo.swift " ,
7306
+ " -working-directory " , " /some/workingdir " ,
7307
+ " -output-file-map " , fileMapFile. path. description] )
7308
+ let plannedJobs = try driver. planBuild ( )
7309
+ let compileJob = plannedJobs [ 0 ]
7310
+ XCTAssertEqual ( compileJob. kind, . compile)
7311
+ XCTAssertTrue ( compileJob. commandLine. contains ( subsequence: [ " -o " , try toPathOption ( " /tmp/foo/.build/x86_64-apple-macosx/debug/foo.build/foo.o " , isRelative: false ) ] ) )
7312
+ }
7313
+
7314
+ }
7237
7315
7238
7316
func testRelativeResourceDir( ) throws {
7239
7317
do {
@@ -7274,7 +7352,7 @@ final class SwiftDriverTests: XCTestCase {
7274
7352
XCTAssertEqual ( compileJob. kind, . compile)
7275
7353
let linkJob = plannedJobs [ 1 ]
7276
7354
XCTAssertEqual ( linkJob. kind, . link)
7277
- XCTAssertTrue ( linkJob. commandLine. contains ( try toPathOption ( sdkRoot. pathString + " /usr/lib/swift/linux/x86_64/swiftrt.o " ) ) )
7355
+ XCTAssertTrue ( linkJob. commandLine. contains ( try toPathOption ( sdkRoot. pathString + " /usr/lib/swift/linux/x86_64/swiftrt.o " , isRelative : false ) ) )
7278
7356
}
7279
7357
}
7280
7358
0 commit comments