Skip to content
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

Sdkresolvers can use environment variable tracking #1

Open
wants to merge 6 commits into
base: maneely/propertytracking
Choose a base branch
from

Conversation

maneely
Copy link
Owner

@maneely maneely commented Aug 14, 2019

These changes surface global properties and environment variables to SDK Resolvers. This allows them to have their environment variable requests be tracked.

SDK Resolvers will have to acknowledge that they have opted-in to environment variable tracking on the returned SdkResult.

_loggingContext.LogBuildEvent(args);
}

return Environment.GetEnvironmentVariable(name) ?? string.Empty;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd favor not returning empty if the environment variable does not exist. In msbuildian an empty string is returned for non-existing env vars, but in C# null is returned.

_loggingContext = loggingContext;
}

public override string GetGlobalPropertyValue(string name)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why expose these to the resolver? AFAIK resolvers didn't have access to global properties before. I'd vote on keeping in that way to minimize their complexity.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the rippling changes required to pipe global properties, I'm more convinced we shouldn't expose them.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that users can override settings that the NuGet SDK resolver uses. Right now it can only get its properties from nuget.config

dotnet#2914

Copy link

@cdmihai cdmihai Aug 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd separate the changes in two PRs then. Making sdk resolution depend on global properties also requires changing sdk resolver caching: #1 (comment)

@@ -83,6 +89,7 @@ public void Translate(ITranslator translator)
translator.Translate(ref _submissionId);
translator.Translate(ref _version);
translator.Translate(ref _interactive);
translator.TranslateDictionary(ref _globalProperties, count => new Dictionary<string, string>(count, StringComparer.OrdinalIgnoreCase));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make node communication slower. Each node calls back into the main node when resolving sdks.

@@ -53,7 +55,7 @@ public override SdkResult ResolveSdk(int submissionId, SdkReference sdk, Logging
*/
result = cached.GetOrAdd(
sdk.Name,
key => base.ResolveSdk(submissionId, sdk, loggingContext, sdkReferenceLocation, solutionPath, projectPath, interactive));
key => base.ResolveSdk(submissionId, sdk, loggingContext, sdkReferenceLocation, solutionPath, projectPath, interactive, globalProperties));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a correctness argument for not passing global properties. Sdks are currently cached per build submission and not per build request (a build submission has multiple requests). We'd have to redo their caching to change the key to be a Microsoft.Build.BackEnd.ConfigurationMetadata. But by doing this we'd loose perf, and I don't see what we gain for it.

@@ -52,11 +55,15 @@ public SdkResult()

public override string Version => _version;

public override bool TrackEnvironmentVariables { get => _trackEnvironmentVariables; set => _trackEnvironmentVariables = value; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems superfluous to have resolvers dynamically respond whether they track environment variables on every sdk resolution. Probably better to ask them once, during resolver loading in Microsoft.Build.BackEnd.SdkResolution.SdkResolverLoader

Like SdkResolver.GetCapabilities, and the env tracking would be part of a return enum.

@@ -32,7 +32,7 @@ public sealed class BinaryLogger : ILogger
// version 7:
// - Include ProjectStartedEventArgs.GlobalProperties
// version 8:
// - new record kinds: EnvironmentVariableRead, PropertyReassignment, UninitializedPropertyRead
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KirillOsenkov do you prefer a version number bump instead, to avoid a small window of time where version 8 would be broken?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can bump it. Will do next commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants