-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix feature bands for side-by-side manifests #33937
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ namespace Microsoft.NET.Sdk.WorkloadManifestReader | |
| /// </remarks> | ||
| public class WorkloadResolver : IWorkloadResolver | ||
| { | ||
| private readonly Dictionary<string, WorkloadManifest> _manifests = new(StringComparer.OrdinalIgnoreCase); | ||
| private readonly Dictionary<string, (WorkloadManifest manifest, WorkloadManifestInfo info)> _manifests = new(StringComparer.OrdinalIgnoreCase); | ||
| private readonly Dictionary<WorkloadId, (WorkloadDefinition workload, WorkloadManifest manifest)> _workloads = new(); | ||
| private readonly Dictionary<WorkloadPackId, (WorkloadPack pack, WorkloadManifest manifest)> _packs = new(); | ||
| private IWorkloadManifestProvider? _manifestProvider; | ||
|
|
@@ -118,9 +118,10 @@ private void LoadManifestsFromProvider(IWorkloadManifestProvider manifestProvide | |
| using (Stream? localizationStream = readableManifest.OpenLocalizationStream()) | ||
| { | ||
| var manifest = WorkloadManifestReader.ReadWorkloadManifest(readableManifest.ManifestId, manifestStream, localizationStream, readableManifest.ManifestPath); | ||
| if (!_manifests.TryAdd(readableManifest.ManifestId, manifest)) | ||
| var manifestInfo = new WorkloadManifestInfo(manifest.Id, manifest.Version, readableManifest.ManifestDirectory, readableManifest.ManifestFeatureBand); | ||
| if (!_manifests.TryAdd(readableManifest.ManifestId, (manifest, manifestInfo))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be very unusual for readableManifest.ManifestId to already be in _manifests, correct? That seems like an install failure.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, something would be very wrong, probably a bug in the manifest provider. |
||
| { | ||
| var existingManifest = _manifests[readableManifest.ManifestId]; | ||
| var existingManifest = _manifests[readableManifest.ManifestId].manifest; | ||
| throw new WorkloadManifestCompositionException(Strings.DuplicateManifestID, manifestProvider.GetType().FullName, readableManifest.ManifestId, readableManifest.ManifestPath, existingManifest.ManifestPath); | ||
| } | ||
| } | ||
|
|
@@ -134,14 +135,15 @@ private void ComposeWorkloadManifests() | |
|
|
||
| Dictionary<WorkloadId, (WorkloadRedirect redirect, WorkloadManifest manifest)>? redirects = null; | ||
|
|
||
| foreach (var manifest in _manifests.Values) | ||
| foreach (var (manifest, info) in _manifests.Values) | ||
| { | ||
| if (manifest.DependsOnManifests != null) | ||
| { | ||
| foreach (var dependency in manifest.DependsOnManifests) | ||
| { | ||
| if (_manifests.TryGetValue(dependency.Key, out var resolvedDependency)) | ||
| if (_manifests.TryGetValue(dependency.Key, out var t)) | ||
| { | ||
| var resolvedDependency = t.manifest; | ||
| if (FXVersion.Compare(dependency.Value, resolvedDependency.ParsedVersion) > 0) | ||
| { | ||
| throw new WorkloadManifestCompositionException(Strings.ManifestDependencyVersionTooLow, dependency.Key, resolvedDependency.Version, dependency.Value, manifest.Id, manifest.ManifestPath); | ||
|
|
@@ -711,11 +713,17 @@ private bool IsWorkloadPlatformCompatible(WorkloadDefinition workload, WorkloadM | |
|
|
||
| private bool IsWorkloadImplicitlyAbstract(WorkloadDefinition workload, WorkloadManifest manifest) => !GetPacksInWorkload(workload, manifest).Any(); | ||
|
|
||
| public string GetManifestVersion(string manifestId) => | ||
| (_manifests.TryGetValue(manifestId, out WorkloadManifest? value)? value : null)?.Version | ||
| ?? throw new Exception($"Manifest with id {manifestId} does not exist."); | ||
| public string GetManifestVersion(string manifestId) | ||
| { | ||
| if (_manifests.TryGetValue(manifestId, out var value)) | ||
| { | ||
| return value.manifest.Version; | ||
| } | ||
| throw new Exception($"Manifest with id {manifestId} does not exist."); | ||
| } | ||
|
|
||
|
|
||
| public IEnumerable<WorkloadManifestInfo> GetInstalledManifests() => _manifests.Select(m => new WorkloadManifestInfo(m.Value.Id, m.Value.Version, Path.GetDirectoryName(m.Value.ManifestPath)!)); | ||
| public IEnumerable<WorkloadManifestInfo> GetInstalledManifests() => _manifests.Select(t => t.Value.info); | ||
| } | ||
|
|
||
| static class DictionaryExtensions | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,12 @@ public static WorkloadSet FromDictionaryForJson(IDictionary<string, string> dict | |
| public static WorkloadSet FromJson(string json, SdkFeatureBand defaultFeatureBand) | ||
| { | ||
| #if USE_SYSTEM_TEXT_JSON | ||
| return FromDictionaryForJson(JsonSerializer.Deserialize<IDictionary<string, string>>(json)!, defaultFeatureBand); | ||
| var jsonSerializerOptions = new JsonSerializerOptions() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should have a "standard" JsonSerializerOptions that we use everywhere to avoid forgetting AllowTrailingCommas. What do you think? |
||
| { | ||
| AllowTrailingCommas = true, | ||
| ReadCommentHandling = JsonCommentHandling.Skip | ||
| }; | ||
| return FromDictionaryForJson(JsonSerializer.Deserialize<IDictionary<string, string>>(json, jsonSerializerOptions)!, defaultFeatureBand); | ||
| #else | ||
| return FromDictionaryForJson(JsonConvert.DeserializeObject<IDictionary<string, string>>(json)!, defaultFeatureBand); | ||
| #endif | ||
|
|
||
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'm not 100% sure I understand the point of this change. It seems like it is trying to make it so you don't have to allocate a new WorkloadManifestInfo in the foreach loop...so is your goal just to move the allocations to all be before the loop?
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.
Previously it was just saving the path for each manifest and then creating the WorkloadManifestInfo at the end. But now we want to keep track of the feature band together with the manifest path, so it's easier to create the WorkloadManifestInfo with the feature band information when we find each manifest.