Skip to content
Open
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
11 changes: 9 additions & 2 deletions Sources/SkipDrive/GradleDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ public struct GradleDriver {
// java -Xmx64m -Xms64m -Dorg.gradle.appname=gradle -classpath /opt/homebrew/Cellar/gradle/8.0.2/libexec/lib/gradle-launcher-8.0.2.jar org.gradle.launcher.GradleMain info
#if DEBUG
// output the launch message in a format that makes it easy to copy and paste the result into the terminal
print("execGradle:", (gradleArgs + args).joined(separator: " "))
let skipQuiet = (ProcessInfo.processInfo.environment["SKIP_QUIET"] ?? "0") != "0"
if !skipQuiet {
print("execGradle:", (gradleArgs + args).joined(separator: " "))
}
#endif

return Process.streamLines(command: gradleArgs + args, environment: env, workingDirectory: workingDirectory, includeStdErr: true, onExit: onExit)
Expand All @@ -110,14 +113,15 @@ public struct GradleDriver {
/// - actions: the gradle actions to run, such as `["test"]`
/// - arguments: additional arguments to specify
/// - daemon: whether the enable the forking of a persistent gradle daemon that will make subsequent runs faster (e.g., 5 secs vs. 15 secs)
/// - warn: when `true` (and `quiet` is `false`), passes `--warn` to set Gradle log level to warnings and errors only
/// - failFast: whether to pass the "--fail-fast" flag
/// - continue: whether to permit failing tests to complete with the "--continue" flag
/// - offline: whether to pass the "--offline" flag
/// - rerunTasks: whether to pass the "--rerun-tasks" flag
/// - exitHandler: the exit handler, which may want to permit a process failure in order to have time to parse the tests
/// - Returns: an array of parsed test suites containing information about the test run
@available(macOS 13, macCatalyst 16, iOS 16, tvOS 16, watchOS 8, *)
public func launchGradleProcess(in workingDirectory: URL?, buildFolder: String = ".build", module: String?, actions: [String], arguments: [String], environment: [String: String] = ProcessInfo.processInfo.environmentWithDefaultToolPaths, daemon enableDaemon: Bool = true, info infoFlag: Bool = false, quiet quietFlag: Bool = false, plain plainFlag: Bool = true, maxMemory: UInt64? = nil, failFast failFastFlag: Bool = false, noBuildCache noBuildCacheFlag: Bool = false, continue continueFlag: Bool = false, offline offlineFlag: Bool = false, rerunTasks rerunTasksFlag: Bool = true, exitHandler: @escaping (ProcessResult) throws -> ()) async throws -> (output: AsyncLineOutput, result: () throws -> ParsedTestResults) {
public func launchGradleProcess(in workingDirectory: URL?, buildFolder: String = ".build", module: String?, actions: [String], arguments: [String], environment: [String: String] = ProcessInfo.processInfo.environmentWithDefaultToolPaths, daemon enableDaemon: Bool = true, info infoFlag: Bool = false, quiet quietFlag: Bool = false, warn warnFlag: Bool = false, plain plainFlag: Bool = true, maxMemory: UInt64? = nil, failFast failFastFlag: Bool = false, noBuildCache noBuildCacheFlag: Bool = false, continue continueFlag: Bool = false, offline offlineFlag: Bool = false, rerunTasks rerunTasksFlag: Bool = true, exitHandler: @escaping (ProcessResult) throws -> ()) async throws -> (output: AsyncLineOutput, result: () throws -> ParsedTestResults) {


var args = actions + arguments
Expand Down Expand Up @@ -179,6 +183,9 @@ public struct GradleDriver {

if quietFlag {
args += ["--quiet"]
} else if warnFlag {
// Log level WARN: errors and warnings only; less lifecycle noise than default (e.g. used with SKIP_QUIET when invoking Gradle from Xcode).
args += ["--warn"]
}

if plainFlag {
Expand Down
9 changes: 6 additions & 3 deletions Sources/SkipDrive/GradleHarness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,18 @@ extension GradleHarness {
public func gradleExec(in projectFolder: URL?, moduleName: String?, packageName: String?, arguments: [String]) async throws {
preprocessGradleArguments(in: projectFolder, arguments: arguments)

let skipQuiet = (ProcessInfo.processInfo.environment["SKIP_QUIET"] ?? "0") != "0"

let driver = try await GradleDriver()
let acts: [String] = [] // releaseBuild ? ["assembleRelease"] : ["assembleDebug"] // expected in the arguments to the command

var exitCode: ProcessResult.ExitStatus? = nil
let (output, _) = try await driver.launchGradleProcess(in: projectFolder, module: moduleName, actions: acts, arguments: arguments, environment: ProcessInfo.processInfo.environmentWithDefaultToolPaths, info: false, rerunTasks: false, exitHandler: { result in
print("note: Gradle \(result.resultDescription)")
let (output, _) = try await driver.launchGradleProcess(in: projectFolder, module: moduleName, actions: acts, arguments: arguments, environment: ProcessInfo.processInfo.environmentWithDefaultToolPaths, info: false, warn: skipQuiet, rerunTasks: false, exitHandler: { result in
if !skipQuiet {
print("note: Gradle \(result.resultDescription)")
}
exitCode = result.exitStatus
})

var lines: [String] = []
for try await pout in output {
let line = resolveSymlinksInXcodeIssueOutput(pout.line)
Expand Down
Loading