[bgen] Route output through IToolLog - #26612
rolfbjarne wants to merge 1 commit into
Conversation
Add an injectable bgen entry point while preserving standalone console behavior, diagnostic formatting, cancellation, and verbosity handling. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Four unresolved findings remain, including one critical process-termination issue and three moderate correctness or concurrency issues.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This pull request refactors bgen diagnostics and compiler execution around injected IToolLog, adding in-process BindingTouch.Run while preserving standalone CLI behavior.
Changes:
- Adds logger-aware execution with cancellation and custom HOME support.
- Routes diagnostics and compiler output through injected logging.
- Adds focused logging and cancellation tests.
Unresolved findings:
- Critical (3 votes) —
src/bgen/Generator.cs:1252: invalid selectors can terminate the host process. - Moderate (1 vote) —
src/bgen/BindingTouch.cs:401: cancellation is not checked during generation. - Moderate (1 vote) —
src/bgen/BindingTouch.cs:126: global warning state is unsafe for concurrent runs. - Moderate (1 vote) —
src/bgen/error.cs:176: warning details may be promoted to MSBuild errors.
File summaries
| File | Summary |
|---|---|
tools/common/IToolLog.cs |
Preserves standalone console routing. |
tools/common/Driver.execution.cs |
Adds cancellation-aware process execution. |
tests/bgen/LoggingTests.cs |
Tests logging, errors, and cancellation. |
src/bgen/Nomenclator.cs |
Routes nomenclator warnings through the logger. |
src/bgen/Generator.cs |
Uses injected logging for generator diagnostics. |
src/bgen/error.cs |
Routes diagnostics through IToolLog. |
src/bgen/BindingTouch.cs |
Adds in-process execution and cancellation handling. |
src/bgen/AttributeManager.cs |
Stores the diagnostic logger. |
Review details
Suppressed comments (3)
src/bgen/BindingTouch.cs:402
⚠️ bug — The token is checked immediately before and afterg.Go(), but not while generation runs. A cancellation requested during this synchronous traversal is therefore ignored until the entire generator finishes (and may then proceed to compilation), so the new in-process entry point cannot cancel promptly. Add cancellation checks within the generator's long-running traversal and cover cancellation during generation.
g.Go ();
ThrowIfCancellationRequested ();
src/bgen/BindingTouch.cs:126
- ❌ concurrency — Exposing
Runfor in-process callers makes concurrent invocations possible, but warning severity is still stored in the process-globalErrorHelper.warning_levelsdictionary:Main3clears it, option parsing mutates it, andBindingExceptionconstructors read it. Parallel MSBuild tasks can therefore overwrite or clear each other's--warnaserror/--nowarnsettings (and race on the dictionary), producing incorrect diagnostics. Keep warning state in the per-run context/logger or serializeRuninvocations.
public static int Run (string [] args, IToolLog log, CancellationToken cancellationToken, string? customHome)
src/bgen/error.cs:177
⚠️ bug — For a warning (error == false), this still sends the stack trace throughLogError. The injected MSBuild logger mapsIToolLog.LogError(string)toLog.LogError, so a verbose bgen warning is promoted to an MSBuild error and can fail the build. Route warning details throughlog.Logwhile retainingLogErrorfor actual errors.
if (log.Verbosity > 2 && e.StackTrace is not null)
log.LogError (e.StackTrace);
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
|
|
||
| if (export.Selector.IndexOfAny (invalid_selector_chars) != -1) { | ||
| Console.Error.WriteLine ("Export attribute contains invalid selector name: {0}", export.Selector); | ||
| BindingTouch.LogError ($"Export attribute contains invalid selector name: {export.Selector}"); |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
|
Superseded by #26615, which contains the rebased changes on a new branch because updating this PR's published branch would require a prohibited force-push. |
Refactor bgen diagnostics and normal output to use an injected
IToolLogwhile preserving standalone command-line behavior throughConsoleLog.This adds
BindingTouch.Run (string [] args, IToolLog log, CancellationToken cancellationToken)for in-process callers. It is preparatory work for #26590, which will pass theBGenMSBuild task as the logger when invoking bgen in-process.This PR is stacked on #26614, which removes bgen's source compilation and subprocess execution support. The change preserves bgen warning/error formatting, verbosity handling, exit codes, unexpected-exception reporting, cancellation behavior, and help output. Focused tests cover
ConsoleLog, injected normal/warning/error output, BI0000 errors, and cancellation.🤖 Pull request created by Copilot