Skip to content
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

Move .swiftmodule output directory #7103

Merged
merged 1 commit into from
Dec 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ public final class SwiftTargetBuildDescription {
}
}

var modulesPath: AbsolutePath {
return self.buildParameters.buildPath.appending(component: "Modules")
}

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

Expand All @@ -122,7 +125,7 @@ public final class SwiftTargetBuildDescription {

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

/// Path to the resource Info.plist file, if generated.
Expand Down Expand Up @@ -638,7 +641,7 @@ public final class SwiftTargetBuildDescription {
result.append(contentsOf: self.sources.map(\.pathString))

result.append("-I")
result.append(self.buildParameters.buildPath.pathString)
result.append(self.modulesPath.pathString)

result += try self.compileArguments()
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ extension LLBuildManifestBuilder {
moduleName: target.target.c99name,
moduleAliases: target.target.moduleAliases,
moduleOutputPath: target.moduleOutputPath,
importPath: target.buildParameters.buildPath,
importPath: target.modulesPath,
tempsPath: target.tempsPath,
objects: try target.objects,
otherArguments: try target.compileArguments(),
Expand Down
5 changes: 3 additions & 2 deletions Sources/Build/BuildPlan/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,11 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
}
arguments += extraSwiftCFlags

// Add the search path to the directory containing the modulemap file.
// Add search paths to the directories containing module maps and Swift modules.
for target in targets {
switch target {
case .swift: break
case .swift(let targetDescription):
arguments += ["-I", targetDescription.moduleOutputPath.parentDirectory.pathString]
case .clang(let targetDescription):
if let includeDir = targetDescription.moduleMap?.parentDirectory {
arguments += ["-I", includeDir.pathString]
Expand Down
5 changes: 3 additions & 2 deletions Sources/Commands/PackageTools/DumpCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ struct DumpSymbolGraph: SwiftCommand {
)

if result.exitStatus != .terminated(code: 0) {
let commandline = "\nUsing commandline: \(result.arguments)"
switch result.output {
case .success(let value):
swiftTool.observabilityScope.emit(error: "Failed to emit symbol graph for '\(target.c99name)': \(String(decoding: value, as: UTF8.self))")
swiftTool.observabilityScope.emit(error: "Failed to emit symbol graph for '\(target.c99name)': \(String(decoding: value, as: UTF8.self))\(commandline)")
case .failure(let error):
swiftTool.observabilityScope.emit(error: "Internal error while emitting symbol graph for '\(target.c99name)': \(error)")
swiftTool.observabilityScope.emit(error: "Internal error while emitting symbol graph for '\(target.c99name)': \(error)\(commandline)")
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,8 @@ final class BuildPlanTests: XCTestCase {
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
"-target", defaultTargetTriple,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "exe.build", "exe.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "lib.swiftmodule").pathString,
"-g",
]
#elseif os(Windows)
Expand Down Expand Up @@ -869,7 +869,7 @@ final class BuildPlanTests: XCTestCase {
let contents: String = try fs.readFileContents(yaml)
let swiftGetVersionFilePath = try XCTUnwrap(llbuild.swiftGetVersionFiles.first?.value)
XCTAssertMatch(contents, .contains("""
inputs: ["\(Pkg.appending(components: "Sources", "exe", "main.swift").escapedPathString)","\(swiftGetVersionFilePath.escapedPathString)","\(buildPath.appending(components: "PkgLib.swiftmodule").escapedPathString)","\(buildPath.appending(components: "exe.build", "sources").escapedPathString)"]
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)"]
"""))

}
Expand Down Expand Up @@ -1736,8 +1736,8 @@ final class BuildPlanTests: XCTestCase {
"@\(buildPath.appending(components: "PkgPackageTests.product", "Objects.LinkFileList"))"] +
rpathsForBackdeployment +
["-target", "\(hostTriple.tripleString(forPlatformVersion: version))",
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Foo.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "FooTests.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "Foo.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "FooTests.swiftmodule").pathString,
"-g",
])
#elseif os(Windows)
Expand Down Expand Up @@ -2313,7 +2313,7 @@ final class BuildPlanTests: XCTestCase {
"@\(buildPath.appending(components: "Bar-Baz.product", "Objects.LinkFileList"))",
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
"-target", defaultTargetTriple,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Bar.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "Bar.swiftmodule").pathString,
"-g",
])
#elseif os(Windows)
Expand Down Expand Up @@ -2432,7 +2432,7 @@ final class BuildPlanTests: XCTestCase {
"@\(buildPath.appending(components: "lib.product", "Objects.LinkFileList"))",
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
"-target", defaultTargetTriple,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "lib.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
"-g",
]
#elseif os(Windows)
Expand Down Expand Up @@ -4110,7 +4110,7 @@ final class BuildPlanTests: XCTestCase {
XCTAssertMatch(contents, .contains("""
"\(buildPath.appending(components: "Bar.build", "main.m.o").escapedPathString)":
tool: clang
inputs: ["\(buildPath.appending(components: "Foo.swiftmodule").escapedPathString)","\(PkgA.appending(components: "Sources", "Bar", "main.m").escapedPathString)"]
inputs: ["\(buildPath.appending(components: "Modules", "Foo.swiftmodule").escapedPathString)","\(PkgA.appending(components: "Sources", "Bar", "main.m").escapedPathString)"]
outputs: ["\(buildPath.appending(components: "Bar.build", "main.m.o").escapedPathString)"]
description: "Compiling Bar main.m"
"""))
Expand Down Expand Up @@ -4184,7 +4184,7 @@ final class BuildPlanTests: XCTestCase {
XCTAssertMatch(contents, .contains("""
"\(buildPath.appending(components: "Bar.build", "main.m.o").escapedPathString)":
tool: clang
inputs: ["\(buildPath.appending(components: "Foo.swiftmodule").escapedPathString)","\(PkgA.appending(components: "Sources", "Bar", "main.m").escapedPathString)"]
inputs: ["\(buildPath.appending(components: "Modules", "Foo.swiftmodule").escapedPathString)","\(PkgA.appending(components: "Sources", "Bar", "main.m").escapedPathString)"]
outputs: ["\(buildPath.appending(components: "Bar.build", "main.m.o").escapedPathString)"]
description: "Compiling Bar main.m"
"""))
Expand Down Expand Up @@ -4322,10 +4322,10 @@ final class BuildPlanTests: XCTestCase {
XCTAssertMatch(contents, .contains("""
"\(buildPath.appending(components: "lib.build", "lib.swiftmodule.o").escapedPathString)":
tool: shell
inputs: ["\(buildPath.appending(components: "lib.swiftmodule").escapedPathString)"]
inputs: ["\(buildPath.appending(components: "Modules", "lib.swiftmodule").escapedPathString)"]
outputs: ["\(buildPath.appending(components: "lib.build", "lib.swiftmodule.o").escapedPathString)"]
description: "Wrapping AST for lib for debugging"
args: ["\(result.plan.buildParameters.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"]
args: ["\(result.plan.buildParameters.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"]
"""))
}

Expand Down Expand Up @@ -4958,7 +4958,7 @@ final class BuildPlanTests: XCTestCase {

let yamlContents: String = try fs.readFileContents(yaml)
let inputs: SerializedJSON = """
inputs: ["\(AbsolutePath("/Pkg/Snippets/ASnippet.swift"))","\(swiftGetVersionFilePath)","\(AbsolutePath("/Pkg/.build/debug/Lib.swiftmodule"))"
inputs: ["\(AbsolutePath("/Pkg/Snippets/ASnippet.swift"))","\(swiftGetVersionFilePath)","\(AbsolutePath("/Pkg/.build/debug/Modules/Lib.swiftmodule"))"
"""
XCTAssertMatch(yamlContents, .contains(inputs.underlying))
}
Expand Down Expand Up @@ -5173,8 +5173,8 @@ final class BuildPlanTests: XCTestCase {
"@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
"-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
"-target", defaultTargetTriple,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "Modules", "lib.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "exe.build", "exe.swiftmodule").pathString,
"-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "lib.swiftmodule").pathString,
"-g",
]
#elseif os(Windows)
Expand Down
24 changes: 16 additions & 8 deletions Tests/CommandsTests/BuildToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct BuildResult {
let stdout: String
let stderr: String
let binContents: [String]
let moduleContents: [String]
}

final class BuildToolTests: CommandsTestCase {
Expand Down Expand Up @@ -55,7 +56,14 @@ final class BuildToolTests: CommandsTestCase {
// is what `binContents` is meant to represent.
return contents != ["output-file-map.json"]
}
return BuildResult(binPath: binPath, stdout: stdout, stderr: stderr, binContents: binContents)
let moduleContents = (try? localFileSystem.getDirectoryContents(binPath.appending(component: "Modules"))) ?? []
return BuildResult(
binPath: binPath,
stdout: stdout,
stderr: stderr,
binContents: binContents,
moduleContents: moduleContents
)
}

func testUsage() throws {
Expand Down Expand Up @@ -325,9 +333,9 @@ final class BuildToolTests: CommandsTestCase {
// Also make sure we didn't emit parseable module interfaces
// (do this here to avoid doing a second build in
// testParseableInterfaces().
XCTAssertNoMatch(result.binContents, ["ATarget.swiftinterface"])
XCTAssertNoMatch(result.binContents, ["BTarget.swiftinterface"])
XCTAssertNoMatch(result.binContents, ["CTarget.swiftinterface"])
XCTAssertNoMatch(result.moduleContents, ["ATarget.swiftinterface"])
XCTAssertNoMatch(result.moduleContents, ["BTarget.swiftinterface"])
XCTAssertNoMatch(result.moduleContents, ["CTarget.swiftinterface"])
}
}
}
Expand All @@ -336,8 +344,8 @@ final class BuildToolTests: CommandsTestCase {
try fixture(name: "Miscellaneous/ParseableInterfaces") { fixturePath in
do {
let result = try build(["--enable-parseable-module-interfaces"], packagePath: fixturePath)
XCTAssertMatch(result.binContents, ["A.swiftinterface"])
XCTAssertMatch(result.binContents, ["B.swiftinterface"])
XCTAssertMatch(result.moduleContents, ["A.swiftinterface"])
XCTAssertMatch(result.moduleContents, ["B.swiftinterface"])
} catch SwiftPMError.executionFailure(_, _, let stderr) {
XCTFail(stderr)
}
Expand All @@ -348,8 +356,8 @@ final class BuildToolTests: CommandsTestCase {
try fixture(name: "Miscellaneous/LibraryEvolution") { fixturePath in
do {
let result = try build([], packagePath: fixturePath)
XCTAssertMatch(result.binContents, ["A.swiftinterface"])
XCTAssertMatch(result.binContents, ["B.swiftinterface"])
XCTAssertMatch(result.moduleContents, ["A.swiftinterface"])
XCTAssertMatch(result.moduleContents, ["B.swiftinterface"])
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class MiscellaneousTestCase: XCTestCase {
XCTAssertBuilds(fixturePath.appending("app"))
let buildDir = fixturePath.appending(components: "app", ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug")
XCTAssertFileExists(buildDir.appending("FooExec"))
XCTAssertFileExists(buildDir.appending("FooLib1.swiftmodule"))
XCTAssertFileExists(buildDir.appending("FooLib2.swiftmodule"))
XCTAssertFileExists(buildDir.appending(components: "Modules", "FooLib1.swiftmodule"))
XCTAssertFileExists(buildDir.appending(components: "Modules", "FooLib2.swiftmodule"))
}
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/FunctionalTests/ModuleAliasingFixtureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ModuleAliasingFixtureTests: XCTestCase {
let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug")
XCTAssertBuilds(pkgPath, extraArgs: ["--vv"])
XCTAssertFileExists(buildPath.appending(components: "App"))
XCTAssertFileExists(buildPath.appending(components: "GameUtils.swiftmodule"))
XCTAssertFileExists(buildPath.appending(components: "Utils.swiftmodule"))
XCTAssertFileExists(buildPath.appending(components: "Modules", "GameUtils.swiftmodule"))
XCTAssertFileExists(buildPath.appending(components: "Modules", "Utils.swiftmodule"))
_ = try SwiftPM.Build.execute(packagePath: pkgPath)
}
}
Expand All @@ -37,8 +37,8 @@ class ModuleAliasingFixtureTests: XCTestCase {
let buildPath = pkgPath.appending(components: ".build", try UserToolchain.default.targetTriple.platformBuildPathComponent, "debug")
XCTAssertBuilds(pkgPath, extraArgs: ["--vv"])
XCTAssertFileExists(buildPath.appending(components: "App"))
XCTAssertFileExists(buildPath.appending(components: "AUtils.swiftmodule"))
XCTAssertFileExists(buildPath.appending(components: "BUtils.swiftmodule"))
XCTAssertFileExists(buildPath.appending(components: "Modules", "AUtils.swiftmodule"))
XCTAssertFileExists(buildPath.appending(components: "Modules", "BUtils.swiftmodule"))
_ = try SwiftPM.Build.execute(packagePath: pkgPath)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/WorkspaceTests/InitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class InitTests: XCTestCase {
#else
XCTAssertFileExists(binPath.appending("Foo"))
#endif
XCTAssertFileExists(binPath.appending(components: "Foo.swiftmodule"))
XCTAssertFileExists(binPath.appending(components: "Modules", "Foo.swiftmodule"))
}
}

Expand Down Expand Up @@ -145,7 +145,7 @@ class InitTests: XCTestCase {
// Try building it
XCTAssertBuilds(path)
let triple = try UserToolchain.default.targetTriple
XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Foo.swiftmodule"))
XCTAssertFileExists(path.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "Foo.swiftmodule"))
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@ class InitTests: XCTestCase {
// Try building it.
XCTAssertBuilds(packageRoot)
let triple = try UserToolchain.default.targetTriple
XCTAssertFileExists(packageRoot.appending(components: ".build", triple.platformBuildPathComponent, "debug", "some_package.swiftmodule"))
XCTAssertFileExists(packageRoot.appending(components: ".build", triple.platformBuildPathComponent, "debug", "Modules", "some_package.swiftmodule"))
}
}

Expand Down
Loading