Skip to content

Commit b7efe72

Browse files
authored
Merge pull request #2165 from aciidb0mb3r/remove-sbt-5.1
Remove use of swift-build-tool from SwiftPM
2 parents 560a2c0 + 6f2a1e0 commit b7efe72

File tree

3 files changed

+5
-90
lines changed

3 files changed

+5
-90
lines changed

Sources/Commands/Options.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public class ToolOptions {
5050
/// If should link the Swift stdlib statically.
5151
public var shouldLinkStaticSwiftStdlib = false
5252

53-
/// If should enable building with llbuild library.
54-
public var shouldEnableLLBuildLibrary = true
55-
5653
/// Skip updating dependencies from their remote during a resolution.
5754
public var skipDependencyUpdate = false
5855

Sources/Commands/SwiftTool.swift

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ public class SwiftTool<Options: ToolOptions> {
212212
/// The stream to print standard output on.
213213
fileprivate var stdoutStream: OutputByteStream = Basic.stdoutStream
214214

215-
/// If true, Redirects the stdout stream to stderr when invoking
216-
/// `swift-build-tool`.
217-
private var shouldRedirectStdoutToStderr = false
218-
219215
/// Create an instance of this tool.
220216
///
221217
/// - parameter args: The command line arguments to be passed to this tool.
@@ -329,11 +325,6 @@ public class SwiftTool<Options: ToolOptions> {
329325
usage: "Link Swift stdlib statically"),
330326
to: { $0.shouldLinkStaticSwiftStdlib = $1 })
331327

332-
binder.bind(
333-
option: parser.add(option: "--enable-llbuild-library", kind: Bool.self,
334-
usage: "Enable building with the llbuild library"),
335-
to: { $0.shouldEnableLLBuildLibrary = $1 })
336-
337328
binder.bind(
338329
option: parser.add(option: "--force-resolved-versions", kind: Bool.self),
339330
to: { $0.forceResolvedVersions = $1 })
@@ -514,7 +505,6 @@ public class SwiftTool<Options: ToolOptions> {
514505

515506
/// Start redirecting the standard output stream to the standard error stream.
516507
func redirectStdoutToStderr() {
517-
self.shouldRedirectStdoutToStderr = true
518508
self.stdoutStream = Basic.stderrStream
519509
DiagnosticsEngineHandler.default.stdoutStream = Basic.stderrStream
520510
}
@@ -598,14 +588,14 @@ public class SwiftTool<Options: ToolOptions> {
598588
return
599589
}
600590

601-
let yaml = plan.buildParameters.llbuildManifest
591+
let manifest = plan.buildParameters.llbuildManifest
602592
// Generate the llbuild manifest.
603-
let client = options.shouldEnableLLBuildLibrary ? "basic" : "swift-build"
604-
let llbuild = LLBuildManifestGenerator(plan, client: client)
605-
try llbuild.generateManifest(at: yaml)
593+
let llbuild = LLBuildManifestGenerator(plan, client: "basic")
594+
try llbuild.generateManifest(at: manifest)
606595

607596
// Run llbuild.
608-
try runLLBuild(plan: plan, manifest: yaml, llbuildTarget: llbuildTargetName)
597+
assert(localFileSystem.isFile(manifest), "llbuild manifest not present: \(manifest)")
598+
try runLLBuild(plan: plan, manifest: manifest, llbuildTarget: llbuildTargetName)
609599

610600
// Create backwards-compatibilty symlink to old build path.
611601
let oldBuildPath = buildPath.appending(component: options.configuration.dirname)
@@ -616,15 +606,6 @@ public class SwiftTool<Options: ToolOptions> {
616606
}
617607

618608
func runLLBuild(plan: BuildPlan, manifest: AbsolutePath, llbuildTarget: String) throws {
619-
assert(localFileSystem.isFile(manifest), "llbuild manifest not present: \(manifest)")
620-
if options.shouldEnableLLBuildLibrary {
621-
try runLLBuildAsLibrary(plan: plan, manifest: manifest, llbuildTarget: llbuildTarget)
622-
} else {
623-
try runLLBuildAsExecutable(manifest: manifest, llbuildTarget: llbuildTarget)
624-
}
625-
}
626-
627-
func runLLBuildAsLibrary(plan: BuildPlan, manifest: AbsolutePath, llbuildTarget: String) throws {
628609
// Setup the build delegate.
629610
let isVerbose = verbosity != .concise
630611
let progressAnimation: ProgressAnimationProtocol = isVerbose ?
@@ -646,59 +627,6 @@ public class SwiftTool<Options: ToolOptions> {
646627
guard success else { throw Diagnostics.fatalError }
647628
}
648629

649-
func runLLBuildAsExecutable(manifest: AbsolutePath, llbuildTarget: String) throws {
650-
// Create a temporary directory for the build process.
651-
let tempDirName = "org.swift.swiftpm.\(NSUserName())"
652-
let tempDir = try determineTempDirectory().appending(component: tempDirName)
653-
try localFileSystem.createDirectory(tempDir, recursive: true)
654-
655-
// Run the swift-build-tool with the generated manifest.
656-
var args = [String]()
657-
658-
#if os(macOS)
659-
// If enabled, use sandbox-exec on macOS. This provides some safety
660-
// against arbitrary code execution. We only allow the permissions which
661-
// are absolutely necessary for performing a build.
662-
if !options.shouldDisableSandbox {
663-
let allowedDirectories = [
664-
tempDir,
665-
buildPath,
666-
].map(resolveSymlinks)
667-
args += ["sandbox-exec", "-p", sandboxProfile(allowedDirectories: allowedDirectories)]
668-
}
669-
#endif
670-
671-
args += [try getToolchain().llbuild.pathString, "-f", manifest.pathString, llbuildTarget]
672-
if verbosity != .concise {
673-
args.append("-v")
674-
}
675-
676-
// Create the environment for llbuild.
677-
var env = Process.env
678-
// We override the temporary directory so tools assuming full access to
679-
// the tmp dir can create files here freely, provided they respect this
680-
// variable.
681-
env["TMPDIR"] = tempDir.pathString
682-
683-
// Run llbuild and print output on standard streams.
684-
let process = Process(arguments: args, environment: env, outputRedirection: shouldRedirectStdoutToStderr ? .collect : .none)
685-
try process.launch()
686-
try processSet.add(process)
687-
let result = try process.waitUntilExit()
688-
689-
// Emit the output to the selected stream if we need to redirect the
690-
// stream.
691-
if shouldRedirectStdoutToStderr {
692-
self.stdoutStream <<< (try result.utf8stderrOutput())
693-
self.stdoutStream <<< (try result.utf8Output())
694-
self.stdoutStream.flush()
695-
}
696-
697-
guard result.exitStatus == .terminated(code: 0) else {
698-
throw ProcessResult.Error.nonZeroExit(result)
699-
}
700-
}
701-
702630
/// Return the build parameters.
703631
func buildParameters() throws -> BuildParameters {
704632
return try _buildParameters.dematerialize()

Sources/Workspace/UserToolchain.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ public final class UserToolchain: Toolchain {
6464
/// This is only present on macOS.
6565
public let xctest: AbsolutePath?
6666

67-
/// Path to llbuild.
68-
public let llbuild: AbsolutePath
69-
7067
/// The compilation destination object.
7168
public let destination: Destination
7269

@@ -206,13 +203,6 @@ public final class UserToolchain: Toolchain {
206203
let swiftCompilers = try UserToolchain.determineSwiftCompilers(binDir: binDir, lookup: { UserToolchain.lookup(variable: $0, searchPaths: searchPaths) })
207204
self.swiftCompiler = swiftCompilers.compile
208205

209-
// Look for llbuild in bin dir.
210-
llbuild = binDir.appending(component: "swift-build-tool")
211-
guard localFileSystem.exists(llbuild) else {
212-
throw InvalidToolchainDiagnostic("could not find `llbuild` at expected path \(llbuild)")
213-
}
214-
215-
216206
// We require xctest to exist on macOS.
217207
#if os(macOS)
218208
// FIXME: We should have some general utility to find tools.

0 commit comments

Comments
 (0)