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

Add hide-build flag to swift-run #6040

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion Sources/Commands/SwiftRunTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ struct RunToolOptions: ParsableArguments {
@Flag(name: .customLong("build-tests"), help: "Build both source and test targets")
var shouldBuildTests: Bool = false

/// If the build log should be hidden.
@Flag(name: .customLong("hide-build"), help: "Hides the build log and displays only the runtime log")
var shouldHideBuildLog: Bool = false

/// The executable product to run.
@Argument(help: "The executable to run", completion: .shellCommand("swift package completion-tool list-executables"))
var executable: String?
Expand Down Expand Up @@ -191,7 +195,10 @@ public struct SwiftRunTool: SwiftCommand {
}

do {
let buildSystem = try swiftTool.createBuildSystem(explicitProduct: options.executable)
let buildSystem = try swiftTool.createBuildSystem(
explicitProduct: options.executable,
customOutputStream: options.shouldHideBuildLog ? NullStream() : .none
)
let productName = try findProductName(in: buildSystem.getPackageGraph())
if options.shouldBuildTests {
try buildSystem.build(subset: .allIncludingTests)
Expand Down Expand Up @@ -301,3 +308,13 @@ private extension Basics.Diagnostic {
}
}

private final class NullStream: WritableByteStream {
var position: Int = 0

func write(_ byte: UInt8) {}

func write<C>(_ bytes: C) where C : Collection, C.Element == UInt8 {}

func flush() {}
}

9 changes: 9 additions & 0 deletions Tests/CommandsTests/RunToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ final class RunToolTests: CommandsTestCase {
}
}

func testHideBuildOption() throws {
try fixture(name: "Miscellaneous/FlatPackage") { fixturePath in
var (_, stderr) = try execute(["--hide-build"], packagePath: fixturePath)
XCTAssertNoMatch(stderr, .contains("[0/1] Planning build"))
XCTAssertNoMatch(stderr, .contains("Building for debugging..."))
XCTAssertNoMatch(stderr, .contains("Build complete!"))
}
}

func testMutualExclusiveFlags() throws {
try fixture(name: "Miscellaneous/EchoExecutable") { fixturePath in
XCTAssertThrowsCommandExecutionError(try execute(["--build-tests", "--skip-build"], packagePath: fixturePath)) { error in
Expand Down