Skip to content

command plugins: Optionally print build logs during packageManager.build #7255

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

Merged

Conversation

euanh
Copy link
Contributor

@euanh euanh commented Jan 15, 2024

This commit adds the option for a build run on behalf of a command plugin to echo logs to the console as they are produced, in addition to the current behaviour of accumulating them in a buffer. Console echoing is turned off by default.

Motivation:

When a plugin asks for a target to be built by calling packageManager.build, SwiftPM accumulates the build log in a buffer and returns the whole log when the build completes. No feedback is printed on the console while the build is running, so if the target is large the user can't tell whether the build is making progress or is stuck.

Modifications:

  • Added TeeOutputByteStream, an OutputByteStream which copies its inputs to a set of output streams
  • Added an echoLogs parameter to packageManager.build, defaulting to false to match the current behaviour.
  • Added a test to verify that logs are echoed and the existing log accumulation continues to work.

Result:

A command plugin can ask for build outputs to be echoed as they are produced. The user will have some feedback that a build is happening, rather than the long pause which can happen now.

This change depends on #7254.

@MaxDesiatov MaxDesiatov self-assigned this Jan 15, 2024
}

var position: Int {
return 0 // should be related to the downstreams somehow
Copy link
Contributor Author

@euanh euanh Jan 15, 2024

Choose a reason for hiding this comment

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

What should 'position' return here? The downstreams might all be at different positions. Should this be the number of bytes which have been passed to write, or should it be related to positions of the downstreams?

Copy link
Contributor

Choose a reason for hiding this comment

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

IDK, the doc comment for that protocol says it's "The current offset within the output stream", if that helps in any way.

@euanh euanh force-pushed the plugin-diagnostics-echo-build-logs branch 3 times, most recently from 4cd3d67 to ff7a6a0 Compare January 15, 2024 13:21
@MaxDesiatov
Copy link
Contributor

@swift-ci test

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

@euanh
Copy link
Contributor Author

euanh commented Jan 16, 2024

The Windows test failure doesn't immediately look like it's related to this change:

FAIL: Swift(windows-x86_64) :: Driver/linker-clang_rt.swift (1 of 10252)
******************** TEST 'Swift(windows-x86_64) :: Driver/linker-clang_rt.swift' FAILED ********************
...
Exit Code: 1

Command Output (stdout):
--
$ ":" "RUN: at line 7"
$ "rm" "-rf" "T:\1\tools\swift\test-windows-x86_64\Driver\Output\linker-clang_rt.swift.tmp"
# command stderr:
Error: 'rm' command failed, [WinError 32] The process cannot access the file because it is being used by another process.
error: command failed with exit status: 1

--

@MaxDesiatov
Copy link
Contributor

Yeah, that failure looks like something caused by Windows builds not running in complete isolation from each other 😕

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

When a plugin asks for a target to be built by calling
packageManager.build, SwiftPM accumulates the build log in a buffer
and returns the whole log when the build completes.   No feedback
is printed on the console while the build is running, so if the
target is large the user can't tell whether the build is making
progress or is stuck.

This commit adds the option to echo logs to the console as they are
produced, in addition to accumulating them in a buffer.   Console
echoing is turned off by default.
@euanh euanh force-pushed the plugin-diagnostics-echo-build-logs branch from 56a5b02 to 35e5c1b Compare January 18, 2024 16:33
@MaxDesiatov
Copy link
Contributor

@swift-ci test

@euanh
Copy link
Contributor Author

euanh commented Jan 23, 2024

@swift-ci test windows

@MaxDesiatov MaxDesiatov merged commit 6a7db24 into swiftlang:main Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants