From 574d1178e9e20482fbdc918ffac7c24ce5fa42c5 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Thu, 13 Aug 2026 10:50:00 -0500 Subject: [PATCH] [build] Remove obsolete build tools Remove the unused MSBuild fuzzer and the retired plot-to-Application-Insights uploader, including the orphaned CSV plot input task. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../plots-to-appinsights/AppInsights.cs | 35 -- .../ProcessPlotCSVFile.csproj | 16 - .../ProcessPlotCSVFile.sln | 25 -- build-tools/plots-to-appinsights/Program.cs | 343 ------------------ build-tools/plots-to-appinsights/Result.cs | 17 - build-tools/plots-to-appinsights/Settings.cs | 152 -------- .../ProcessPlotInput.cs | 153 -------- tools/msbuild-fuzzer/Program.cs | 317 ---------------- tools/msbuild-fuzzer/msbuild-fuzzer.csproj | 14 - tools/msbuild-fuzzer/msbuild-fuzzer.sln | 31 -- 10 files changed, 1103 deletions(-) delete mode 100644 build-tools/plots-to-appinsights/AppInsights.cs delete mode 100644 build-tools/plots-to-appinsights/ProcessPlotCSVFile.csproj delete mode 100644 build-tools/plots-to-appinsights/ProcessPlotCSVFile.sln delete mode 100644 build-tools/plots-to-appinsights/Program.cs delete mode 100644 build-tools/plots-to-appinsights/Result.cs delete mode 100644 build-tools/plots-to-appinsights/Settings.cs delete mode 100644 build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/ProcessPlotInput.cs delete mode 100644 tools/msbuild-fuzzer/Program.cs delete mode 100644 tools/msbuild-fuzzer/msbuild-fuzzer.csproj delete mode 100644 tools/msbuild-fuzzer/msbuild-fuzzer.sln diff --git a/build-tools/plots-to-appinsights/AppInsights.cs b/build-tools/plots-to-appinsights/AppInsights.cs deleted file mode 100644 index 7d445d511a3..00000000000 --- a/build-tools/plots-to-appinsights/AppInsights.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Microsoft.ApplicationInsights; -using Microsoft.ApplicationInsights.Extensibility; -using System; -using System.Collections.Generic; - -namespace Xamarin.Android.Tools.Plots -{ - internal class AppInsights - { - private TelemetryClient TelemetryClient; - - public AppInsights (string appInsightsInstrumentationKey) - { - if (string.IsNullOrEmpty (appInsightsInstrumentationKey)) { - throw new ArgumentNullException (nameof (appInsightsInstrumentationKey)); - } - - // https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring#log-custom-telemetry-in-c-functions - var telemetryConfiguration = new TelemetryConfiguration (appInsightsInstrumentationKey); - TelemetryClient = new TelemetryClient (telemetryConfiguration) // Note: Direct creation of the TelemetryClient using the default constructor has been deprecated. Use dependency injection instead. - { - InstrumentationKey = appInsightsInstrumentationKey - }; - } - - public void SendTelemetry (string eventName, Dictionary properties, Dictionary metrics) - { - lock (TelemetryClient) { - TelemetryClient.TrackEvent (eventName, properties, metrics); - } - } - - public void Flush () => TelemetryClient.Flush (); - } -} diff --git a/build-tools/plots-to-appinsights/ProcessPlotCSVFile.csproj b/build-tools/plots-to-appinsights/ProcessPlotCSVFile.csproj deleted file mode 100644 index 158d8837964..00000000000 --- a/build-tools/plots-to-appinsights/ProcessPlotCSVFile.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Exe - $(DotNetStableTargetFramework) - false - Xamarin.Android.Tools.Plots - - - - - - - - diff --git a/build-tools/plots-to-appinsights/ProcessPlotCSVFile.sln b/build-tools/plots-to-appinsights/ProcessPlotCSVFile.sln deleted file mode 100644 index 4f1fdb9d85b..00000000000 --- a/build-tools/plots-to-appinsights/ProcessPlotCSVFile.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30002.166 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProcessPlotCSVFile", "ProcessPlotCSVFile.csproj", "{6374A2BB-2212-4891-AB0C-028D866C5CE6}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {6374A2BB-2212-4891-AB0C-028D866C5CE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6374A2BB-2212-4891-AB0C-028D866C5CE6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6374A2BB-2212-4891-AB0C-028D866C5CE6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6374A2BB-2212-4891-AB0C-028D866C5CE6}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {FB3F2614-E0B7-45D1-A79B-16DB9444431F} - EndGlobalSection -EndGlobal diff --git a/build-tools/plots-to-appinsights/Program.cs b/build-tools/plots-to-appinsights/Program.cs deleted file mode 100644 index cb757223495..00000000000 --- a/build-tools/plots-to-appinsights/Program.cs +++ /dev/null @@ -1,343 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Collections.Generic; - -namespace Xamarin.Android.Tools.Plots -{ - internal static class Constants - { - public const string AzureTimestampFormatUtc = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; - public const string TelemetryEventName = "xamarin-android.plot"; - public const string TelemetryEventName_Warning = "xamarin-android.plot.warning"; - public const string TelemetryEventName_Error = "xamarin-android.plot.error"; - } - - class Program - { - static int Main (string [] args) - { - var retCode = 0; - var errMessage = string.Empty; - var settings = new Settings (); - - try { - var currentUtcTime = DateTime.UtcNow; - - var result = settings.ProcessArgs (args); - - if (settings.BuildDateUtc.Equals (default)) { - settings.BuildDateUtc = currentUtcTime; - } - - settings.Display (Console.Out); - - if (!string.IsNullOrEmpty (result.Message)) { - Console.WriteLine (result.Message); - Console.WriteLine (); - } else if (!File.Exists (settings.CsvPathAndFilename)) { - var message = $"CSV file '{settings.CsvPathAndFilename}' does not exist"; - Console.WriteLine ($"ERROR: {message}"); - Console.WriteLine (); - result.Status = Status.CsvFileDoesNotExist; - - var appInsightsClientError = new AppInsights (settings.AppInsightsTelemetryKey); - var eventNameError = GetEventName (settings.Environment, Constants.TelemetryEventName_Error); - SendTelemetryError (appInsightsClientError, eventNameError, message, settings, Console.Out); - appInsightsClientError.Flush (); - } - - if (result.Status != Status.OK) { - Console.WriteLine ("ProcessPlotCSVFile [OPTIONS] PlotFilename.csv"); - Console.WriteLine (); - Console.WriteLine ("Options:"); - settings.Options.WriteOptionDescriptions (Console.Out); - Console.WriteLine (); - return 1; - } - - var plots = ProcessCSVFile (settings.CsvPathAndFilename, out var warningMessages, Console.Out); - - var appInsightsClient = new AppInsights (settings.AppInsightsTelemetryKey); - var eventName = GetEventName (settings.Environment, Constants.TelemetryEventName); - - Console.WriteLine ($"Sending telemetry. Event name: {eventName} / number of plots: {plots.Count ()}"); - SendTelemtry (appInsightsClient, eventName, plots, settings, Console.Out); - appInsightsClient.Flush (); - - var eventNameWarning = GetEventName (settings.Environment, Constants.TelemetryEventName_Warning); - SendTelemetryWarnings (appInsightsClient, eventNameWarning, warningMessages, settings, Console.Out); - appInsightsClient.Flush (); - - } catch (Exception e) { - errMessage = e.Message; - Console.WriteLine ($"EXCEPTION: {errMessage}"); - Console.WriteLine (e.StackTrace); - retCode = 2; - } - - try { - if (!string.IsNullOrEmpty (errMessage)) { - var appInsightsClient = new AppInsights (settings.AppInsightsTelemetryKey); - var eventNameError = GetEventName (settings.Environment, Constants.TelemetryEventName_Error); - - SendTelemetryError (appInsightsClient, eventNameError, errMessage, settings, Console.Out); - appInsightsClient.Flush (); - } - } catch (Exception e) { - Console.WriteLine ($"EXCEPTION: Sending error telemetry: {e.Message}"); - Console.WriteLine (e.StackTrace); - retCode = 3; - } - - return retCode; - } - - static Dictionary ProcessCSVFile (string csvPathAndFilename, out List warningMessages, TextWriter tw) - { - warningMessages = new List (); - - if (string.IsNullOrEmpty (csvPathAndFilename)) { - throw new ArgumentNullException (nameof (csvPathAndFilename)); - } - - if (!File.Exists (csvPathAndFilename)) { - throw new FileNotFoundException (csvPathAndFilename); - } - - if (tw == null) { - throw new ArgumentNullException (nameof (tw)); - } - - var plots = new Dictionary (StringComparer.OrdinalIgnoreCase); - - var lines = File.ReadAllLines (csvPathAndFilename); - lines = lines.Where (line => !string.IsNullOrWhiteSpace (line)).ToArray (); // Remove any empty lines - var duplicateLabelsHavingDifferentValues = new List (); - if (lines.Length == 2) { - var labels = lines [0].Split (new [] { ',' }); - var values = lines [1].Split (new [] { ',' }); - - if (labels.Length == values.Length) { - var index = 0; - foreach (var label in labels) { - if (decimal.TryParse (values [index], out var value)) { - if (plots.TryGetValue (label, out var existingValue)) { - var csvFilename = Path.GetFileName (csvPathAndFilename); - var warningMessage = $"The plot file contains a duplicate plot for '{label}'. value1: {existingValue} / value2: {value}. File: {csvFilename}"; - warningMessages.Add (warningMessage); - tw.WriteLine ($"WARNING: {nameof (ProcessCSVFile)}: {warningMessage}"); - - if (value != existingValue) { - tw.WriteLine ($"ERROR: {nameof (ProcessCSVFile)}: The duplicate plots have different values. value1: {existingValue} / value2: {value}. File: {csvFilename}"); - duplicateLabelsHavingDifferentValues.Add (label); // This will result in an exception being thrown - } - } else { - plots [label] = value; // The CSV file might contain redundant information - } - } else { - throw new Exception ($"{nameof (ProcessCSVFile)}: Failed to parse the value '{values [index]}' for the {label} label in 0-based column {index}. Expecting a numeric value"); - } - index++; - } - - if (duplicateLabelsHavingDifferentValues.Any ()) { - var distinctLabels = duplicateLabelsHavingDifferentValues.Distinct (); - throw new Exception ($"{nameof (ProcessCSVFile)}: Duplicate plot labels having different values: {string.Join (",", distinctLabels)}"); - } - } else { - throw new Exception ($"{nameof (ProcessCSVFile)}: Mismatch between plot labels (line 1) and values (line 2). Count of labels and values should be identical. Number of labels: {labels.Length} / number of values: {values.Length}"); - } - } else { - throw new Exception ($"{nameof (ProcessCSVFile)}: Plot CSV file is expected to have two lines. First line should include the comma-delimited labels where the second line should include the comma-limited values. Instead the CSV file has {lines.Length} line(s)"); - } - - return plots; - } - - static string GetEventName (string environment, string eventName) - { - if (string.IsNullOrEmpty (eventName)) { - throw new ArgumentNullException (nameof (eventName)); - } - - if (string.IsNullOrEmpty (environment)) { - environment = "Dev"; - } - - if (!environment.Equals ("Production", StringComparison.OrdinalIgnoreCase)) { - eventName = $"{eventName}.{environment.ToLowerInvariant ()}"; - } - - return eventName; - } - - static Dictionary GetBaseTelemetryProperties (Settings settings) - { - if (settings == null) { - throw new ArgumentNullException (nameof (settings)); - } - - var schemaVersion = "1.0"; - var sessionTimestamp = DateTime.UtcNow.ToString (Constants.AzureTimestampFormatUtc); - - var properties = new Dictionary (StringComparer.OrdinalIgnoreCase) { - { "Version", schemaVersion }, - { "Environment", settings.Environment }, - { "SessionTimestamp", sessionTimestamp }, - { "BuildSystem", settings.BuildSystem }, - { "BuildPipeline", settings.BuildPipelineName }, - { "BuildType", settings.BuildType }, - { "BuildId", settings.BuildId }, - { "BuildNumber", settings.BuildNumber }, - { "BuildUrl", settings.BuildUrl }, - { "BuildDate", settings.BuildDateUtc.ToString(Constants.AzureTimestampFormatUtc) }, - { "Filename", Path.GetFileName(settings.CsvPathAndFilename) }, - { "Title", settings.PlotTitle }, - { "Group", settings.PlotGroup } - }; - - return properties; - } - - static void SendTelemtry (AppInsights appInsightsClient, string eventName, Dictionary plots, Settings settings, TextWriter tw) - { - if (appInsightsClient == null) { - throw new ArgumentNullException (nameof (appInsightsClient)); - } - - if (string.IsNullOrEmpty (eventName)) { - throw new ArgumentNullException (nameof (eventName)); - } - - if (plots == null || !plots.Any()) { - throw new ArgumentNullException (nameof (plots)); - } - - if (settings == null) { - throw new ArgumentNullException (nameof (settings)); - } - - if (tw == null) { - throw new ArgumentNullException (nameof (tw)); - } - - var ctPlot = 0; - foreach (var plot in plots) { - - var properties = GetBaseTelemetryProperties (settings); - var plotProperties = new Dictionary (StringComparer.OrdinalIgnoreCase) { - { "SeriesLabel", plot.Key } - }; - - // Add plot information to the properties dictionary - plotProperties.ToList ().ForEach (x => properties [x.Key] = x.Value); - - var metrics = new Dictionary (StringComparer.OrdinalIgnoreCase) { - { "Value", (double) plot.Value } - }; - - appInsightsClient.SendTelemetry (eventName, properties, metrics); - - ctPlot++; - tw.WriteLine ($"Telemetry sent: Plot {ctPlot}"); - tw.WriteLine ($" Event name: {eventName}"); - tw.WriteLine (" Properties:"); - foreach (var property in properties.OrderBy (x => x.Key)) { - tw.WriteLine ($" {property.Key}: {property.Value}"); - } - - tw.WriteLine (" Metrics:"); - foreach (var metric in metrics.OrderBy (x => x.Key)) { - tw.WriteLine ($" {metric.Key}: {metric.Value}"); - } - } - } - - static void SendTelemetryWarnings (AppInsights appInsightsClient, string eventName, List warnings, Settings settings, TextWriter tw) - { - if (appInsightsClient == null) { - throw new ArgumentNullException (nameof (appInsightsClient)); - } - - if (string.IsNullOrEmpty (eventName)) { - throw new ArgumentNullException (nameof (eventName)); - } - - if (warnings == null) { // Note: It's okay if warnings is empty - throw new ArgumentNullException (nameof (warnings)); - } - - if (settings == null) { - throw new ArgumentNullException (nameof (settings)); - } - - if (tw == null) { - throw new ArgumentNullException (nameof (tw)); - } - - foreach (var warning in warnings) { - var properties = GetBaseTelemetryProperties (settings); - var warningProperties = new Dictionary (StringComparer.OrdinalIgnoreCase) { - { "Message", warning } - }; - - // Add warning to the properties dictionary - warningProperties.ToList ().ForEach (x => properties [x.Key] = x.Value); - - var metrics = new Dictionary (StringComparer.OrdinalIgnoreCase); - - appInsightsClient.SendTelemetry (eventName, properties, metrics); - - tw.WriteLine ($"Telemetry sent: Warning: {warning}"); - tw.WriteLine ($" Event name: {eventName}"); - tw.WriteLine (" Properties:"); - foreach (var property in properties.OrderBy (x => x.Key)) { - tw.WriteLine ($" {property.Key}: {property.Value}"); - } - } - } - - static void SendTelemetryError (AppInsights appInsightsClient, string eventName, string errMessage, Settings settings, TextWriter tw) - { - if (appInsightsClient == null) { - throw new ArgumentNullException (nameof (appInsightsClient)); - } - - if (string.IsNullOrEmpty(eventName)) { - throw new ArgumentNullException (nameof (eventName)); - } - - if (string.IsNullOrEmpty(errMessage)) { - throw new ArgumentNullException (nameof (errMessage)); - } - - if (settings == null) { - throw new ArgumentNullException (nameof (settings)); - } - - if (tw == null) { - throw new ArgumentNullException (nameof(tw)); - } - - var properties = GetBaseTelemetryProperties (settings); - var errorProperties = new Dictionary (StringComparer.OrdinalIgnoreCase) { - { "Message", errMessage } - }; - - // Add error to the properties dictionary - errorProperties.ToList ().ForEach (x => properties [x.Key] = x.Value); - - var metrics = new Dictionary (StringComparer.OrdinalIgnoreCase); - - appInsightsClient.SendTelemetry (eventName, properties, metrics); - - tw.WriteLine ($"Telemetry sent: Error: {errMessage}"); - tw.WriteLine ($" Event name: {eventName}"); - tw.WriteLine (" Properties:"); - foreach (var property in properties.OrderBy (x => x.Key)) { - tw.WriteLine ($" {property.Key}: {property.Value}"); - } - } - } -} diff --git a/build-tools/plots-to-appinsights/Result.cs b/build-tools/plots-to-appinsights/Result.cs deleted file mode 100644 index edc16138117..00000000000 --- a/build-tools/plots-to-appinsights/Result.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Xamarin.Android.Tools.Plots -{ - internal enum Status - { - OK = 0, - ShowHelp = 1, - MissingArgument = 2, - CsvFileDoesNotExist = 3, - Error = 4 - } - - internal class Result - { - public string Message { get; set; } - public Status Status { get; set; } = Status.OK; - } -} diff --git a/build-tools/plots-to-appinsights/Settings.cs b/build-tools/plots-to-appinsights/Settings.cs deleted file mode 100644 index 8bce56a6bf5..00000000000 --- a/build-tools/plots-to-appinsights/Settings.cs +++ /dev/null @@ -1,152 +0,0 @@ -using Mono.Options; -using System; -using System.IO; - -namespace Xamarin.Android.Tools.Plots -{ - internal class Settings - { - public bool ShowHelp { get; set; } - public string Environment { get; set; } = "Dev"; - public string BuildSystem { get; set; } = "Azure DevOps"; - public string BuildRepo { get; set; } - public string BuildType { get; set; } = "Desktop"; - public string BuildPipelineName { get; set; } - public string BuildId { get; set; } - public string BuildNumber { get; set; } - public string BuildUrl { get; set; } - public DateTime BuildDateUtc { get; set; } = default; - public string BuildCommit { get; set; } - public string PlotGroup { get; set; } - public string PlotTitle { get; set; } - public string AppInsightsTelemetryKey { get; set; } - public string CsvPathAndFilename { get; set; } - - public OptionSet Options { - get { - // README/packaging: https://github.com/xamarin/XamarinComponents/tree/master/XPlat/Mono.Options - // Source: https://github.com/mono/mono/tree/master/mcs/class/Mono.Options - // Note: Use '=' after items with associated values; otherwise, the 'v' parameter will hold the name of the option and not associated value for the argument - var options = new OptionSet { - { "h|help", "Show help", - v => ShowHelp = true }, - { "e|environment=", "Environment: Production, Test, Dev. Default: Dev", - v => Environment = v }, - { "s|build-system=", "Build system such as Azure DevOps or Jenkins. Default: Azure DevOps", - v => BuildSystem = v }, - { "r|repo=", "Repo being built", - v => BuildRepo = v }, - { "t|build-type=", "Build type: PR, CI, Manual or Desktop. Default: Desktop", - v => BuildType = v }, - { "p|build-pipeline-name=", "Build pipeline (definition) name such as Xamarin.Android", - v => BuildPipelineName = v }, - { "i|build-id=", "Build id", - v => BuildId = v }, - { "n|build-number=", "Build number", - v => BuildNumber = v }, - { "u|build-url=", "Url link to the build", - v => BuildUrl = v }, - { "d|build-date=", "Build date in UTC time. Default: Current UTC time when this app is first executed", - v => BuildDateUtc = DateTime.Parse(v).ToUniversalTime() }, - { "c|commit=", "Commid id for the commit being built", - v => BuildCommit = v }, - { "pg|plot-group=", "Plot group associated with the plot", - v => PlotGroup = v }, - { "pt|plot-title=", "Title for the plot chart", - v => PlotTitle = v }, - { "k|telemetry-key=", "Application Insights telemetry key", - v => AppInsightsTelemetryKey =v }, - { "<>", v => CsvPathAndFilename = v } - }; - - return options; - } - } - - internal Result ProcessArgs (string [] args) - { - var result = new Result (); - - if (args == null || args.Length == 0) { - result.Status = Status.MissingArgument; - result.Message = "Input arguments required"; - } else { - try { - Options.Parse (args); - } catch (OptionException e) { - result.Status = Status.Error; - result.Message = $"EXCEPTION: Processing input arguments: {e.Message}"; - } - - if (result.Status == Status.OK) { - if (ShowHelp) { - result.Status = Status.ShowHelp; - } else { - result = Validate (); - } - } - } - - return result; - } - - private Result Validate () - { - var result = new Result (); - var setting = string.Empty; - - // Environment is not required: Default: Dev - // BuildSystem is not required: Default: Azure DevOps - // BuildType is not required: Default: Desktop - if (string.IsNullOrWhiteSpace (BuildRepo)) { - setting = "repo"; - } else if (string.IsNullOrWhiteSpace (BuildPipelineName)) { - setting = "build-pipeline-name"; - } else if (string.IsNullOrWhiteSpace (BuildId)) { - setting = "build-id"; - } else if (string.IsNullOrWhiteSpace (BuildNumber)) { - setting = "build-number"; - } else if (string.IsNullOrWhiteSpace (BuildUrl)) { - setting = "build-url"; - } else if (string.IsNullOrWhiteSpace (BuildCommit)) { - setting = "commit"; - } else if (string.IsNullOrWhiteSpace (PlotGroup)) { - setting = "plot-group"; - } else if (string.IsNullOrWhiteSpace (PlotTitle)) { - setting = "plot-title"; - } else if (string.IsNullOrWhiteSpace (AppInsightsTelemetryKey)) { - setting = "telemetry-key"; - } else if (string.IsNullOrWhiteSpace (CsvPathAndFilename)) { - setting = "CSV path & filename"; - } - - if (!string.IsNullOrEmpty (setting)) { - result.Message = $"Required argument '{setting}' not set"; - result.Status = Status.MissingArgument; - } - - return result; - } - - internal void Display (TextWriter tw) - { - tw.WriteLine ("Settings:"); - tw.WriteLine ($" Environment: {Environment}"); - tw.WriteLine ($" BuildSystem: {BuildSystem}"); - tw.WriteLine ($" BuildRepo: {BuildRepo}"); - tw.WriteLine ($" BuildType: {BuildType}"); - tw.WriteLine ($" BuildPipelineName: {BuildPipelineName}"); - tw.WriteLine ($" BuildId: {BuildId}"); - tw.WriteLine ($" BuildNumber: {BuildNumber}"); - tw.WriteLine ($" BuildUrl: {BuildUrl}"); - tw.WriteLine ($" BuildDateUtc: {BuildDateUtc.ToString (Constants.AzureTimestampFormatUtc)}"); - tw.WriteLine ($" BuildCommit: {BuildCommit}"); - tw.WriteLine ($" PlotGroup: {PlotGroup}"); - tw.WriteLine ($" PlotTitle: {PlotTitle}"); - var appInsightsTelemetryKey = !string.IsNullOrEmpty (AppInsightsTelemetryKey) ? "[hidden]" : "[empty]"; - tw.WriteLine ($" AppInsightsTelemetryKey: {appInsightsTelemetryKey}"); - tw.WriteLine ($" Plot CSV file: {CsvPathAndFilename}"); - } - } - -} diff --git a/build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/ProcessPlotInput.cs b/build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/ProcessPlotInput.cs deleted file mode 100644 index 24f363641e0..00000000000 --- a/build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/ProcessPlotInput.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text.RegularExpressions; - -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; - -namespace Xamarin.Android.BuildTools.PrepTasks -{ - public class ProcessPlotInput : Task - { - [Required] - public string InputFilename { get; set; } - - public string ApplicationPackageName { get; set; } - - [Required] - public string DefinitionsFilename { get; set; } - - public string ResultsFilename { get; set; } - - public bool AddResults { get; set; } - - public string LabelSuffix { get; set; } - - protected Dictionary definedRegexs = new Dictionary (); - protected Dictionary results = new Dictionary (); - - protected void LoadDefinitions () - { - using (var reader = new StreamReader (DefinitionsFilename)) { - string line; - - while ((line = reader.ReadLine ()) != null) { - if (line.StartsWith ("#", StringComparison.Ordinal)) - continue; - int index = line.IndexOf ('='); - if (index < 1 || index == line.Length) - continue; - var label = line.Substring (0, index); - var pattern = line.Substring (index + 1); - Regex regex; - try { - regex = new Regex (pattern); - } catch (Exception e) { - Log.LogWarning ($"unable to create regex for label: {label} from pattern: {pattern}\n{e}"); - continue; - } - if (definedRegexs.ContainsKey (label)) - Log.LogWarning ($"label '{label}' is defined multiple times. the last definition will be used"); - definedRegexs [label] = regex; - } - } - } - - protected bool CheckInputFile () - { - if (File.Exists (InputFilename)) - return true; - - var errorMessage = $"Input file '{InputFilename}' doesn't exist."; - Log.LogError (errorMessage); - - ErrorResultsHelper.CreateErrorResultsFile ( - Path.ChangeExtension (ResultsFilename, null) + LabelSuffix + ".xml", - ApplicationPackageName, - "logcat output", - new Exception (errorMessage), - $"Input file '{InputFilename}' doesn't exist. It might be caused by various reasons. Among them: the test crashed or test did not run."); - - return false; - } - - public override bool Execute () - { - LoadDefinitions (); - - if (!CheckInputFile ()) - return false; - - using (var reader = new StreamReader (InputFilename)) { - string line; - - while ((line = reader.ReadLine ()) != null) { - foreach (var regex in definedRegexs) { - var definedMatch = regex.Value.Match (line); - if (!definedMatch.Success) - continue; - string logMessage = definedMatch.Value; - var v = definedMatch.Groups ["value"]; - if (!v.Success) - continue; - results [regex.Key] = v.Value; - var m = definedMatch.Groups ["message"]; - if (m.Success) - logMessage = m.Value; - - Log.LogMessage (MessageImportance.Low, $"Message: {logMessage} Value: {v.Value}"); - } - } - - WriteResults (); - - reader.Close (); - } - - return true; - } - - protected void WriteResults () - { - if (ResultsFilename != null) { - string line1 = null, line2 = null; - if (AddResults && File.Exists (ResultsFilename)) - using (var reader = new StreamReader (ResultsFilename)) { - try { - line1 = reader.ReadLine (); - line2 = reader.ReadLine (); - } catch (Exception e) { - Log.LogWarning ($"unable to read previous results from {ResultsFilename}\n{e}"); - line1 = line2 = null; - } - } - using (var resultsFile = new StreamWriter (ResultsFilename)) { - WriteValues (resultsFile, results.Keys, line1, LabelSuffix); - WriteValues (resultsFile, results.Values, line2); - resultsFile.Close (); - } - } - } - - void WriteValues (StreamWriter writer, ICollection values, string line, string suffix = null) - { - bool first; - if (string.IsNullOrEmpty (line)) - first = true; - else { - writer.Write (line); - first = false; - } - foreach (var key in values) { - if (!first) - writer.Write (','); - writer.Write (key); - if (!string.IsNullOrEmpty (suffix)) - writer.Write (suffix); - first = false; - } - writer.WriteLine (); - } - } -} diff --git a/tools/msbuild-fuzzer/Program.cs b/tools/msbuild-fuzzer/Program.cs deleted file mode 100644 index 58c4c8809b8..00000000000 --- a/tools/msbuild-fuzzer/Program.cs +++ /dev/null @@ -1,317 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using Xamarin.ProjectTools; - -namespace MSBuild.Fuzzer -{ - class Program - { - static readonly Random random = new Random (); - static readonly List installedPackages = new List (); - static ProjectBuilder builder; - static XamarinFormsAndroidApplicationProject application; - static bool needsInstall = true; - static string directory; - - static void Main () - { - var temp = Path.Combine (Path.GetDirectoryName (typeof (Program).Assembly.Location)); - using (builder = new ProjectBuilder (Path.Combine ("temp", "Fuzzer")) { - AutomaticNuGetRestore = false, - CleanupAfterSuccessfulBuild = false, - CleanupOnDispose = true, - Root = XABuildPaths.TestOutputDirectory, - }) { - directory = Path.GetFullPath (Path.Combine (builder.Root, builder.ProjectDirectory)); - if (Directory.Exists (directory)) - Directory.Delete (directory, recursive: true); - - application = new XamarinFormsAndroidApplicationProject (); - application.AndroidManifest = application.AndroidManifest.Replace ("", ""); - application.MainActivity = application.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", "Android.Util.Log.Debug (\"FUZZER\", \"App started!\");"); - var abis = new string [] { "armeabi-v7a", "arm64-v8a", "x86" }; - application.SetProperty (KnownProperties.AndroidSupportedAbis, string.Join (";", abis)); - - if (!NuGetRestore ()) { - Console.WriteLine ("Initial NuGet restore failed!"); - return; - } - - Func [] operations = { - AddClass, - AddResource, - Build, - ChangePackageName, - Clean, - DesignTimeBuild, - Install, - NuGetRestore, - RemoveClass, - RemoveResource, - RenameClass, - RenameResource, - Run, - TouchRandomFile, - Uninstall, - }; - - while (true) { - var operation = operations [random.Next (operations.Length)]; - if (!operation ()) { - break; - } - } - } - - Console.WriteLine ("Press enter to exit..."); - Console.ReadLine (); - } - - static bool NuGetRestore () - { - Console.WriteLine (nameof (NuGetRestore)); - return builder.RunTarget (application, "Restore", doNotCleanupOnUpdate: true); - } - - static bool Build () - { - Console.WriteLine (nameof (Build)); - return builder.Build (application, doNotCleanupOnUpdate: true); - } - - static bool DesignTimeBuild () - { - Console.WriteLine (nameof (DesignTimeBuild)); - return builder.DesignTimeBuild (application, doNotCleanupOnUpdate: true); - } - - static bool Clean () - { - Console.WriteLine (nameof (Clean)); - return builder.Clean (application, doNotCleanupOnUpdate: true); - } - - static bool Install () - { - Console.WriteLine (nameof (Install)); - if (!builder.Install (application, doNotCleanupOnUpdate: true)) { - return false; - } - if (!installedPackages.Contains (application.PackageName)) - installedPackages.Add (application.PackageName); - needsInstall = false; - return true; - } - - static bool Uninstall () - { - Console.WriteLine (nameof (Uninstall)); - foreach (var packageName in installedPackages) { - Adb ($"uninstall {packageName}"); - } - installedPackages.Clear (); - needsInstall = true; - return true; - } - - static bool Run () - { - if (needsInstall && !Install ()) - return false; - Console.WriteLine (nameof (Run)); - string stop = Adb ($"shell am force-stop {application.PackageName}", ignoreExitCode: true); - Adb ("logcat -c"); - string activity = $"{application.PackageName}/{application.JavaPackageName}.MainActivity"; - string start = Adb ($"shell am start -n {activity}"); - Console.WriteLine (start.Trim ()); - //Wait for the app to start - Thread.Sleep (3000); - string logcat = Adb ("logcat -d"); - if (!logcat.Contains ("App started!")) { - Console.WriteLine (logcat); - throw new Exception ($"Activity {activity} did not start!"); - } - return true; - } - - static string Adb (string arguments, bool ignoreExitCode = false) - { - var info = new ProcessStartInfo { - FileName = "adb", - Arguments = arguments, - CreateNoWindow = true, - WindowStyle = ProcessWindowStyle.Hidden, - UseShellExecute = false, - RedirectStandardError = true, - RedirectStandardOutput = true, - }; - var builder = new StringBuilder (); - using (var process = new Process ()) { - var stdout_done = new ManualResetEventSlim (false); - var stderr_done = new ManualResetEventSlim (false); - process.StartInfo = info; - process.OutputDataReceived += (sender, e) => { - if (e.Data != null) { - builder.AppendLine (e.Data); - } else { - stdout_done.Set (); - } - }; - process.ErrorDataReceived += (sender, e) => { - if (e.Data != null) { - builder.AppendLine (e.Data); - } else { - stderr_done.Set (); - } - }; - process.Start (); - process.BeginErrorReadLine (); - process.BeginOutputReadLine (); - process.WaitForExit (); - stderr_done.Wait (); - stdout_done.Wait (); - if (!ignoreExitCode && process.ExitCode != 0) { - Console.WriteLine (builder); - throw new Exception ($"Adb exited with code: {process.ExitCode}"); - } - } - return builder.ToString (); - } - - static readonly string [] extensions = { - ".cs", - ".csproj", - ".png", - ".xaml", - ".xml", - }; - - static bool TouchRandomFile () - { - Console.WriteLine (nameof (TouchRandomFile)); - var files = (from f in Directory.EnumerateFiles (directory, "*", SearchOption.AllDirectories) - let relative = f.Substring (directory.Length + 1) - where !relative.StartsWith ("obj") && !relative.StartsWith ("bin") - let ext = Path.GetExtension (f) - where extensions.Contains (ext) - select f).ToArray (); - var file = files [random.Next (0, files.Length)]; - File.SetLastWriteTimeUtc (file, DateTime.UtcNow); - return true; - } - - static bool ChangePackageName () - { - Console.WriteLine (nameof (ChangePackageName)); - application.PackageName = "com.foo.a" + RandomName (); - application.Touch ("Properties\\AndroidManifest.xml"); - needsInstall = true; - return true; - } - - static bool AddClass () - { - Console.WriteLine (nameof (AddClass)); - application.Sources.Add (new Class ()); - return true; - } - - static bool RemoveClass () - { - Console.WriteLine (nameof (RemoveClass)); - for (int i = application.Sources.Count - 1; i >= 0; i--) { - if (application.Sources [i] is Class) { - application.Sources.RemoveAt (i); - break; - } - } - return true; - } - - static bool RenameClass () - { - Console.WriteLine (nameof (RemoveClass)); - var clazz = application.Sources.OfType ().FirstOrDefault (); - if (clazz != null) { - clazz.Rename (); - } - return true; - } - - static bool AddResource () - { - Console.WriteLine (nameof (AddResource)); - application.Sources.Add (new AndroidResource ()); - return true; - } - - static bool RemoveResource () - { - Console.WriteLine (nameof (RemoveResource)); - for (int i = application.Sources.Count - 1; i >= 0; i--) { - if (application.Sources [i] is AndroidResource) { - application.Sources.RemoveAt (i); - break; - } - } - return true; - } - - static bool RenameResource () - { - Console.WriteLine (nameof (RenameResource)); - var resource = application.Sources.OfType ().FirstOrDefault (); - if (resource != null) { - resource.Rename (); - } - return true; - } - - static string RandomName () => Guid.NewGuid ().ToString ("N"); - - class Class : BuildItem.Source - { - public string TypeName { get; set; } - - public Class () : base (RandomName () + ".cs") - { - Rename (); - TextContent = () => $"public class Foo{TypeName} : Java.Lang.Object {{ }}"; - } - - public void Rename () - { - TypeName = RandomName (); - Timestamp = null; - } - } - - class AndroidResource : BuildItem - { - public string ResourceId { get; set; } - - public string StringValue { get; set; } - - public AndroidResource () : base ("AndroidResource", RandomName () + ".xml") - { - Rename (); - TextContent = () => $@" - - {StringValue} -"; - } - - public void Rename () - { - ResourceId = RandomName (); - StringValue = RandomName (); - Timestamp = null; - } - } - } -} diff --git a/tools/msbuild-fuzzer/msbuild-fuzzer.csproj b/tools/msbuild-fuzzer/msbuild-fuzzer.csproj deleted file mode 100644 index c4ac46a77e8..00000000000 --- a/tools/msbuild-fuzzer/msbuild-fuzzer.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - $(DotNetStableTargetFramework) - {A3671983-ABC2-4693-8872-463427B57117} - Exe - - - - - {2dd1ee75-6d8d-4653-a800-0a24367f7f38} - Xamarin.ProjectTools - - - \ No newline at end of file diff --git a/tools/msbuild-fuzzer/msbuild-fuzzer.sln b/tools/msbuild-fuzzer/msbuild-fuzzer.sln deleted file mode 100644 index e0d6cc19012..00000000000 --- a/tools/msbuild-fuzzer/msbuild-fuzzer.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28803.352 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "msbuild-fuzzer", "msbuild-fuzzer.csproj", "{A3671983-ABC2-4693-8872-463427B57117}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.ProjectTools", "..\..\src\Xamarin.Android.Build.Tasks\Tests\Xamarin.ProjectTools\Xamarin.ProjectTools.csproj", "{2DD1EE75-6D8D-4653-A800-0A24367F7F38}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A3671983-ABC2-4693-8872-463427B57117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A3671983-ABC2-4693-8872-463427B57117}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A3671983-ABC2-4693-8872-463427B57117}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A3671983-ABC2-4693-8872-463427B57117}.Release|Any CPU.Build.0 = Release|Any CPU - {2DD1EE75-6D8D-4653-A800-0A24367F7F38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2DD1EE75-6D8D-4653-A800-0A24367F7F38}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2DD1EE75-6D8D-4653-A800-0A24367F7F38}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2DD1EE75-6D8D-4653-A800-0A24367F7F38}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {E88EED5D-9DFA-405D-9495-4EC9A146B249} - EndGlobalSection -EndGlobal