Skip to content

Commit

Permalink
Don't log task inputs and outputs when binary logger is enabled (#5498)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillOsenkov authored and Nigusu-Allehu committed Nov 21, 2023
1 parent c72fbab commit c410c2c
Show file tree
Hide file tree
Showing 19 changed files with 1 addition and 186 deletions.
17 changes: 0 additions & 17 deletions src/NuGet.Core/NuGet.Build.Tasks/BuildTasksUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ namespace NuGet.Build.Tasks
{
public static class BuildTasksUtility
{
public static void LogInputParam(Common.ILogger log, string name, params string[] values)
{
LogTaskParam(log, "in", name, values);
}

public static void LogOutputParam(Common.ILogger log, string name, params string[] values)
{
LogTaskParam(log, "out", name, values);
}

private static void LogTaskParam(Common.ILogger log, string direction, string name, params string[] values)
{
var stringValues = values?.Select(s => s) ?? Enumerable.Empty<string>();

log.Log(Common.LogLevel.Debug, $"({direction}) {name} '{string.Join(";", stringValues)}'");
}

/// <summary>
/// Add all restorable projects to the restore list.
/// This is the behavior for --recursive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public class GetCentralPackageVersionsTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'");
log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
log.LogDebug($"(in) CentralPackageVersions '{string.Join(";", CentralPackageVersions.Select(p => p.ItemSpec))}'");

var entries = new List<ITaskItem>();
var seenIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

Expand Down
11 changes: 0 additions & 11 deletions src/NuGet.Core/NuGet.Build.Tasks/GetProjectTargetFrameworksTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ public class GetProjectTargetFrameworksTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectPath '{ProjectPath}'");
log.LogDebug($"(in) TargetFrameworkMoniker '{TargetFrameworkMoniker}'");
log.LogDebug($"(in) TargetPlatformIdentifier '{TargetPlatformIdentifier}'");
log.LogDebug($"(in) TargetPlatformVersion '{TargetPlatformVersion}'");
log.LogDebug($"(in) TargetPlatformMinVersion '{TargetPlatformMinVersion}'");
log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
log.LogDebug($"(in) TargetFramework '{TargetFramework}'");

// If no framework can be found this will return Unsupported.
var frameworks = MSBuildProjectFrameworkUtility.GetProjectFrameworkStrings(
projectFilePath: ProjectPath,
Expand All @@ -79,8 +70,6 @@ public override bool Execute()

ProjectTargetFrameworks = string.Join(";", frameworks);

log.LogDebug($"(out) ProjectTargetFrameworks '{ProjectTargetFrameworks}'");

return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,8 @@ public class GetReferenceNearestTargetFrameworkTask : Microsoft.Build.Utilities.

public override bool Execute()
{

var logger = new MSBuildLogger(Log);

BuildTasksUtility.LogInputParam(logger, nameof(CurrentProjectTargetFramework), CurrentProjectTargetFramework);

BuildTasksUtility.LogInputParam(logger, nameof(CurrentProjectTargetPlatform), CurrentProjectTargetPlatform);

BuildTasksUtility.LogInputParam(logger, nameof(FallbackTargetFrameworks),
FallbackTargetFrameworks == null
? ""
: string.Join(";", FallbackTargetFrameworks.Select(p => p)));

BuildTasksUtility.LogInputParam(logger, nameof(AnnotatedProjectReferences),
AnnotatedProjectReferences == null
? ""
: string.Join(";", AnnotatedProjectReferences.Select(p => p.ItemSpec)));

if (AnnotatedProjectReferences == null)
{
return !Log.HasLoggedErrors;
Expand Down Expand Up @@ -109,8 +94,6 @@ public override bool Execute()
AssignedProjects[index] = AssignNearestFrameworkForSingleReference(AnnotatedProjectReferences[index], projectNuGetFramework, fallbackNuGetFrameworks, logger);
}

BuildTasksUtility.LogOutputParam(logger, nameof(AssignedProjects), string.Join(";", AssignedProjects.Select(p => p.ItemSpec)));

return !Log.HasLoggedErrors;
}

Expand Down
20 changes: 0 additions & 20 deletions src/NuGet.Core/NuGet.Build.Tasks/GetRestoreDotnetCliToolsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,6 @@ public class GetRestoreDotnetCliToolsTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectPath '{ProjectPath}'");
log.LogDebug($"(in) DotnetCliToolReferences '{string.Join(";", DotnetCliToolReferences.Select(p => p.ItemSpec))}'");
if (RestoreSources != null)
{
log.LogDebug($"(in) RestoreSources '{string.Join(";", RestoreSources.Select(p => p))}'");
}
if (RestorePackagesPath != null)
{
log.LogDebug($"(in) RestorePackagesPath '{RestorePackagesPath}'");
}
if (RestoreFallbackFolders != null)
{
log.LogDebug($"(in) RestoreFallbackFolders '{string.Join(";", RestoreFallbackFolders.Select(p => p))}'");
}
if (RestoreConfigFilePaths != null)
{
log.LogDebug($"(in) RestoreConfigFilePaths '{string.Join(";", RestoreConfigFilePaths.Select(p => p))}'");
}

var entries = new List<ITaskItem>();

foreach (var msbuildItem in DotnetCliToolReferences)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public class GetRestoreFrameworkReferencesTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'");
log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
log.LogDebug($"(in) FrameworkReferences '{string.Join(";", FrameworkReferences.Select(p => p.ItemSpec))}'");

var entries = new List<ITaskItem>();
var seenIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public class GetRestorePackageDownloadsTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'");
log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
log.LogDebug($"(in) PackageDownloads '{string.Join(";", PackageDownloads.Select(p => p.ItemSpec))}'");

var entries = new List<ITaskItem>();
var seenIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ public class GetRestorePackageReferencesTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'");
log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
log.LogDebug($"(in) PackageReferences '{string.Join(";", PackageReferences.Select(p => p.ItemSpec))}'");

var entries = new List<ITaskItem>();
var seenIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public class GetRestoreProjectJsonPathTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectPath '{ProjectPath}'");

var directory = Path.GetDirectoryName(ProjectPath);
var projectName = Path.GetFileNameWithoutExtension(ProjectPath);

Expand All @@ -39,8 +36,6 @@ public override bool Execute()
ProjectJsonPath = path;
}

log.LogDebug($"(out) ProjectJsonPath '{ProjectJsonPath}'");

return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ public class GetRestoreProjectReferencesTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
// Log inputs
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'");
log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'");
log.LogDebug($"(in) ProjectReferences '{string.Join(";", ProjectReferences.Select(p => p.ItemSpec))}'");
log.LogDebug($"(in) ParentProjectPath '{ParentProjectPath}'");

var entries = new List<ITaskItem>();

// Filter obvious duplicates without considering OS case sensitivity.
Expand Down
12 changes: 1 addition & 11 deletions src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectStyleTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Globalization;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.ProjectModel;

namespace NuGet.Build.Tasks
Expand Down Expand Up @@ -52,22 +53,11 @@ public override bool Execute()
{
var log = new MSBuildLogger(Log);

// Log Inputs
BuildTasksUtility.LogInputParam(log, nameof(HasPackageReferenceItems), HasPackageReferenceItems.ToString(CultureInfo.CurrentCulture));
BuildTasksUtility.LogInputParam(log, nameof(MSBuildProjectDirectory), MSBuildProjectDirectory);
BuildTasksUtility.LogInputParam(log, nameof(MSBuildProjectName), MSBuildProjectName);
BuildTasksUtility.LogInputParam(log, nameof(ProjectJsonPath), ProjectJsonPath);
BuildTasksUtility.LogInputParam(log, nameof(RestoreProjectStyle), RestoreProjectStyle);

var result = BuildTasksUtility.GetProjectRestoreStyle(RestoreProjectStyle, HasPackageReferenceItems, ProjectJsonPath, MSBuildProjectDirectory, MSBuildProjectName, log);

IsPackageReferenceCompatibleProjectStyle = result.IsPackageReferenceCompatibleProjectStyle;
ProjectStyle = result.ProjectStyle;

// Log Outputs
BuildTasksUtility.LogOutputParam(log, nameof(IsPackageReferenceCompatibleProjectStyle), IsPackageReferenceCompatibleProjectStyle.ToString(CultureInfo.CurrentCulture));
BuildTasksUtility.LogOutputParam(log, nameof(ProjectStyle), ProjectStyle.ToString());

return !Log.HasLoggedErrors;
}
}
Expand Down
23 changes: 0 additions & 23 deletions src/NuGet.Core/NuGet.Build.Tasks/GetRestoreSettingsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,6 @@ public override bool Execute()
#endif
var log = new MSBuildLogger(Log);

// Log Inputs
BuildTasksUtility.LogInputParam(log, nameof(ProjectUniqueName), ProjectUniqueName);
BuildTasksUtility.LogInputParam(log, nameof(RestoreSources), RestoreSources);
BuildTasksUtility.LogInputParam(log, nameof(RestorePackagesPath), RestorePackagesPath);
BuildTasksUtility.LogInputParam(log, nameof(RestoreRepositoryPath), RestoreRepositoryPath);
BuildTasksUtility.LogInputParam(log, nameof(RestoreFallbackFolders), RestoreFallbackFolders);
BuildTasksUtility.LogInputParam(log, nameof(RestoreConfigFile), RestoreConfigFile);
BuildTasksUtility.LogInputParam(log, nameof(RestoreSolutionDirectory), RestoreSolutionDirectory);
BuildTasksUtility.LogInputParam(log, nameof(RestoreRootConfigDirectory), RestoreRootConfigDirectory);
BuildTasksUtility.LogInputParam(log, nameof(RestorePackagesPathOverride), RestorePackagesPathOverride);
BuildTasksUtility.LogInputParam(log, nameof(RestoreSourcesOverride), RestoreSourcesOverride);
BuildTasksUtility.LogInputParam(log, nameof(RestoreFallbackFoldersOverride), RestoreFallbackFoldersOverride);
BuildTasksUtility.LogInputParam(log, nameof(RestoreProjectStyle), RestoreProjectStyle);
BuildTasksUtility.LogInputParam(log, nameof(MSBuildStartupDirectory), MSBuildStartupDirectory);


try
{
// Validate inputs
Expand Down Expand Up @@ -189,13 +173,6 @@ public override bool Execute()
return false;
}

// Log Outputs
BuildTasksUtility.LogOutputParam(log, nameof(OutputPackagesPath), OutputPackagesPath);
BuildTasksUtility.LogOutputParam(log, nameof(OutputRepositoryPath), OutputRepositoryPath);
BuildTasksUtility.LogOutputParam(log, nameof(OutputSources), OutputSources);
BuildTasksUtility.LogOutputParam(log, nameof(OutputFallbackFolders), OutputFallbackFolders);
BuildTasksUtility.LogOutputParam(log, nameof(OutputConfigFilePaths), OutputConfigFilePaths);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public class GetRestoreSolutionProjectsTask : Microsoft.Build.Utilities.Task

public override bool Execute()
{
// Log inputs
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectReferences '{string.Join(";", ProjectReferences.Select(p => p.ItemSpec))}'");
log.LogDebug($"(in) SolutionFilePath '{SolutionFilePath}'");

var entries = new List<ITaskItem>();
var parentDirectory = Path.GetDirectoryName(SolutionFilePath);

Expand Down
2 changes: 0 additions & 2 deletions src/NuGet.Core/NuGet.Build.Tasks/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void BuildTasksUtility.AddPropertyIfExists(IDictionary<string, string> properties, string key, string[] value)', validate parameter 'properties' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Build.Tasks.BuildTasksUtility.AddPropertyIfExists(System.Collections.Generic.IDictionary{System.String,System.String},System.String,System.String[])")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void BuildTasksUtility.CopyPropertyIfExists(ITaskItem item, IDictionary<string, string> properties, string key, string toKey)', validate parameter 'properties' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Build.Tasks.BuildTasksUtility.CopyPropertyIfExists(Microsoft.Build.Framework.ITaskItem,System.Collections.Generic.IDictionary{System.String,System.String},System.String,System.String)")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'bool BuildTasksUtility.DoesProjectSupportRestore(PackageSpec packageSpec)', validate parameter 'packageSpec' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Build.Tasks.BuildTasksUtility.DoesProjectSupportRestore(NuGet.ProjectModel.PackageSpec)~System.Boolean")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void BuildTasksUtility.LogInputParam(ILogger log, string name, params string[] values)', validate parameter 'log' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Build.Tasks.BuildTasksUtility.LogInputParam(NuGet.Common.ILogger,System.String,System.String[])")]
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void BuildTasksUtility.LogOutputParam(ILogger log, string name, params string[] values)', validate parameter 'log' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Build.Tasks.BuildTasksUtility.LogOutputParam(NuGet.Common.ILogger,System.String,System.String[])")]
[assembly: SuppressMessage("Build", "CA2225:Provide a method named 'ToConsoleOutLogMessage' or 'FromBuildErrorEventArgs' as an alternate for operator op_Implicit.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Build.Tasks.ConsoleOutLogItem.op_Implicit(Microsoft.Build.Framework.BuildErrorEventArgs)~NuGet.Build.Tasks.ConsoleOutLogItem")]
[assembly: SuppressMessage("Build", "CA2225:Provide a method named 'ToConsoleOutLogMessage' or 'FromBuildMessageEventArgs' as an alternate for operator op_Implicit.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Build.Tasks.ConsoleOutLogItem.op_Implicit(Microsoft.Build.Framework.BuildMessageEventArgs)~NuGet.Build.Tasks.ConsoleOutLogItem")]
[assembly: SuppressMessage("Build", "CA2225:Provide a method named 'ToConsoleOutLogMessage' or 'FromBuildWarningEventArgs' as an alternate for operator op_Implicit.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Build.Tasks.ConsoleOutLogItem.op_Implicit(Microsoft.Build.Framework.BuildWarningEventArgs)~NuGet.Build.Tasks.ConsoleOutLogItem")]
Expand Down
11 changes: 0 additions & 11 deletions src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ public override bool Execute()

NuGet.Common.Migrations.MigrationRunner.Run();

// Log inputs
log.LogDebug($"(in) RestoreGraphItems Count '{RestoreGraphItems?.Count() ?? 0}'");
log.LogDebug($"(in) RestoreDisableParallel '{RestoreDisableParallel}'");
log.LogDebug($"(in) RestoreNoCache '{RestoreNoCache || RestoreNoHttpCache}'");
log.LogDebug($"(in) RestoreIgnoreFailedSources '{RestoreIgnoreFailedSources}'");
log.LogDebug($"(in) RestoreRecursive '{RestoreRecursive}'");
log.LogDebug($"(in) RestoreForce '{RestoreForce}'");
log.LogDebug($"(in) HideWarningsAndErrors '{HideWarningsAndErrors}'");
log.LogDebug($"(in) RestoreForceEvaluate '{RestoreForceEvaluate}'");
log.LogDebug($"(in) RestorePackagesConfig '{RestorePackagesConfig}'");

try
{
return ExecuteAsync(log).Result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public override bool Execute()
var all = AllProjects?.Select(e => e.ItemSpec).ToArray() ?? Array.Empty<string>();
var valid = ValidProjects?.Select(e => e.ItemSpec).ToArray() ?? Array.Empty<string>();

// log inputs
BuildTasksUtility.LogInputParam(log, nameof(AllProjects), all);
BuildTasksUtility.LogInputParam(log, nameof(ValidProjects), valid);

// Log warnings for invalid projects
foreach (var path in all.Except(valid, PathUtility.GetStringComparerBasedOnOS()))
{
Expand Down
4 changes: 0 additions & 4 deletions src/NuGet.Core/NuGet.Build.Tasks/WriteRestoreGraphTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ public override bool Execute()

var log = new MSBuildLogger(Log);

log.LogDebug($"(in) RestoreGraphItems Count '{RestoreGraphItems?.Count() ?? 0}'");
log.LogDebug($"(in) RestoreGraphOutputPath '{RestoreGraphOutputPath}'");
log.LogDebug($"(in) RestoreRecursive '{RestoreRecursive}'");

// Convert to the internal wrapper
var wrappedItems = RestoreGraphItems.Select(GetMSBuildItem);

Expand Down
Loading

0 comments on commit c410c2c

Please sign in to comment.