Skip to content

Conversation

@euanh
Copy link
Contributor

@euanh euanh commented Jan 16, 2024

This change adds a 'progress' message to the diagnostics which a plugin can send back to SwiftPM. This message is printed to standard error at the default verbosity level.

Motivation:

Currently, a plugin can write output to standard output or send diagnostics which SwiftPM writes to standard error. If the plugin spawns long-running operations we might want to print progress messages to let the user know that it is still running. The existing options all have compromises:

  • Anything the plugin prints to its standard output or standard error is echoed to SwiftPM's standard output, but we may want to keep progress information separate from other plugin outputs - the plugin might be called as part of a shell pipeline where a downstream process will consume its output, for example.
  • The existing diagnostic messages - remark (info), warning and error - are all suppressed at the default verbosity level.
  • Increasing the level with -v causes SwiftPM to print lots of extra logging information from the build, which swamps the plugin info messages.

This commit adds a 'progress' message which SwiftPM will print to standard error at the default verbosity level, allowing progress to be shown without polluting standard output or pulling in additional build logging which might not be relevant to the user.

Modifications:

  • Diagnostics.progress takes a message as a string and passes it to SwiftPM, which prints it to standard error.

From the plugin programmer's point of view Diagnostics.progress is logically a diagnostics message, however it is a new type in the SwiftPM <-> plugin protocol because extending the existing diagnostics enum would require extensive changes to add a the new message and in many existing cases it would not be relevant.

Result:

A plugin can show the user that it is making progress by printing messages which SwiftPM will echoed to stderr at the default verbosity level.

Example output (diagnostics-stub is the name of the plugin in Package.swift):

% swift-package print-diagnostics progress
[diagnostics-stub] command plugin: Diagnostics.progress



/// The plugin emits a progress message.
case emitProgress(message: String)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be extended in future with progress bars or n/m completed prefixes.

}


func pluginEmittedProgress(_ message: String) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not clear what is the best option here. Could append to outputData or add a progress array field similar to diagnostics below.

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Overall LGTM, but this needs @neonichu's approval before merging.

@MaxDesiatov
Copy link
Contributor

@swift-ci test

@euanh euanh force-pushed the plugin-diagnostics-add-progress branch from 2389346 to 4ec32b8 Compare January 18, 2024 13:34
@euanh
Copy link
Contributor Author

euanh commented Jan 18, 2024

Rebased on top of #7262

…sity

This change adds a 'progress' message to the diagnostics which a plugin can send back to SwiftPM.   This message is printed to standard error at the default verbosity level.

 ### Motivation:

Currently, a plugin can write output to standard output or send diagnostics which SwiftPM writes to standard error.   If the plugin spawns long-running operations we might want to print progress messages to let the user know that it is still running.   The existing options all have compromises:

* Anything the plugin prints to its standard output or standard error is echoed to SwiftPM's standard output, but we may want to keep progress information separate from other plugin outputs - the plugin might be called as part of a shell pipeline where a downstream process will consume its output, for example.
* The existing diagnostic messages - remark (info), warning and error - are all suppressed at the default verbosity level.
* Increasing the level with `-v` causes SwiftPM to print lots of extra logging information from the build, which swamps the plugin info messages.

This commit adds a 'progress' message which SwiftPM will print to standard error at the default verbosity level, allowing progress to be shown without polluting standard output or pulling in additional build logging which might not be relevant to the user.

 ### Modifications:

* `Diagnostics.progress` takes a message as a string and passes it to SwiftPM, which prints it to standard error.

From the plugin programmer's point of view `Diagnostics.progress` is logically a diagnostics message, however it is a new type in the SwiftPM <-> plugin protocol because extending the existing diagnostics enum would require extensive changes to add a the new message and in many existing cases it would not be relevant.

 ### Result:

A plugin can show the user that it is making progress by printing messages which SwiftPM will echoed to stderr at the default verbosity level.
@euanh euanh force-pushed the plugin-diagnostics-add-progress branch from 4ec32b8 to eb0a203 Compare January 18, 2024 16:25
@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 d0c576a into swiftlang:main Jan 25, 2024
@euanh euanh deleted the plugin-diagnostics-add-progress branch January 26, 2024 09:03
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