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

Use package source mappings in VMR build #19114

Merged
merged 7 commits into from
Mar 22, 2024

Conversation

NikolaMilosavljevic
Copy link
Member

Fixes: dotnet/source-build#4206, dotnet/source-build#4229

Overview of changes:

  • Remove temporary nuget-client patch that reverted root cause of non-determinism in package restore - Revert non-determinism in Nuget local sources #19074
  • Delete original SBRP packages after they get copied to reference packages dir
  • Add package source mappings for all source-build sources, following the logic in original issue - also explained below
  • In offline build, remove all existing package source mappings for online sources
  • In online build, filter existing package source mappings to remove anything that exists in any source-build source
  • Add package source mappings for source-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:

  • Add all packages from current source-build sources, i.e. source-built-*, reference-packages
  • For previously source-built sources, add only the packages that do not exist in any of the current source-built sources. Also add packages if PSB source contains a package version that does not exist in current package sources. (This was required for aspnetcore build, which brings transitive dependency on ILLink.Tasks package from PSB, via crossgen2 package dependency.)

@NikolaMilosavljevic NikolaMilosavljevic requested review from a team as code owners March 20, 2024 17:41
Copy link
Member

@ViktorHofer ViktorHofer left a 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.

Comment on lines 55 to 56
<!-- Delete the original SBRP packages -->
<RemoveDir Directories="$(PrebuiltSourceBuiltPackagesPath)SourceBuildReferencePackages" />
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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; }
Copy link
Member

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.

Copy link
Member Author

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";
Copy link
Member

@ViktorHofer ViktorHofer Mar 20, 2024

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.

Copy link
Member Author

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)" />
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed with 3f02bc9

Comment on lines 62 to 66
Hashtable allSourcesPackages = new Hashtable();
Hashtable currentPackages = new Hashtable();
Hashtable referencePackages = new Hashtable();
Hashtable previouslyBuiltPackages = new Hashtable();
Hashtable oldSourceMappingPatterns = new Hashtable();
Copy link
Member

@ViktorHofer ViktorHofer Mar 20, 2024

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.

Copy link
Member Author

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!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed with 3f02bc9

Comment on lines 220 to 223
if (string.IsNullOrEmpty(VmrRoot))
{
throw new InvalidDataException(string.Format(CultureInfo.CurrentCulture, "VmrRoot is not set - cannot determine SBRP packages."));
}
Copy link
Member

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.

Copy link
Member Author

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; }
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed with 3f02bc9


if (!BuildWithOnlineFeeds)
DiscoverPackagesFromAllSourceBuildSources(pkgSourcesElement, allSourcesPackages, currentPackages, referencePackages, previouslyBuiltPackages);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed with 3f02bc9

@ViktorHofer
Copy link
Member

How will this work when not building from source? I assume the SBRP logic will then get skipped?

@MichaelSimons
Copy link
Member

@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?

@NikolaMilosavljevic
Copy link
Member Author

How will this work when not building from source? I assume the SBRP logic will then get skipped?

Yes, SBRP logic is conditioned on presence of SBRP cache source, which only exists for SBRP repo.

@NikolaMilosavljevic
Copy link
Member Author

@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?

configs.zip

@MichaelSimons
Copy link
Member

@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?

configs.zip

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));
Copy link
Member

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

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed with 3f02bc9

@NikolaMilosavljevic
Copy link
Member Author

@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?

configs.zip

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.

Makes sense - I've missed this. Will update. Thanks!

@NikolaMilosavljevic
Copy link
Member Author

@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?

configs.zip

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.

Fixed with 3f02bc9


private void AddDefaultMappingsForOnlineSources(XElement pkgSrcMappingClearElement, XElement pkgSourcesElement)
{
throw new NotImplementedException();
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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))
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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)
Copy link
Member

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.

Suggested change
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)

Copy link
Member Author

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>>();
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed with 3f458e5

@NikolaMilosavljevic
Copy link
Member Author

Online build is failing due to vstest NuGet.config. Will have a fix shortly.

NikolaMilosavljevic and others added 2 commits March 21, 2024 09:17
…eBuild.Tasks.XPlat/UpdateNuGetConfigPackageSourcesMappings.cs

Co-authored-by: Michael Simons <msimons@microsoft.com>
@NikolaMilosavljevic
Copy link
Member Author

Online build is failing due to vstest NuGet.config. Will have a fix shortly.

Fixed with 3f458e5

.Where(e => e.Name == "add" && !allSourcesPackages.Keys.Contains(e.Attribute("key").Value))
.Select(e => e.Attribute("key").Value)
.Distinct()
.ToArray())
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed with 0a1e0b1

Copy link
Member

@MichaelSimons MichaelSimons left a 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.

@NikolaMilosavljevic
Copy link
Member Author

Setting DO NOT MERGE until all validations, including local and internal, are done and successful.

@mthalman
Copy link
Member

Current error from nuget-client:

  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.CommandLine.XPlat/NuGet.CommandLine.XPlat.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Credentials/NuGet.Credentials.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Common/NuGet.Common.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Build.Tasks/NuGet.Build.Tasks.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Packaging/NuGet.Packaging.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Configuration/NuGet.Configuration.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Build.Tasks.Console/NuGet.Build.Tasks.Console.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Commands/NuGet.Commands.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Resolver/NuGet.Resolver.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.DependencyResolver.Core/NuGet.DependencyResolver.Core.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Protocol/NuGet.Protocol.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Versioning/NuGet.Versioning.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.ProjectModel/NuGet.ProjectModel.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Frameworks/NuGet.Frameworks.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/Microsoft.Build.NuGetSdkResolver.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.LibraryModel/NuGet.LibraryModel.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Packaging.Core/NuGet.Packaging.Core.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.PackageManagement/NuGet.PackageManagement.csproj]
      0 Warning(s)
      19 Error(s)

@NikolaMilosavljevic
Copy link
Member Author

NikolaMilosavljevic commented Mar 21, 2024

Current error from nuget-client:

  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.CommandLine.XPlat/NuGet.CommandLine.XPlat.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Credentials/NuGet.Credentials.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Common/NuGet.Common.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Build.Tasks/NuGet.Build.Tasks.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Packaging/NuGet.Packaging.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Configuration/NuGet.Configuration.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Build.Tasks.Console/NuGet.Build.Tasks.Console.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Commands/NuGet.Commands.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Resolver/NuGet.Resolver.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.DependencyResolver.Core/NuGet.DependencyResolver.Core.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Protocol/NuGet.Protocol.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Versioning/NuGet.Versioning.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.ProjectModel/NuGet.ProjectModel.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Frameworks/NuGet.Frameworks.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/Microsoft.Build.NuGetSdkResolver/Microsoft.Build.NuGetSdkResolver.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.LibraryModel/NuGet.LibraryModel.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.Packaging.Core/NuGet.Packaging.Core.csproj]
  /vmr/.dotnet/sdk/9.0.100-preview.2.24103.2/NuGet.targets(694,5): error : Package source 'dotnet-libraries' must have at least one package pattern. Path: '/vmr/artifacts/obj/nuget-client/NuGet.Config' [/vmr/src/nuget-client/src/NuGet.Core/NuGet.PackageManagement/NuGet.PackageManagement.csproj]
      0 Warning(s)
      19 Error(s)

Yeah - have a fix - just pushed - b985bea

Copy link
Member

@mthalman mthalman left a 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";
Copy link
Member

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:

SourceName="source-build-reference-package-cache"

private XElement GetPackageMappingsElementForSource(string packageSource)
{
bool isCurrentSourceBuiltSource =
packageSource.StartsWith("source-built-") ||
Copy link
Member

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");
Copy link
Member

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>

Comment on lines +217 to +221
if (packageSource.StartsWith("source-built-"))
{
AddToDictionary(currentPackages, id, version);
}
else if (packageSource.Equals("reference-packages"))
Copy link
Member

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.

@NikolaMilosavljevic
Copy link
Member Author

All of my comments are just about maintainability. Feel free to defer those updates to address later in order to unblock things.

Thanks - I'll create an issue to fix those in a follow-up PR.

@NikolaMilosavljevic
Copy link
Member Author

All of my comments are just about maintainability. Feel free to defer those updates to address later in order to unblock things.

Thanks - I'll create an issue to fix those in a follow-up PR.

dotnet/source-build#4242

@NikolaMilosavljevic
Copy link
Member Author

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:
configs.zip
ub* files are for unified-build, to test the custom feed.

foreach (string packageSource in allSourcesPackages.Keys)
{
// Skip sources with zero package patterns
if (allSourcesPackages[packageSource] != null)
Copy link
Member

@mthalman mthalman Mar 22, 2024

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?

Copy link
Member

@MichaelSimons MichaelSimons left a 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"];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private string[] CustomSources = ["prebuilt", "net-sdk-supporting-feed"];
private readonly string[] CustomSources = ["prebuilt", "net-sdk-supporting-feed"];

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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)
Copy link
Member

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))
Copy link
Member

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.

@NikolaMilosavljevic NikolaMilosavljevic merged commit 049c92b into dotnet:main Mar 22, 2024
22 checks passed
@NikolaMilosavljevic
Copy link
Member Author

/backport to release/9.0.1xx-preview3

Copy link

Started backporting to release/9.0.1xx-preview3: https://github.com/dotnet/installer/actions/runs/8391929435

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.

NuGet feed non-determinism is preventing correct source build behavior
4 participants