-
Notifications
You must be signed in to change notification settings - Fork 447
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
Use package source mappings in VMR build #19114
Use package source mappings in VMR build #19114
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave some feedback which you can react to post-merge as I understand that this is high priority.
<!-- Delete the original SBRP packages --> | ||
<RemoveDir Directories="$(PrebuiltSourceBuiltPackagesPath)SourceBuildReferencePackages" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we copy to that location if we then immediately copy to another location and delete this location?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We extract these SBRPs from the PSB archive, together with other packages to prereqs/packages/previously-source-built
.
After extraction, SBRPs will be in prereqs/packages/previously-source-built/SourceBuildReferencePackages
.
We then copy SBRPs to prereqs/packages/reference
folder, but still leave the original extracted content that could cause poisoned files. With package mappings work, this is totally unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
@@ -34,45 +37,126 @@ public class UpdateNuGetConfigPackageSourcesMappings : Task | |||
/// </summary> | |||
public string[] SourceBuildSources { get; set; } | |||
|
|||
public string VmrRoot { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather call this RepoRoot
. VMR isn't the best keyword to use in source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
@@ -34,45 +37,126 @@ public class UpdateNuGetConfigPackageSourcesMappings : Task | |||
/// </summary> | |||
public string[] SourceBuildSources { get; set; } | |||
|
|||
public string VmrRoot { get; set; } | |||
|
|||
private string SBRPCacheSourceName = "source-build-reference-package-cache"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be const and follow naming conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
@@ -52,6 +52,9 @@ | |||
|
|||
<Copy SourceFiles="@(UnpackedSourceBuildReferencePackages)" DestinationFiles="$(ReferencePackagesDir)%(Filename)%(Extension)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of copy and delete, wouldn't it be better to change this to a move?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
...ls/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/UpdateNuGetConfigPackageSourcesMappings.cs
Show resolved
Hide resolved
...ls/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/UpdateNuGetConfigPackageSourcesMappings.cs
Show resolved
Hide resolved
Hashtable allSourcesPackages = new Hashtable(); | ||
Hashtable currentPackages = new Hashtable(); | ||
Hashtable referencePackages = new Hashtable(); | ||
Hashtable previouslyBuiltPackages = new Hashtable(); | ||
Hashtable oldSourceMappingPatterns = new Hashtable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually recommend to use Dictionary<T,V> instead of Hashtable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a better option - will update, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
if (string.IsNullOrEmpty(VmrRoot)) | ||
{ | ||
throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, "VmrRoot is not set - cannot determine SBRP packages.")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably just add the Required
attribute to the VmrRoot property and remove this block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
@@ -34,45 +37,126 @@ public class UpdateNuGetConfigPackageSourcesMappings : Task | |||
/// </summary> | |||
public string[] SourceBuildSources { get; set; } | |||
|
|||
public string VmrRoot { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is only used to get the SBRP repo path. Consider refactoring to be the SBRP src path. IMO it would be better to have this logic encapsulated in the msbuild logic rather than within this task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that sounds good - will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
...ls/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/UpdateNuGetConfigPackageSourcesMappings.cs
Show resolved
Hide resolved
|
||
if (!BuildWithOnlineFeeds) | ||
DiscoverPackagesFromAllSourceBuildSources(pkgSourcesElement, allSourcesPackages, currentPackages, referencePackages, previouslyBuiltPackages); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it would help the readability of this method to break it apart - it is around 130 lines. The three chucks are obvious targets to encapsulate in helper methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Yeah - I did some refactoring but stopped short. Wanted to get some early feedback, before refactoring some more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
How will this work when not building from source? I assume the SBRP logic will then get skipped? |
@NikolaMilosavljevic - would you mind sharing a few processed nuget.configs with this change. e.g. a repo w/existing mappings, a repo without, online, and offline? |
Yes, SBRP logic is conditioned on presence of SBRP cache source, which only exists for SBRP repo. |
|
The online configs that do not contain package source mappings do not look right to me. All online feeds need a packageSourceMapping added with a * package pattern. IIRC, without this, the online feeds will not be considered at all and therefore would break the build when prebuilts exist. |
} | ||
} | ||
|
||
throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, "Did not extract nuspec file from package: {0}", path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an exception in a try..catch is an anti-pattern and does not feed necessary here. This could be moved outside the try..catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
} | ||
} | ||
|
||
public class NupkgInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making a private nested type as it should not be used outside the task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f02bc9
Makes sense - I've missed this. Will update. Thanks! |
Fixed with 3f02bc9 |
...ls/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/UpdateNuGetConfigPackageSourcesMappings.cs
Outdated
Show resolved
Hide resolved
...ls/tasks/Microsoft.DotNet.SourceBuild.Tasks.XPlat/UpdateNuGetConfigPackageSourcesMappings.cs
Show resolved
Hide resolved
|
||
private void AddDefaultMappingsForOnlineSources(XElement pkgSrcMappingClearElement, XElement pkgSourcesElement) | ||
{ | ||
throw new NotImplementedException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional or an incomplete refactoring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not intentional - not used as I refactored it more. Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f458e5
|
||
private void AddToDictionary(Dictionary<string, List<string>> dictionary, string key, string value) | ||
{ | ||
if (dictionary.ContainsKey(key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TryGetValue looks to be a better choice here as it avoids indexing the dictionary multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix, for simpler code (one less line). Not sure about perf as TryGetValue
essentially invokes ContainsKey
and does the indexing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f458e5
} | ||
} | ||
|
||
private void GetExistingFilteredSourceMappings(XElement pkgSrcMappingElement, Dictionary<string, List<string>> currentPackages, Dictionary<string, List<string>> referencePackages, Dictionary<string, List<string>> previouslyBuiltPackages, Dictionary<string, List<string>> oldSourceMappingPatterns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is too long IMO.
private void GetExistingFilteredSourceMappings(XElement pkgSrcMappingElement, Dictionary<string, List<string>> currentPackages, Dictionary<string, List<string>> referencePackages, Dictionary<string, List<string>> previouslyBuiltPackages, Dictionary<string, List<string>> oldSourceMappingPatterns) | |
private void GetExistingFilteredSourceMappings( | |
XElement pkgSrcMappingElement, | |
Dictionary<string, List<string>> currentPackages, | |
Dictionary<string, List<string>> referencePackages, | |
Dictionary<string, List<string>> previouslyBuiltPackages, | |
Dictionary<string, List<string>> oldSourceMappingPatterns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f458e5
.Select(e => e.Attribute("pattern").Value) | ||
.Distinct() | ||
.ToArray(); | ||
var allSourcesPackages = new Dictionary<string, List<string>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider noting that not all these dictionaries contain the same type of value, consider calling it out here. What I am referring to is that all but the allSourcesPackages stores the versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 3f458e5
Online build is failing due to |
…eBuild.Tasks.XPlat/UpdateNuGetConfigPackageSourcesMappings.cs Co-authored-by: Michael Simons <msimons@microsoft.com>
Fixed with 3f458e5 |
.Where(e => e.Name == "add" && !allSourcesPackages.Keys.Contains(e.Attribute("key").Value)) | ||
.Select(e => e.Attribute("key").Value) | ||
.Distinct() | ||
.ToArray()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToArray is unnecessary overhead here isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops - you're right - will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 0a1e0b1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One minor comment. LGTM.
Setting |
Current error from nuget-client:
|
Yeah - have a fix - just pushed - b985bea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of my comments are just about maintainability. Feel free to defer those updates to address later in order to unblock things.
[Required] | ||
public string SbrpRepoSrcPath { get; set; } | ||
|
||
private const string SbrpCacheSourceName = "source-build-reference-package-cache"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be ideal if this could be passed in as a task property so it's shared with the value from here:
installer/src/SourceBuild/content/repo-projects/source-build-reference-packages.proj
Line 30 in 79f35dc
SourceName="source-build-reference-package-cache" |
private XElement GetPackageMappingsElementForSource(string packageSource) | ||
{ | ||
bool isCurrentSourceBuiltSource = | ||
packageSource.StartsWith("source-built-") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source-built-
string should be passed as a task property so it can be shared with the value from here:
<ShippingSourceName>source-built-%(Identity)</ShippingSourceName> |
bool isCurrentSourceBuiltSource = | ||
packageSource.StartsWith("source-built-") || | ||
packageSource.Equals(SbrpCacheSourceName) || | ||
packageSource.Equals("reference-packages"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment of using a task property to share with:
<ReferencePackagesNuGetSourceName>reference-packages</ReferencePackagesNuGetSourceName> |
if (packageSource.StartsWith("source-built-")) | ||
{ | ||
AddToDictionary(currentPackages, id, version); | ||
} | ||
else if (packageSource.Equals("reference-packages")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuse strings from task properties that I commented on.
Thanks - I'll create an issue to fix those in a follow-up PR. |
|
With latest changes to add mappings to online sources, PR validation checks are passing. Internal SB and UB pipelines are in progress. Some of the configs: |
foreach (string packageSource in allSourcesPackages.Keys) | ||
{ | ||
// Skip sources with zero package patterns | ||
if (allSourcesPackages[packageSource] != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the other occurrence of this comment, it used a pattern like allSourcesPackages[packageSource]?.Count > 0
to account for empty lists. Should that be used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments can be addressed in a follow-up PR. I think we should get this in ASAP to unblock Preview 3.
@@ -54,6 +54,8 @@ public class UpdateNuGetConfigPackageSourcesMappings : Task | |||
private Dictionary<string, List<string>> previouslyBuiltPackages = []; | |||
private Dictionary<string, List<string>> oldSourceMappingPatterns = []; | |||
|
|||
private string[] CustomSources = ["prebuilt", "net-sdk-supporting-feed"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private string[] CustomSources = ["prebuilt", "net-sdk-supporting-feed"]; | |
private readonly string[] CustomSources = ["prebuilt", "net-sdk-supporting-feed"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I question if prebuilt should be handled the same as net-sdk-supporting-feed. The prebuilt feed is a local feed which can be enumerated and have full packageIds added for each of it's packages. It should not have the cumulative list of PackageIDs added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense. It seemed that we should cover it when we discussed it yesterday, but it does not seem correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please open an issue to track this.
{ | ||
XElement pkgSrc = new XElement("packageSource", new XAttribute("key", packageSource)); | ||
foreach (string packagePattern in packagePatterns) | ||
if (oldSourceMappingPatterns.Count > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, this if condition seems unnecessary. It is adding unnecessary complexity and nesting, the foreach will no-op with an empty collection.
{ | ||
foreach (string sourceName in CustomSources) | ||
{ | ||
if (null != pkgSourcesElement.Descendants().FirstOrDefault(e => e.Name == "add" && e.Attribute("key").Value == sourceName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this logic is duplicated a number of times. Consider a lookup helper method.
/backport to release/9.0.1xx-preview3 |
Started backporting to release/9.0.1xx-preview3: https://github.com/dotnet/installer/actions/runs/8391929435 |
Fixes: dotnet/source-build#4206, dotnet/source-build#4229
Overview of changes:
nuget-client
patch that reverted root cause of non-determinism in package restore - Revert non-determinism in Nuget local sources #19074source-build-reference-package-cache
source utilized in SBRP repo build. Unlike all other sources, this one is dynamic and populated during SBRP repo build, with new packages as they get built. We need to update NuGet.config before repo build. Solution was to discover all packages that will be built by this repo, from all nuspec files in repo's sources.Package source mappings logic:
source-built-*
,reference-packages