Skip to content

Commit

Permalink
Don't log RAR task inputs manually when LogTaskInputs is set. (dotnet…
Browse files Browse the repository at this point in the history
…#5017)

Move the environment variable read to Traits and cache it. Otherwise we would read the environment every time a task is run.
  • Loading branch information
KirillOsenkov authored and Forgind committed Jan 14, 2020
1 parent e7b6e83 commit fe2dfdf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;

using Microsoft.Build.Execution;
using Microsoft.Build.Exceptions;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Construction;
using Microsoft.Build.BackEnd.Logging;
using System.Globalization;
using System.Reflection;
#if FEATURE_APPDOMAIN
using System.Runtime.Remoting;
#endif
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Exceptions;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Shared;
using Microsoft.Build.Utilities;

using TaskItem = Microsoft.Build.Execution.ProjectItemInstance.TaskItem;

Expand Down Expand Up @@ -145,7 +146,7 @@ internal TaskExecutionHost(IBuildComponentHost host)
// If this is false, check the environment variable to see if it's there:
if (!LogTaskInputs)
{
LogTaskInputs = (Environment.GetEnvironmentVariable("MSBUILDLOGTASKINPUTS") == "1");
LogTaskInputs = Traits.Instance.EscapeHatches.LogTaskInputs;
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/Shared/Traits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ public bool LogProjectImports
}
}

private bool? _logTaskInputs;
public bool LogTaskInputs
{
get
{
if (_logTaskInputs == null)
{
_logTaskInputs = Environment.GetEnvironmentVariable("MSBUILDLOGTASKINPUTS") == "1";
}
return _logTaskInputs.Value;
}
set
{
_logTaskInputs = value;
}
}

/// <summary>
/// Read information only once per file per ResolveAssemblyReference invocation.
/// </summary>
Expand Down
8 changes: 7 additions & 1 deletion src/Tasks/AssemblyDependency/ResolveAssemblyReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public ITaskItem[] Assemblies

/// <summary>
/// A list of assembly files that can be part of the search and resolution process.
/// These must be absolute filesnames, or project-relative filenames.
/// These must be absolute filenames, or project-relative filenames.
///
/// Assembly files in this list will be considered when SearchPaths contains
/// {CandidateAssemblyFiles} as one of the paths to consider.
Expand Down Expand Up @@ -1269,6 +1269,12 @@ private MessageImportance ChooseReferenceLoggingImportance(Reference reference)
/// </summary>
private void LogInputs()
{
if (Traits.Instance.EscapeHatches.LogTaskInputs)
{
// the inputs will be logged automatically anyway, avoid duplication in the logs
return;
}

if (!Silent)
{
Log.LogMessageFromResources(MessageImportance.Low, "ResolveAssemblyReference.LogTaskPropertyFormat", "TargetFrameworkMoniker");
Expand Down

0 comments on commit fe2dfdf

Please sign in to comment.