Repository navigation
fix(dotnet): consume all MSBuild BuildEventArgsFieldFlags in binlog reader - #4620
Open
viniciusdsandrade wants to merge 4 commits into
Open
viniciusdsandrade wants to merge 4 commits into
viniciusdsandrade wants to merge 4 commits into
Conversation
…eader MSBuild's BuildEventArgsWriter serializes ThreadId, HelpKeyword, and SenderName between BuildEventContext and Timestamp when their flags are set, and serializes optional diagnostic location fields for message records before Arguments and Importance. When compiler tasks such as Csc emit warnings or errors with SenderName set, skipping those flags shifts subsequent stream reads by one field, causing RECORD_WARNING and RECORD_ERROR to read Code into File, ProjectFile index into Line, and Line into Column. Signed-off-by: Vinícius DS Andrade <[email protected]>
Add a unit test verifying that RECORD_WARNING and RECORD_ERROR preserve their code, file path, line, column, and message when optional base event flags (BuildEventContext, ThreadId, HelpKeyword, SenderName, Timestamp) are present. Signed-off-by: Vinícius DS Andrade <[email protected]>
📊 Automated PR Analysis
SummaryFixes the MSBuild binlog field parser in src/cmds/dotnet/binlog.rs to read all BuildEventArgsFieldFlags (ThreadId, HelpKeyword, SenderName, and diagnostic/location fields) in MSBuild's exact serialization order. Previously, events with SenderName set (e.g., from Csc) caused a byte offset that corrupted warning/error code, file, line, and column fields. Adds a unit test verifying correct parsing of such events. Review Checklist
Linked issues: #4587 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
cargo fmt --check failed on the aligned string-record comments in the test, which is a gate the project requires before merge. Formatting only, no behavior change.
read_event_fields also consumed the Subcategory..EndColumnNumber fields when their flag bits were set. Issue rtk-ai#4587 only needs ThreadId, HelpKeyword and SenderName read before Timestamp, and no test sets the diagnostic bits. The warning and error record already reads those same fields positionally right after read_event_fields, so a record that set the bits would have them consumed twice and shift every later read. The MSBuild writer could not be checked offline and the repository has no real binlog fixture, so leave the diagnostic fields out until a captured log backs them with a test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consume all MSBuild
BuildEventArgsFieldFlagsinread_event_fieldsin MSBuild's serialization order so structuredRECORD_WARNINGandRECORD_ERRORevents preserve their diagnostic code, file path, line, and column.Closes #4587
Context & Problem
In MSBuild's binary log format (
BuildEventArgsWriter.WriteBaseFields), base event fields are written in this order when theirBuildEventArgsFieldFlagsbits are set:Message(1 << 2): deduplicated stringBuildEventContext(1 << 0): 7 x 7-bit ints (6 in v1)ThreadId(1 << 4): 7-bit intHelpKeyword(1 << 1): deduplicated stringSenderName(1 << 3): deduplicated string (set wheneverSenderName != null && SenderName != "MSBuild", such as"Csc"for compiler warnings and errors)Timestamp(1 << 5):i64ticks (8 bytes LE) +DateTimeKind(7-bit int)Extended(1 << 16): extended type, dictionary, and extended commentFollowed by optional message diagnostic/location flags (
Subcategory,Code,File,ProjectFile,LineNumber,ColumnNumber,EndLineNumber,EndColumnNumber),Arguments, andImportance.src/cmds/dotnet/binlog.rsonly handledMessage,BuildEventContext,Timestamp,Extended,Arguments, andImportance. When a task such asCsclogged a warning or error withSenderName = "Csc",read_event_fieldsdid not read the 1-byteSenderNamestring index beforeTimestamp. As a result,Timestamp'sread_i64_le()+read_7bit_i32()consumedSenderName+ the 8-byteTicks(whose high byte is< 0x80), leavingTimestamp.Kindunread in the stream.Subsequent reads in
RECORD_ERROR | RECORD_WARNINGwere shifted by one field:_subcategoryreadTimestamp.KindcodereadSubcategory("")filereadCode(for example"CS0168")_project_filereadFile(for example"Beta.cs")lineread theProjectFilestring index (for example53)columnreadLineNumber(for example7)This produced corrupted warning output such as
CS0168(53,7): The variable 'unused' is declared...with the source file path lost.Solution
FLAG_*constants from MSBuild'sBuildEventArgsFieldFlagsinsrc/cmds/dotnet/binlog.rs.ThreadId,HelpKeyword,SenderName, and optional message diagnostic/location fields inread_event_fieldsin MSBuild's exact serialization order.test_parse_build_reads_events_with_sender_name_and_optional_flags) verifying thatRECORD_WARNINGandRECORD_ERRORevents withBuildEventContext,ThreadId,HelpKeyword,SenderName, andTimestampretain theircode,file,line,column, andmessage.How to Test
Verified by static code inspection against MSBuild's
BuildEventArgsFieldFlags/BuildEventArgsWriter/BuildEventArgsReaderandsrc/cmds/dotnet/binlog.rs; execution is delegated to the PR CI matrix:cargo test --lib cmds::dotnet::binlog::testsChecklist
cargo testpasses (pending CI execution; not run locally)cargo clippy --all-targetsclean (pending CI execution; not run locally)cargo fmt --checkclean (pending CI execution; not run locally)[\u{26a1} N tokens]badge (viaformat_badge()) (N/A: binlog parser bug fix)summary_footer()line (N/A: binlog parser bug fix)