-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support multiple binary logs from command line arguments #12706
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
base: main
Are you sure you want to change the base?
Conversation
- Added AdditionalFilePaths property to BinaryLogger to track multiple output destinations - Modified ProcessBinaryLogger to collect all distinct binlog paths from multiple -bl flags - Updated BinaryLogger.Shutdown to copy the binlog to all additional paths - Added ExtractFilePathFromParameters helper method to parse file paths from parameters - Added error message resource for copy failures Co-authored-by: baronfel <[email protected]>
- Added MultipleBinaryLogsCreatesMultipleFiles test to verify all specified binlog files are created - Added MultipleBinaryLogsWithDuplicatesCreateDistinctFiles test to verify duplicates are handled correctly - Both tests verify files are identical Co-authored-by: baronfel <[email protected]>
- Enhanced ProcessBinaryLogger to detect configuration differences - If all binlog options only differ in file paths, use optimized copy approach - If configurations differ (e.g., ProjectImports settings), create separate logger instances - Added ExtractNonPathParameters method to compare configurations - Added test for different configurations creating separate loggers - This approach respects all configuration options while optimizing when possible Co-authored-by: baronfel <[email protected]>
| /// Gets or sets additional output file paths. When set, the binlog will be copied to all these paths | ||
| /// after the build completes. The primary FilePath will be used as the temporary write location. | ||
| /// </summary> | ||
| public List<string> AdditionalFilePaths { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rainersigwald is this the binlog API that end-users end up using? If so we probably want to think about this exposed shape a bit more and force this stuff into 'normal 'logger parameter parsing instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added documentation clarifying this is for internal MSBuild use only. External code should create multiple logger instances instead. The property needs to remain public since it's accessed from the MSBuild assembly, but the remarks make it clear this isn't intended for general API use. (commit 0403ab7)
|
@copilot it's possible for the engine itself to create a binlog (see AppendDebuggingLoggers for where this can happen) - as part of this PR we should take this into account when we compute the optimal number of BinaryLogger class instances to create - if there is already a 'normal' binlog requested for the build when MSBUILDDEBUGENGINE is set, we should just be able to add the engine-generated binlog path to the set of paths to copy the final 'normal' binlog to. |
- Added remarks to AdditionalFilePaths clarifying it's for MSBuild command-line processing - Documented that external code should use multiple logger instances instead - Addressed feedback that this shouldn't be part of the public logger API surface Co-authored-by: baronfel <[email protected]>
The current implementation handles MSBUILDDEBUGENGINE correctly - when enabled, Optimizing this to add the debug path to an existing binlog's copy list would require:
Since MSBUILDDEBUGENGINE is a special debugging feature (not commonly used in production) and the current behavior (two independent loggers) is functionally correct, I've kept the implementation simple. If this optimization becomes important, we can revisit it as a follow-up enhancement. |
- Use LogMessage to log copy destinations before stream close - Throw LoggerException for copy errors (can't use LogMessage after stream close) - Move distinct paths processing logic to BinaryLogger.ProcessParameters() - Add ProcessedBinaryLoggerParameters class to encapsulate results - Simplify XMake.ProcessBinaryLogger() to use the new method Co-authored-by: YuliiaKovalova <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| additionalPath, | ||
| ex.Message); | ||
|
|
||
| throw new LoggerException(message, ex, errorCode, helpKeyword); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rainersigwald I am not sure how to handle it better - I some places I see Console.WriteLine usage, but it's not clear when we can use it?
- Replace hardcoded ".binlog" with BinlogFileExtension constant - Replace hardcoded "LogFile=" with LogFileParameterPrefix constant - Add XML documentation to TryInterpretPathParameterStatic method - Convert ProcessedBinaryLoggerParameters from class to readonly struct - Change AdditionalFilePaths and DistinctParameterSets to IReadOnlyList<string> Co-authored-by: YuliiaKovalova <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
When users specify the same binary log path multiple times, they will now see a message indicating which duplicate paths were ignored. This helps users identify potential mistakes in their command-line arguments. Co-authored-by: YuliiaKovalova <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request implements support for multiple binary log files when specified via command-line arguments (e.g., -bl:1.binlog -bl:2.binlog), addressing the issue where previously only the last-specified binlog was created. The implementation intelligently handles two scenarios: when all binlog configurations are identical (optimized with a single logger and file copying), and when configurations differ (creating separate logger instances).
Key Changes
- Smart parameter processing: New
BinaryLogger.ProcessParameters()method analyzes multiple-blflags, deduplicates paths, and determines whether configurations are identical - Optimized file copying: When configurations match, uses a single logger with post-build file copying to additional destinations for consistency and performance
- Duplicate path handling: Automatically filters duplicate paths and informs users via console output
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Build/Logging/BinaryLogger/BinaryLogger.cs | Core implementation: new ProcessParameters static method, AdditionalFilePaths property, file extraction/comparison methods, ProcessedBinaryLoggerParameters struct, and Shutdown method updates for file copying |
| src/MSBuild/XMake.cs | Command-line processing updates to call BinaryLogger.ProcessParameters() and create appropriate logger instances based on configuration analysis |
| src/MSBuild.UnitTests/XMake_Tests.cs | Three new test methods covering multiple binlogs with identical configs, duplicate path handling, and different configurations |
| src/Build/Resources/Strings.resx | New error message resource ErrorCopyingBinaryLog (MSB4279) for file copy failures |
| src/MSBuild/Resources/Strings.resx | New informational message DuplicateBinaryLoggerPathsIgnored for duplicate path warnings |
| src/Build/Resources/xlf/*.xlf | Localization files updated with new ErrorCopyingBinaryLog resource (marked as "new" state for translation) |
| src/MSBuild/Resources/xlf/*.xlf | Localization files updated with new DuplicateBinaryLoggerPathsIgnored resource (marked as "new" state for translation) |
| [Fact] | ||
| public void MultipleBinaryLogsCreatesMultipleFiles() | ||
| { | ||
| var testProject = _env.CreateFile("TestProject.proj", @" | ||
| <Project> | ||
| <Target Name=""Build""> | ||
| <Message Text=""Hello World!"" /> | ||
| </Target> | ||
| </Project> | ||
| "); | ||
|
|
||
| string binLogLocation = _env.DefaultTestDirectory.Path; | ||
| string binLog1 = Path.Combine(binLogLocation, "1.binlog"); | ||
| string binLog2 = Path.Combine(binLogLocation, "2.binlog"); | ||
| string binLog3 = Path.Combine(binLogLocation, "3.binlog"); | ||
|
|
||
| string output = RunnerUtilities.ExecMSBuild($"\"{testProject.Path}\" \"/bl:{binLog1}\" \"/bl:{binLog2}\" \"/bl:{binLog3}\"", out var success, _output); | ||
|
|
||
| success.ShouldBeTrue(output); | ||
|
|
||
| // Verify all three binlog files exist | ||
| File.Exists(binLog1).ShouldBeTrue("First binlog file should exist"); | ||
| File.Exists(binLog2).ShouldBeTrue("Second binlog file should exist"); | ||
| File.Exists(binLog3).ShouldBeTrue("Third binlog file should exist"); | ||
|
|
||
| // Verify all files have content (are not empty) | ||
| new FileInfo(binLog1).Length.ShouldBeGreaterThan(0, "First binlog should not be empty"); | ||
| new FileInfo(binLog2).Length.ShouldBeGreaterThan(0, "Second binlog should not be empty"); | ||
| new FileInfo(binLog3).Length.ShouldBeGreaterThan(0, "Third binlog should not be empty"); | ||
|
|
||
| // Verify all files are identical (have the same content) | ||
| byte[] file1Bytes = File.ReadAllBytes(binLog1); | ||
| byte[] file2Bytes = File.ReadAllBytes(binLog2); | ||
| byte[] file3Bytes = File.ReadAllBytes(binLog3); | ||
|
|
||
| file1Bytes.SequenceEqual(file2Bytes).ShouldBeTrue("First and second binlog should be identical"); | ||
| file1Bytes.SequenceEqual(file3Bytes).ShouldBeTrue("First and third binlog should be identical"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MultipleBinaryLogsWithDuplicatesCreateDistinctFiles() | ||
| { | ||
| var testProject = _env.CreateFile("TestProject.proj", @" | ||
| <Project> | ||
| <Target Name=""Build""> | ||
| <Message Text=""Hello World!"" /> | ||
| </Target> | ||
| </Project> | ||
| "); | ||
|
|
||
| string binLogLocation = _env.DefaultTestDirectory.Path; | ||
| string binLog1 = Path.Combine(binLogLocation, "1.binlog"); | ||
| string binLog2 = Path.Combine(binLogLocation, "2.binlog"); | ||
|
|
||
| // Specify binLog1 twice - should only create two distinct files | ||
| string output = RunnerUtilities.ExecMSBuild($"\"{testProject.Path}\" \"/bl:{binLog1}\" \"/bl:{binLog2}\" \"/bl:{binLog1}\"", out var success, _output); | ||
|
|
||
| success.ShouldBeTrue(output); | ||
|
|
||
| // Verify both binlog files exist | ||
| File.Exists(binLog1).ShouldBeTrue("First binlog file should exist"); | ||
| File.Exists(binLog2).ShouldBeTrue("Second binlog file should exist"); | ||
|
|
||
| // Verify both files are identical | ||
| byte[] file1Bytes = File.ReadAllBytes(binLog1); | ||
| byte[] file2Bytes = File.ReadAllBytes(binLog2); | ||
|
|
||
| file1Bytes.SequenceEqual(file2Bytes).ShouldBeTrue("Binlog files should be identical"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void MultipleBinaryLogsWithDifferentConfigurationsCreatesSeparateLoggers() | ||
| { | ||
| var testProject = _env.CreateFile("TestProject.proj", @" | ||
| <Project> | ||
| <Import Project=""Imported.proj"" /> | ||
| <Target Name=""Build""> | ||
| <Message Text=""Hello World!"" /> | ||
| </Target> | ||
| </Project> | ||
| "); | ||
|
|
||
| _env.CreateFile("Imported.proj", @" | ||
| <Project> | ||
| <PropertyGroup> | ||
| <TestProp>Value</TestProp> | ||
| </PropertyGroup> | ||
| </Project> | ||
| "); | ||
|
|
||
| string binLogLocation = _env.DefaultTestDirectory.Path; | ||
| string binLog1 = Path.Combine(binLogLocation, "with-imports.binlog"); | ||
| string binLog2 = Path.Combine(binLogLocation, "no-imports.binlog"); | ||
|
|
||
| // One with default imports, one with ProjectImports=None | ||
| string output = RunnerUtilities.ExecMSBuild($"\"{testProject.Path}\" \"/bl:{binLog1}\" \"/bl:{binLog2};ProjectImports=None\"", out var success, _output); | ||
|
|
||
| success.ShouldBeTrue(output); | ||
|
|
||
| // Verify both binlog files exist | ||
| File.Exists(binLog1).ShouldBeTrue("First binlog file should exist"); | ||
| File.Exists(binLog2).ShouldBeTrue("Second binlog file should exist"); | ||
|
|
||
| // Verify files are different sizes (one has imports embedded, one doesn't) | ||
| long size1 = new FileInfo(binLog1).Length; | ||
| long size2 = new FileInfo(binLog2).Length; | ||
|
|
||
| size1.ShouldBeGreaterThan(size2, "Binlog with imports should be larger than one without"); | ||
| } |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for the file copy error scenario. The Shutdown method can throw a LoggerException when file copying fails (lines 539-568), but none of the tests verify this error handling behavior.
Consider adding a test that:
- Sets up a scenario where copying would fail (e.g., invalid destination path, insufficient permissions, or locked file)
- Verifies that an appropriate exception is thrown with the correct error message
- Ensures the primary binlog file is still created successfully
| /// <summary> | ||
| /// Extracts the file path from binary logger parameters string. | ||
| /// This is a helper method for processing multiple binlog parameters. | ||
| /// </summary> | ||
| /// <param name="parameters">The parameters string (e.g., "output.binlog" or "output.binlog;ProjectImports=None")</param> | ||
| /// <returns>The resolved file path, or "msbuild.binlog" if no path is specified</returns> | ||
| public static string ExtractFilePathFromParameters(string parameters) | ||
| { | ||
| const string DefaultBinlogFileName = "msbuild" + BinlogFileExtension; | ||
|
|
||
| if (string.IsNullOrEmpty(parameters)) | ||
| { | ||
| return Path.GetFullPath(DefaultBinlogFileName); | ||
| } | ||
|
|
||
| var paramParts = parameters.Split(MSBuildConstants.SemicolonChar, StringSplitOptions.RemoveEmptyEntries); | ||
| string filePath = null; | ||
|
|
||
| foreach (var parameter in paramParts) | ||
| { | ||
| if (TryInterpretPathParameterStatic(parameter, out string extractedPath)) | ||
| { | ||
| filePath = extractedPath; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (filePath == null) | ||
| { | ||
| filePath = DefaultBinlogFileName; | ||
| } | ||
|
|
||
| try | ||
| { | ||
| return Path.GetFullPath(filePath); | ||
| } | ||
| catch | ||
| { | ||
| // If path resolution fails, return the original path | ||
| return filePath; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attempts to interpret a parameter string as a file path. | ||
| /// </summary> | ||
| /// <param name="parameter">The parameter to interpret (e.g., "LogFile=output.binlog" or "output.binlog")</param> | ||
| /// <param name="filePath">The extracted file path if the parameter is a path, otherwise the original parameter</param> | ||
| /// <returns>True if the parameter is a valid file path (ends with .binlog or contains wildcards), false otherwise</returns> | ||
| private static bool TryInterpretPathParameterStatic(string parameter, out string filePath) | ||
| { | ||
| bool hasPathPrefix = parameter.StartsWith(LogFileParameterPrefix, StringComparison.OrdinalIgnoreCase); | ||
|
|
||
| if (hasPathPrefix) | ||
| { | ||
| parameter = parameter.Substring(LogFileParameterPrefix.Length); | ||
| } | ||
|
|
||
| parameter = parameter.Trim('"'); | ||
|
|
||
| bool isWildcard = ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_12) && parameter.Contains("{}"); | ||
| bool hasProperExtension = parameter.EndsWith(BinlogFileExtension, StringComparison.OrdinalIgnoreCase); | ||
| filePath = parameter; | ||
|
|
||
| if (!isWildcard) | ||
| { | ||
| return hasProperExtension; | ||
| } | ||
|
|
||
| filePath = parameter.Replace("{}", ExpandPathParameter(string.Empty), StringComparison.Ordinal); | ||
|
|
||
| if (!hasProperExtension) | ||
| { | ||
| filePath += BinlogFileExtension; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Extracts the non-file-path parameters from binary logger parameters string. | ||
| /// This is used to compare configurations between multiple binlog parameters. | ||
| /// </summary> | ||
| /// <param name="parameters">The parameters string (e.g., "output.binlog;ProjectImports=None")</param> | ||
| /// <returns>A normalized string of non-path parameters, or empty string if only path parameters</returns> | ||
| public static string ExtractNonPathParameters(string parameters) | ||
| { | ||
| if (string.IsNullOrEmpty(parameters)) | ||
| { | ||
| return string.Empty; | ||
| } | ||
|
|
||
| var paramParts = parameters.Split(MSBuildConstants.SemicolonChar, StringSplitOptions.RemoveEmptyEntries); | ||
| var nonPathParams = new List<string>(); | ||
|
|
||
| foreach (var parameter in paramParts) | ||
| { | ||
| // Skip file path parameters | ||
| if (TryInterpretPathParameterStatic(parameter, out _)) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| // This is a configuration parameter (like ProjectImports=None, OmitInitialInfo, etc.) | ||
| nonPathParams.Add(parameter); | ||
| } | ||
|
|
||
| // Sort for consistent comparison | ||
| nonPathParams.Sort(StringComparer.OrdinalIgnoreCase); | ||
| return string.Join(";", nonPathParams); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Result of processing multiple binary logger parameter sets. | ||
| /// </summary> | ||
| public readonly struct ProcessedBinaryLoggerParameters | ||
| { | ||
| /// <summary> | ||
| /// List of distinct parameter sets that need separate logger instances. | ||
| /// </summary> | ||
| public IReadOnlyList<string> DistinctParameterSets { get; } | ||
|
|
||
| /// <summary> | ||
| /// If true, all parameter sets have identical configurations (only file paths differ), | ||
| /// so a single logger can be used with file copying for additional paths. | ||
| /// </summary> | ||
| public bool AllConfigurationsIdentical { get; } | ||
|
|
||
| /// <summary> | ||
| /// Additional file paths to copy the binlog to (only valid when AllConfigurationsIdentical is true). | ||
| /// </summary> | ||
| public IReadOnlyList<string> AdditionalFilePaths { get; } | ||
|
|
||
| /// <summary> | ||
| /// List of duplicate file paths that were filtered out. | ||
| /// </summary> | ||
| public IReadOnlyList<string> DuplicateFilePaths { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ProcessedBinaryLoggerParameters"/> struct. | ||
| /// </summary> | ||
| /// <param name="distinctParameterSets">List of distinct parameter sets that need separate logger instances.</param> | ||
| /// <param name="allConfigurationsIdentical">Whether all parameter sets have identical configurations.</param> | ||
| /// <param name="additionalFilePaths">Additional file paths to copy the binlog to.</param> | ||
| /// <param name="duplicateFilePaths">List of duplicate file paths that were filtered out.</param> | ||
| public ProcessedBinaryLoggerParameters( | ||
| IReadOnlyList<string> distinctParameterSets, | ||
| bool allConfigurationsIdentical, | ||
| IReadOnlyList<string> additionalFilePaths, | ||
| IReadOnlyList<string> duplicateFilePaths) | ||
| { | ||
| DistinctParameterSets = distinctParameterSets; | ||
| AllConfigurationsIdentical = allConfigurationsIdentical; | ||
| AdditionalFilePaths = additionalFilePaths; | ||
| DuplicateFilePaths = duplicateFilePaths; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Processes multiple binary logger parameter sets and returns distinct paths and configuration info. | ||
| /// </summary> | ||
| /// <param name="binaryLoggerParameters">Array of parameter strings from command line</param> | ||
| /// <returns>Processed result with distinct parameter sets and configuration info</returns> | ||
| public static ProcessedBinaryLoggerParameters ProcessParameters(string[] binaryLoggerParameters) | ||
| { | ||
| var distinctParameterSets = new List<string>(); | ||
| var additionalFilePaths = new List<string>(); | ||
| var duplicateFilePaths = new List<string>(); | ||
| bool allConfigurationsIdentical = true; | ||
|
|
||
| if (binaryLoggerParameters == null || binaryLoggerParameters.Length == 0) | ||
| { | ||
| return new ProcessedBinaryLoggerParameters(distinctParameterSets, allConfigurationsIdentical, additionalFilePaths, duplicateFilePaths); | ||
| } | ||
|
|
||
| if (binaryLoggerParameters.Length == 1) | ||
| { | ||
| distinctParameterSets.Add(binaryLoggerParameters[0]); | ||
| return new ProcessedBinaryLoggerParameters(distinctParameterSets, allConfigurationsIdentical, additionalFilePaths, duplicateFilePaths); | ||
| } | ||
|
|
||
| string primaryArguments = binaryLoggerParameters[0]; | ||
| string primaryNonPathParams = ExtractNonPathParameters(primaryArguments); | ||
|
|
||
| var distinctFilePaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
|
|
||
| // Check if all parameter sets have the same non-path configuration | ||
| for (int i = 0; i < binaryLoggerParameters.Length; i++) | ||
| { | ||
| string currentParams = binaryLoggerParameters[i]; | ||
| string currentNonPathParams = ExtractNonPathParameters(currentParams); | ||
| string currentFilePath = ExtractFilePathFromParameters(currentParams); | ||
|
|
||
| // Check if this is a duplicate file path | ||
| if (distinctFilePaths.Add(currentFilePath)) | ||
| { | ||
| if (!string.Equals(primaryNonPathParams, currentNonPathParams, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| allConfigurationsIdentical = false; | ||
| } | ||
| distinctParameterSets.Add(currentParams); | ||
| } | ||
| else | ||
| { | ||
| // Track duplicate paths for logging | ||
| duplicateFilePaths.Add(currentFilePath); | ||
| } | ||
| } | ||
|
|
||
| // If all configurations are identical, compute additional file paths for copying | ||
| if (allConfigurationsIdentical && distinctParameterSets.Count > 1) | ||
| { | ||
| for (int i = 1; i < distinctParameterSets.Count; i++) | ||
| { | ||
| additionalFilePaths.Add(ExtractFilePathFromParameters(distinctParameterSets[i])); | ||
| } | ||
| } | ||
|
|
||
| return new ProcessedBinaryLoggerParameters(distinctParameterSets, allConfigurationsIdentical, additionalFilePaths, duplicateFilePaths); | ||
| } |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage for the new public static methods ProcessParameters, ExtractFilePathFromParameters, and ExtractNonPathParameters in BinaryLogger. These are now part of the public API but have no direct unit tests in the BinaryLogger test suite.
While these methods are tested indirectly through the XMake integration tests, they should have dedicated unit tests to verify edge cases such as:
- Empty or null parameter arrays
- Parameters with wildcards
- Parameters with various configurations (ProjectImports, OmitInitialInfo, etc.)
- Invalid path formats
- Mixed valid and invalid parameters
This would provide better isolation and faster feedback when these methods have bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot add the tests suggested by your colleague
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added dedicated unit tests for all three public static methods: ExtractFilePathFromParameters, ExtractNonPathParameters, and ProcessParameters. Tests cover edge cases including null/empty inputs, various parameter formats, duplicate path handling (case-insensitive), and different configuration scenarios. (3f5e369)
| additionalPath, | ||
| ex.Message); | ||
|
|
||
| throw new LoggerException(message, ex, errorCode, helpKeyword); |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Log the error but don't fail the build" but the code immediately throws a LoggerException. This contradicts the comment and will actually fail the build.
If the intention is to fail the build on copy errors (which seems appropriate), update the comment to reflect this. If copy failures should not fail the build, remove the throw statement and consider logging the error in a different way (e.g., writing to stderr or a separate error collection).
| throw new LoggerException(message, ex, errorCode, helpKeyword); | |
| Console.Error.WriteLine(message); |
| foreach (var parameter in paramParts) | ||
| { | ||
| if (TryInterpretPathParameterStatic(parameter, out string extractedPath)) | ||
| { | ||
| filePath = extractedPath; | ||
| break; | ||
| } | ||
| } |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This foreach loop implicitly filters its target sequence - consider filtering the sequence explicitly using '.Where(...)'.
| foreach (string paramSet in processedParams.DistinctParameterSets) | ||
| { | ||
| BinaryLogger logger = new BinaryLogger { Parameters = paramSet }; | ||
| loggers.Add(logger); | ||
| } |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This foreach loop immediately maps its iteration variable to another variable - consider mapping the sequence explicitly using '.Select(...)'.
Added dedicated unit tests for the new public static methods: - ExtractFilePathFromParameters: Tests for null/empty input, various parameter formats, LogFile= prefix, and full path resolution - ExtractNonPathParameters: Tests for extracting and sorting configuration parameters - ProcessParameters: Tests for null/empty arrays, single parameter, multiple identical configs with optimization, different configs, duplicate path filtering (case-insensitive), and mixed scenarios with duplicates Co-authored-by: YuliiaKovalova <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
- Extract common path interpretation logic into TryInterpretPathParameterCore to eliminate duplication between TryInterpretPathParameter and TryInterpretPathParameterStatic - Store extracted file paths during first loop in ProcessParameters to avoid redundant ExtractFilePathFromParameters calls when computing additional paths - Both instance and static methods now call the shared core method with appropriate wildcard expander functions Co-authored-by: YuliiaKovalova <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Fixes #12705
Context
Today it's possible to provide the
-blflag multiple times, but the behavior of the engine is that the last-provided flag wins. This is confusing, and in extreme cases can mean that tools that need binlogs and provide them via things like response files can be overridden by a user's invocation. Tools like CodeQL have a harder time adopting binlog usage for C# code analysis because they can't control where the binlog is generated.Changes Made
Implemented support for writing multiple binlogs when supplied via command line arguments. The implementation intelligently handles two scenarios:
Same Configuration (Optimized): When all
-blflags have the same configuration (only file paths differ), a single BinaryLogger writes to one location and copies to additional destinations at build completion for consistency and performance.Different Configurations: When
-blflags have different configurations (e.g.,ProjectImports=NonevsProjectImports=Embed), separate BinaryLogger instances are created to respect each configuration.Key changes:
AdditionalFilePathsproperty to BinaryLogger (documented as internal-use only)BinaryLogger.ProcessParameters()static method to process multiple parameter sets and return distinct paths with configuration infoProcessedBinaryLoggerParametersreadonly struct to encapsulate the processing resultsShutdown()method to copy binlog to additional paths after stream closeLogMessageto log copy destinations before stream closeLoggerExceptionfor copy errors (stream is closed, can't use LogMessage)XMake.ProcessBinaryLogger()to use the new BinaryLogger.ProcessParameters() methodDuplicateFilePathsproperty to track and report duplicate pathsTryInterpretPathParametermethods to eliminate code duplication via shared core methodProcessParametersto avoid redundant path extraction callsTesting
ExtractFilePathFromParameters,ExtractNonPathParameters, andProcessParametersNotes
AdditionalFilePathsproperty is documented as internal-use only - external code should create multiple logger instances instead-blflags are automatically deduplicated - only the first occurrence is keptOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.