Skip to content

Commit 6bde206

Browse files
committed
Revert "Move .swiftmodule output directory (#7103)"
This reverts commit 20b86fe.
1 parent d457fa4 commit 6bde206

File tree

11 files changed

+45
-63
lines changed

11 files changed

+45
-63
lines changed

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

+4-8
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,12 @@ public final class SwiftTargetBuildDescription {
103103
}
104104
}
105105

106-
var modulesPath: AbsolutePath {
107-
return self.buildParameters.buildPath.appending(component: "Modules")
108-
}
109-
110106
/// The path to the swiftmodule file after compilation.
111-
public var moduleOutputPath: AbsolutePath { // note: needs to be public because of sourcekit-lsp
107+
var moduleOutputPath: AbsolutePath {
112108
// If we're an executable and we're not allowing test targets to link against us, we hide the module.
113109
let triple = buildParameters.triple
114110
let allowLinkingAgainstExecutables = (triple.isDarwin() || triple.isLinux() || triple.isWindows()) && self.toolsVersion >= .v5_5
115-
let dirPath = (target.type == .executable && !allowLinkingAgainstExecutables) ? self.tempsPath : self.modulesPath
111+
let dirPath = (target.type == .executable && !allowLinkingAgainstExecutables) ? self.tempsPath : buildParameters.buildPath
116112
return dirPath.appending(component: self.target.c99name + ".swiftmodule")
117113
}
118114

@@ -125,7 +121,7 @@ public final class SwiftTargetBuildDescription {
125121

126122
/// The path to the swifinterface file after compilation.
127123
var parseableModuleInterfaceOutputPath: AbsolutePath {
128-
self.modulesPath.appending(component: self.target.c99name + ".swiftinterface")
124+
self.buildParameters.buildPath.appending(component: self.target.c99name + ".swiftinterface")
129125
}
130126

131127
/// Path to the resource Info.plist file, if generated.
@@ -658,7 +654,7 @@ public final class SwiftTargetBuildDescription {
658654
result.append(contentsOf: self.sources.map(\.pathString))
659655

660656
result.append("-I")
661-
result.append(self.modulesPath.pathString)
657+
result.append(self.buildParameters.buildPath.pathString)
662658

663659
result += try self.compileArguments()
664660
return result

Sources/Build/BuildManifest/LLBuildManifestBuilder+Swift.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ extension LLBuildManifestBuilder {
386386
moduleName: target.target.c99name,
387387
moduleAliases: target.target.moduleAliases,
388388
moduleOutputPath: target.moduleOutputPath,
389-
importPath: target.modulesPath,
389+
importPath: target.buildParameters.buildPath,
390390
tempsPath: target.tempsPath,
391391
objects: try target.objects,
392392
otherArguments: try target.compileArguments(),

Sources/Build/BuildPlan/BuildPlan.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,10 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
522522
}
523523
arguments += extraSwiftCFlags
524524

525-
// Add search paths to the directories containing module maps and Swift modules.
525+
// Add the search path to the directory containing the modulemap file.
526526
for target in targets {
527527
switch target {
528-
case .swift(let targetDescription):
529-
arguments += ["-I", targetDescription.moduleOutputPath.parentDirectory.pathString]
528+
case .swift: break
530529
case .clang(let targetDescription):
531530
if let includeDir = targetDescription.moduleMap?.parentDirectory {
532531
arguments += ["-I", includeDir.pathString]

Sources/Commands/PackageTools/DumpCommands.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ struct DumpSymbolGraph: SwiftCommand {
7878
)
7979

8080
if result.exitStatus != .terminated(code: 0) {
81-
let commandline = "\nUsing commandline: \(result.arguments)"
8281
switch result.output {
8382
case .success(let value):
84-
swiftTool.observabilityScope.emit(error: "Failed to emit symbol graph for '\(target.c99name)': \(String(decoding: value, as: UTF8.self))\(commandline)")
83+
swiftTool.observabilityScope.emit(error: "Failed to emit symbol graph for '\(target.c99name)': \(String(decoding: value, as: UTF8.self))")
8584
case .failure(let error):
86-
swiftTool.observabilityScope.emit(error: "Internal error while emitting symbol graph for '\(target.c99name)': \(error)\(commandline)")
85+
swiftTool.observabilityScope.emit(error: "Internal error while emitting symbol graph for '\(target.c99name)': \(error)")
8786
}
8887
}
8988
}

Tests/BuildTests/BuildPlanTests.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,8 @@ final class BuildPlanTests: XCTestCase {
707707
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
708708
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
709709
"-target", defaultTargetTriple,
710-
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
711710
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "exe.build", "exe.swiftmodule").pathString,
711+
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "lib.swiftmodule").pathString,
712712
"-g",
713713
]
714714
#elseif os(Windows)
@@ -931,7 +931,7 @@ final class BuildPlanTests: XCTestCase {
931931
let contents: String = try fs.readFileContents(yaml)
932932
let swiftGetVersionFilePath = try XCTUnwrap(llbuild.swiftGetVersionFiles.first?.value)
933933
XCTAssertMatch(contents, .contains("""
934-
inputs: ["\(Pkg.appending(components: "Sources", "exe", "main.swift").escapedPathString)","\(swiftGetVersionFilePath.escapedPathString)","\(buildPath.appending(components: "Modules", "PkgLib.swiftmodule").escapedPathString)","\(buildPath.appending(components: "exe.build", "sources").escapedPathString)"]
934+
inputs: ["\(Pkg.appending(components: "Sources", "exe", "main.swift").escapedPathString)","\(swiftGetVersionFilePath.escapedPathString)","\(buildPath.appending(components: "PkgLib.swiftmodule").escapedPathString)","\(buildPath.appending(components: "exe.build", "sources").escapedPathString)"]
935935
"""))
936936

937937
}
@@ -1859,8 +1859,8 @@ final class BuildPlanTests: XCTestCase {
18591859
"@\(buildPath.appending(components: "PkgPackageTests.product", "Objects.LinkFileList"))"] +
18601860
rpathsForBackdeployment +
18611861
["-target", "\(hostTriple.tripleString(forPlatformVersion: version))",
1862-
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "Foo.swiftmodule").pathString,
1863-
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "FooTests.swiftmodule").pathString,
1862+
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Foo.swiftmodule").pathString,
1863+
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "FooTests.swiftmodule").pathString,
18641864
"-g",
18651865
])
18661866
#elseif os(Windows)
@@ -2436,7 +2436,7 @@ final class BuildPlanTests: XCTestCase {
24362436
"@\(buildPath.appending(components: "Bar-Baz.product", "Objects.LinkFileList"))",
24372437
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
24382438
"-target", defaultTargetTriple,
2439-
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "Bar.swiftmodule").pathString,
2439+
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Bar.swiftmodule").pathString,
24402440
"-g",
24412441
])
24422442
#elseif os(Windows)
@@ -2555,7 +2555,7 @@ final class BuildPlanTests: XCTestCase {
25552555
"@\(buildPath.appending(components: "lib.product", "Objects.LinkFileList"))",
25562556
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
25572557
"-target", defaultTargetTriple,
2558-
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
2558+
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "lib.swiftmodule").pathString,
25592559
"-g",
25602560
]
25612561
#elseif os(Windows)
@@ -4378,7 +4378,7 @@ final class BuildPlanTests: XCTestCase {
43784378
XCTAssertMatch(contents, .contains("""
43794379
"\(buildPath.appending(components: "Bar.build", "main.m.o").escapedPathString)":
43804380
tool: clang
4381-
inputs: ["\(buildPath.appending(components: "Modules", "Foo.swiftmodule").escapedPathString)","\(PkgA.appending(components: "Sources", "Bar", "main.m").escapedPathString)"]
4381+
inputs: ["\(buildPath.appending(components: "Foo.swiftmodule").escapedPathString)","\(PkgA.appending(components: "Sources", "Bar", "main.m").escapedPathString)"]
43824382
outputs: ["\(buildPath.appending(components: "Bar.build", "main.m.o").escapedPathString)"]
43834383
description: "Compiling Bar main.m"
43844384
"""))
@@ -4484,7 +4484,7 @@ final class BuildPlanTests: XCTestCase {
44844484
XCTAssertMatch(contents, .contains("""
44854485
"\(buildPath.appending(components: "Bar.build", "main.m.o").escapedPathString)":
44864486
tool: clang
4487-
inputs: ["\(buildPath.appending(components: "Modules", "Foo.swiftmodule").escapedPathString)","\(PkgA.appending(components: "Sources", "Bar", "main.m").escapedPathString)"]
4487+
inputs: ["\(buildPath.appending(components: "Foo.swiftmodule").escapedPathString)","\(PkgA.appending(components: "Sources", "Bar", "main.m").escapedPathString)"]
44884488
outputs: ["\(buildPath.appending(components: "Bar.build", "main.m.o").escapedPathString)"]
44894489
description: "Compiling Bar main.m"
44904490
"""))
@@ -4654,10 +4654,10 @@ final class BuildPlanTests: XCTestCase {
46544654
XCTAssertMatch(contents, .contains("""
46554655
"\(buildPath.appending(components: "lib.build", "lib.swiftmodule.o").escapedPathString)":
46564656
tool: shell
4657-
inputs: ["\(buildPath.appending(components: "Modules", "lib.swiftmodule").escapedPathString)"]
4657+
inputs: ["\(buildPath.appending(components: "lib.swiftmodule").escapedPathString)"]
46584658
outputs: ["\(buildPath.appending(components: "lib.build", "lib.swiftmodule.o").escapedPathString)"]
46594659
description: "Wrapping AST for lib for debugging"
4660-
args: ["\(result.plan.destinationBuildParameters.toolchain.swiftCompilerPath.escapedPathString)","-modulewrap","\(buildPath.appending(components: "Modules", "lib.swiftmodule").escapedPathString)","-o","\(buildPath.appending(components: "lib.build", "lib.swiftmodule.o").escapedPathString)","-target","x86_64-unknown-linux-gnu"]
4660+
args: ["\(result.plan.destinationBuildParameters.toolchain.swiftCompilerPath.escapedPathString)","-modulewrap","\(buildPath.appending(components: "lib.swiftmodule").escapedPathString)","-o","\(buildPath.appending(components: "lib.build", "lib.swiftmodule.o").escapedPathString)","-target","x86_64-unknown-linux-gnu"]
46614661
"""))
46624662
}
46634663

@@ -5290,7 +5290,7 @@ final class BuildPlanTests: XCTestCase {
52905290

52915291
let yamlContents: String = try fs.readFileContents(yaml)
52925292
let inputs: SerializedJSON = """
5293-
inputs: ["\(AbsolutePath("/Pkg/Snippets/ASnippet.swift"))","\(swiftGetVersionFilePath)","\(AbsolutePath("/Pkg/.build/debug/Modules/Lib.swiftmodule"))"
5293+
inputs: ["\(AbsolutePath("/Pkg/Snippets/ASnippet.swift"))","\(swiftGetVersionFilePath)","\(AbsolutePath("/Pkg/.build/debug/Lib.swiftmodule"))"
52945294
"""
52955295
XCTAssertMatch(yamlContents, .contains(inputs.underlying))
52965296
}
@@ -5505,8 +5505,8 @@ final class BuildPlanTests: XCTestCase {
55055505
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
55065506
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
55075507
"-target", defaultTargetTriple,
5508-
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
55095508
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "exe.build", "exe.swiftmodule").pathString,
5509+
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "lib.swiftmodule").pathString,
55105510
"-g",
55115511
]
55125512
#elseif os(Windows)

Tests/CommandsTests/BuildToolTests.swift

+8-16
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct BuildResult {
2626
let stdout: String
2727
let stderr: String
2828
let binContents: [String]
29-
let moduleContents: [String]
3029
}
3130

3231
final class BuildToolTests: CommandsTestCase {
@@ -56,14 +55,7 @@ final class BuildToolTests: CommandsTestCase {
5655
// is what `binContents` is meant to represent.
5756
return contents != ["output-file-map.json"]
5857
}
59-
let moduleContents = (try? localFileSystem.getDirectoryContents(binPath.appending(component: "Modules"))) ?? []
60-
return BuildResult(
61-
binPath: binPath,
62-
stdout: stdout,
63-
stderr: stderr,
64-
binContents: binContents,
65-
moduleContents: moduleContents
66-
)
58+
return BuildResult(binPath: binPath, stdout: stdout, stderr: stderr, binContents: binContents)
6759
}
6860

6961
func testUsage() throws {
@@ -333,9 +325,9 @@ final class BuildToolTests: CommandsTestCase {
333325
// Also make sure we didn't emit parseable module interfaces
334326
// (do this here to avoid doing a second build in
335327
// testParseableInterfaces().
336-
XCTAssertNoMatch(result.moduleContents, ["ATarget.swiftinterface"])
337-
XCTAssertNoMatch(result.moduleContents, ["BTarget.swiftinterface"])
338-
XCTAssertNoMatch(result.moduleContents, ["CTarget.swiftinterface"])
328+
XCTAssertNoMatch(result.binContents, ["ATarget.swiftinterface"])
329+
XCTAssertNoMatch(result.binContents, ["BTarget.swiftinterface"])
330+
XCTAssertNoMatch(result.binContents, ["CTarget.swiftinterface"])
339331
}
340332
}
341333
}
@@ -344,8 +336,8 @@ final class BuildToolTests: CommandsTestCase {
344336
try fixture(name: "Miscellaneous/ParseableInterfaces") { fixturePath in
345337
do {
346338
let result = try build(["--enable-parseable-module-interfaces"], packagePath: fixturePath)
347-
XCTAssertMatch(result.moduleContents, ["A.swiftinterface"])
348-
XCTAssertMatch(result.moduleContents, ["B.swiftinterface"])
339+
XCTAssertMatch(result.binContents, ["A.swiftinterface"])
340+
XCTAssertMatch(result.binContents, ["B.swiftinterface"])
349341
} catch SwiftPMError.executionFailure(_, _, let stderr) {
350342
XCTFail(stderr)
351343
}
@@ -356,8 +348,8 @@ final class BuildToolTests: CommandsTestCase {
356348
try fixture(name: "Miscellaneous/LibraryEvolution") { fixturePath in
357349
do {
358350
let result = try build([], packagePath: fixturePath)
359-
XCTAssertMatch(result.moduleContents, ["A.swiftinterface"])
360-
XCTAssertMatch(result.moduleContents, ["B.swiftinterface"])
351+
XCTAssertMatch(result.binContents, ["A.swiftinterface"])
352+
XCTAssertMatch(result.binContents, ["B.swiftinterface"])
361353
}
362354
}
363355
}

Tests/FunctionalTests/MiscellaneousTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ class MiscellaneousTestCase: XCTestCase {
5454
XCTAssertBuilds(fixturePath.appending("app"))
5555
let buildDir = fixturePath.appending(components: "app", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug")
5656
XCTAssertFileExists(buildDir.appending("FooExec"))
57-
XCTAssertFileExists(buildDir.appending(components: "Modules", "FooLib1.swiftmodule"))
58-
XCTAssertFileExists(buildDir.appending(components: "Modules", "FooLib2.swiftmodule"))
57+
XCTAssertFileExists(buildDir.appending("FooLib1.swiftmodule"))
58+
XCTAssertFileExists(buildDir.appending("FooLib2.swiftmodule"))
5959
}
6060
}
6161

Tests/FunctionalTests/ModuleAliasingFixtureTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class ModuleAliasingFixtureTests: XCTestCase {
2525
let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug")
2626
XCTAssertBuilds(pkgPath, extraArgs: ["--vv"])
2727
XCTAssertFileExists(buildPath.appending(components: "App"))
28-
XCTAssertFileExists(buildPath.appending(components: "Modules", "GameUtils.swiftmodule"))
29-
XCTAssertFileExists(buildPath.appending(components: "Modules", "Utils.swiftmodule"))
28+
XCTAssertFileExists(buildPath.appending(components: "GameUtils.swiftmodule"))
29+
XCTAssertFileExists(buildPath.appending(components: "Utils.swiftmodule"))
3030
_ = try SwiftPM.Build.execute(packagePath: pkgPath)
3131
}
3232
}
@@ -37,8 +37,8 @@ class ModuleAliasingFixtureTests: XCTestCase {
3737
let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug")
3838
XCTAssertBuilds(pkgPath, extraArgs: ["--vv"])
3939
XCTAssertFileExists(buildPath.appending(components: "App"))
40-
XCTAssertFileExists(buildPath.appending(components: "Modules", "AUtils.swiftmodule"))
41-
XCTAssertFileExists(buildPath.appending(components: "Modules", "BUtils.swiftmodule"))
40+
XCTAssertFileExists(buildPath.appending(components: "AUtils.swiftmodule"))
41+
XCTAssertFileExists(buildPath.appending(components: "BUtils.swiftmodule"))
4242
_ = try SwiftPM.Build.execute(packagePath: pkgPath)
4343
}
4444
}

Tests/SourceKitLSPAPITests/SourceKitLSPAPITests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SourceKitLSPAPITests: XCTestCase {
5252
let description = BuildDescription(buildPlan: plan)
5353

5454
try description.checkArguments(for: "exe", graph: graph, partialArguments: ["/fake/path/to/swiftc", "-module-name", "exe", "-emit-dependencies", "-emit-module", "-emit-module-path", "/path/to/build/debug/exe.build/exe.swiftmodule"])
55-
try description.checkArguments(for: "lib", graph: graph, partialArguments: ["/fake/path/to/swiftc", "-module-name", "lib", "-emit-dependencies", "-emit-module", "-emit-module-path", "/path/to/build/debug/Modules/lib.swiftmodule"])
55+
try description.checkArguments(for: "lib", graph: graph, partialArguments: ["/fake/path/to/swiftc", "-module-name", "lib", "-emit-dependencies", "-emit-module", "-emit-module-path", "/path/to/build/debug/lib.swiftmodule"])
5656
}
5757
}
5858

Tests/WorkspaceTests/InitTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class InitTests: XCTestCase {
9494
#else
9595
XCTAssertFileExists(binPath.appending("Foo"))
9696
#endif
97-
XCTAssertFileExists(binPath.appending(components: "Modules", "Foo.swiftmodule"))
97+
XCTAssertFileExists(binPath.appending(components: "Foo.swiftmodule"))
9898
}
9999
}
100100

@@ -145,7 +145,7 @@ class InitTests: XCTestCase {
145145
// Try building it
146146
XCTAssertBuilds(path)
147147
let triple = try UserToolchain.default.targetTriple
148-
XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule"))
148+
XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Foo.swiftmodule"))
149149
}
150150
}
151151

@@ -243,7 +243,7 @@ class InitTests: XCTestCase {
243243
// Try building it.
244244
XCTAssertBuilds(packageRoot)
245245
let triple = try UserToolchain.default.targetTriple
246-
XCTAssertFileExists(packageRoot.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "some_package.swiftmodule"))
246+
XCTAssertFileExists(packageRoot.appending(components: ".build", triple.platformBuildPathComponent, "debug", "some_package.swiftmodule"))
247247
}
248248
}
249249

0 commit comments

Comments
 (0)