Skip to content

Fix --quiet option not working with swift run #8844 #8858

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MaelRB
Copy link

@MaelRB MaelRB commented Jun 22, 2025

Fixes an issue where the --quiet option had no effect when used with swift run and swift build command.

Motivation:

When using the --quiet option with swift run only error messages should be logged.

Modifications:

  • Add isQuiet property to filter out messages based on the log level during build phases of the native, xcode and swiftbuild build system.
  • Remove duplicated declaration of the isVerbose property from different targets.

Result:

When the --quiet option is used with the swift run and swift build command only error messages are logged.

Copy link
Contributor

@plemarquand plemarquand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for this! A few little nits, but nothing major.

@@ -242,6 +242,7 @@ final class LLBuildProgressTracker: LLBuildBuildSystemDelegate, SwiftCompilerOut

func commandStatusChanged(_ command: SPMLLBuild.Command, kind: CommandStatusKind) {
guard !self.logLevel.isVerbose else { return }
guard !self.logLevel.isQuiet else { return }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: roll this up into the guard above

}

public var isQuiet: Bool {
self == .error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just for symmetry with isVerbose

Suggested change
self == .error
self >= .error

@MaelRB MaelRB force-pushed the mrb/fix-quiet-run branch from 34eac3f to 2e3b66a Compare June 23, 2025 15:41
@plemarquand
Copy link
Contributor

@swift-ci please test

Copy link
Contributor

@bkhouri bkhouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. However, to ensure we do not regress, could I ask that you add a test for the for each SwiftPM executable, where appropriate?

Take a look in Tests/CommandsTests/*CommandTests.swift.

@MaelRB
Copy link
Author

MaelRB commented Jun 23, 2025

Thanks for this. However, to ensure we do not regress, could I ask that you add a test for the for each SwiftPM executable, where appropriate?

Take a look in Tests/CommandsTests/*CommandTests.swift.

Yes, sure! Thanks for the hint. I think I have an idea on how to do that properly.

@MaelRB MaelRB force-pushed the mrb/fix-quiet-run branch from 2e3b66a to 65918df Compare June 24, 2025 07:04
@MaelRB MaelRB requested a review from bkhouri June 24, 2025 07:04
@MaelRB
Copy link
Author

MaelRB commented Jun 24, 2025

@bkhouri I don't know how we should use fixtures folders. Should we have a unique folder per test or is it ok to reuse them ? Since test suites are serialized I went for the second option, there shouldn't be any concurrent access to fixtures folders causing flaky tests.

@bkhouri
Copy link
Contributor

bkhouri commented Jun 25, 2025

@bkhouri I don't know how we should use fixtures folders. Should we have a unique folder per test or is it ok to reuse them ? Since test suites are serialized I went for the second option, there shouldn't be any concurrent access to fixtures folders causing flaky tests.

@MaelRB : You can re-use fixtures were necessary :). When using the fixture(name: ...) function, it will copy the fixture to a temporary directory, so there is no "overlap".

@MaelRB MaelRB force-pushed the mrb/fix-quiet-run branch 3 times, most recently from f08fc37 to a023d6a Compare June 26, 2025 11:49
@MaelRB
Copy link
Author

MaelRB commented Jun 26, 2025

I've noticed an inconsistency on which output stream is used by a build system to raise the error when the build failed with the build command. SwiftBuild uses stderr but native and xcode use stdout. Is it the wanted behavior ?

From the swiftBuildQuietLogLevelWithError method:

if buildSystem == .swiftbuild {
   // THEN we should see output in stderr
   #expect(stderr.isEmpty == false)
   // AND no content in stdout
   #expect(stdout.isEmpty)
} else {
   // THEN we should see content in stdout
   #expect(stdout.isEmpty == false)
   // AND no output in stderr
   #expect(stderr.isEmpty)
}

The run command is consistent though

@MaelRB MaelRB force-pushed the mrb/fix-quiet-run branch from a023d6a to fe3573d Compare June 26, 2025 11:58
@MaelRB MaelRB requested a review from bkhouri June 26, 2025 11:59
@plemarquand
Copy link
Contributor

@swift-ci please test

@bkhouri
Copy link
Contributor

bkhouri commented Jun 26, 2025

I've noticed an inconsistency on which output stream is used by a build system to raise the error when the build failed with the build command. SwiftBuild uses stderr but native and xcode use stdout. Is it the wanted behavior ?

@MaelRB Please file an issue and we can looking into it :). Feel free to reference the test (and PR).

@MaelRB MaelRB force-pushed the mrb/fix-quiet-run branch from fe3573d to 9115c35 Compare June 26, 2025 15:47
@MaelRB MaelRB requested a review from bkhouri June 26, 2025 15:48
Copy link
Contributor

@bkhouri bkhouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you for adding tests and working through the comments. it's really appreciated

@bkhouri
Copy link
Contributor

bkhouri commented Jun 26, 2025

@swift-ci test

@bkhouri
Copy link
Contributor

bkhouri commented Jun 26, 2025

@MaelRB: You may need to rebase (or merge main) into your branch to pick the change that address the build failures.

@MaelRB MaelRB force-pushed the mrb/fix-quiet-run branch from 9115c35 to 0eeed67 Compare June 27, 2025 05:47
@plemarquand
Copy link
Contributor

@swift-ci please test

@MaelRB
Copy link
Author

MaelRB commented Jun 27, 2025

@bkhouri @plemarquand Should I wrap test cases within a withKnownIssue block to pass the CI ? Most of the tests in RunCommandTests and BuildCommandTests do that

@bkhouri
Copy link
Contributor

bkhouri commented Jun 27, 2025

@bkhouri @plemarquand Should I wrap test cases within a withKnownIssue block to pass the CI ? Most of the tests in RunCommandTests and BuildCommandTests do that

@MaelRB : if they are related to SwiftBuild, I would say you can mark them withKnownIssue, and try to include a .bug(...) trait on the test referring to the change that "should" address it.

Use the log level to determine whether a message should be log or not. If log level is error, log only error messages and ignore all other messages.
This fixes the issue for swift run command, and it benefits the swift build command as well.

Add a small refactoring to remove duplicated decleration of the isVerbose property from different targets.
@MaelRB MaelRB force-pushed the mrb/fix-quiet-run branch from 0eeed67 to 87cbdb8 Compare June 27, 2025 17:41
@MaelRB
Copy link
Author

MaelRB commented Jun 27, 2025

@bkhouri @plemarquand Should I wrap test cases within a withKnownIssue block to pass the CI ? Most of the tests in RunCommandTests and BuildCommandTests do that

@MaelRB : if they are related to SwiftBuild, I would say you can mark them withKnownIssue, and try to include a .bug(...) trait on the test referring to the change that "should" address it.

I marked two of the tests withKnownIssue. I couldn't link them to any known .bug(...) though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants