From 83a97d05a5e02af24ad0e418d83b27840cdd8c14 Mon Sep 17 00:00:00 2001 From: Kirill Osenkov Date: Tue, 19 Dec 2023 14:13:11 -0800 Subject: [PATCH] Initialize strings when reading binlog records Fixes #736 --- src/BinlogTool/BinlogTool.csproj | 2 +- .../BuildEventArgsReader.Viewer.cs | 23 +++++++++++++++++++ .../BinaryLogger/BuildEventArgsReader.cs | 6 ++++- .../Construction/Construction.cs | 16 ------------- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/BinlogTool/BinlogTool.csproj b/src/BinlogTool/BinlogTool.csproj index 8e66a7f9..7d62243b 100644 --- a/src/BinlogTool/BinlogTool.csproj +++ b/src/BinlogTool/BinlogTool.csproj @@ -2,7 +2,7 @@ Exe - 1.0.8 + 1.0.9 net7.0 major latest diff --git a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.Viewer.cs b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.Viewer.cs index 8a2017f3..b3fa93ce 100644 --- a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.Viewer.cs +++ b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.Viewer.cs @@ -98,6 +98,29 @@ private BuildEventArgs SynthesizePropertyReassignment(BuildEventArgsFields field return e; } + private bool sawCulture; + + private void OnMessageRead(BuildMessageEventArgs args) + { + if (sawCulture) + { + return; + } + + if (args.SenderName == "BinaryLogger" && + args.Message is string message && + message.StartsWith("CurrentUICulture", StringComparison.Ordinal)) + { + sawCulture = true; + var kvp = TextUtilities.ParseNameValue(message); + string culture = kvp.Value; + if (!string.IsNullOrEmpty(culture)) + { + Strings.Initialize(culture); + } + } + } + private string GetTargetStartedMessage(string projectFile, string targetFile, string parentTarget, string targetName) { if (string.Equals(projectFile, targetFile, StringComparison.OrdinalIgnoreCase)) diff --git a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs index 8999bee5..97809d8a 100644 --- a/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs +++ b/src/StructuredLogger/BinaryLogger/BuildEventArgsReader.cs @@ -898,7 +898,7 @@ private BuildEventArgs ReadBuildMessageEventArgs() return SynthesizePropertyReassignment(fields); } - e = new BuildMessageEventArgs( + var buildMessageEventArgs = new BuildMessageEventArgs( fields.Subcategory, fields.Code, fields.File, @@ -915,6 +915,10 @@ private BuildEventArgs ReadBuildMessageEventArgs() { ProjectFile = fields.ProjectFile, }; + + e = buildMessageEventArgs; + + OnMessageRead(buildMessageEventArgs); } else { diff --git a/src/StructuredLogger/Construction/Construction.cs b/src/StructuredLogger/Construction/Construction.cs index 9f6cc20e..9b0c4ec2 100644 --- a/src/StructuredLogger/Construction/Construction.cs +++ b/src/StructuredLogger/Construction/Construction.cs @@ -464,8 +464,6 @@ public void TaskFinished(object sender, TaskFinishedEventArgs args) } } - private bool sawCulture = false; - public void MessageRaised(object sender, BuildMessageEventArgs args) { try @@ -478,20 +476,6 @@ public void MessageRaised(object sender, BuildMessageEventArgs args) return; } - if (!sawCulture && - args.SenderName == "BinaryLogger" && - args.Message is string message && - message.StartsWith("CurrentUICulture", StringComparison.Ordinal)) - { - sawCulture = true; - var kvp = TextUtilities.ParseNameValue(message); - string culture = kvp.Value; - if (!string.IsNullOrEmpty(culture)) - { - Strings.Initialize(culture); - } - } - messageProcessor.Process(args); } }