public static string GetBestMatchingRidWithExclusion(RuntimeGraph runtimeGraph, string runtimeIdentifier, IEnumerable <string> runtimeIdentifiersToExclude, IEnumerable <string> availableRuntimeIdentifiers, out bool wasInGraph) { wasInGraph = runtimeGraph.Runtimes.ContainsKey(runtimeIdentifier); string bestMatch = null; HashSet <string> availableRids = new HashSet <string>(availableRuntimeIdentifiers, StringComparer.Ordinal); HashSet <string> excludedRids = runtimeIdentifiersToExclude switch { null => null, _ => new HashSet <string>(runtimeIdentifiersToExclude, StringComparer.Ordinal) }; foreach (var candidateRuntimeIdentifier in runtimeGraph.ExpandRuntime(runtimeIdentifier)) { if (bestMatch == null && availableRids.Contains(candidateRuntimeIdentifier)) { bestMatch = candidateRuntimeIdentifier; } if (excludedRids != null && excludedRids.Contains(candidateRuntimeIdentifier)) { // Don't treat this as a match return(null); } } return(bestMatch); } }
public void FindRuntimeDependencies_VerifyExpandOrderForTree3() { // C // - B // --- A // - F // --- E // ----- D // --- EE // ----- DD // - X // --- Y // ----- Z var graph = new RuntimeGraph(new[] { new RuntimeDescription("a"), new RuntimeDescription("d"), new RuntimeDescription("y", new[] { "z" }), new RuntimeDescription("x", new[] { "y" }), new RuntimeDescription("b", new[] { "a" }), new RuntimeDescription("e", new[] { "d" }), new RuntimeDescription("ee", new[] { "dd" }), new RuntimeDescription("f", new[] { "e", "ee" }), new RuntimeDescription("c", new[] { "b", "f", "x" }), }); var expected = new[] { "c", "b", "f", "x", "a", "e", "ee", "y", "d", "dd" }; var actual = graph.ExpandRuntime("c").ToArray(); for (var i = 0; i < expected.Length; i++) { Assert.Equal(expected[i], actual[i]); } }
private static void WriteCompatibilityMap(RuntimeGraph graph, string mapFile) { Dictionary <string, IEnumerable <string> > compatibilityMap = new Dictionary <string, IEnumerable <string> >(); foreach (var rid in graph.Runtimes.Keys.OrderBy(rid => rid, StringComparer.Ordinal)) { compatibilityMap.Add(rid, graph.ExpandRuntime(rid)); } var serializer = new JsonSerializer() { Formatting = Formatting.Indented, StringEscapeHandling = StringEscapeHandling.EscapeNonAscii }; string directory = Path.GetDirectoryName(mapFile); if (!String.IsNullOrEmpty(directory) && !Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (var file = File.CreateText(mapFile)) { serializer.Serialize(file, compatibilityMap); } }
public void FindRuntimeDependencies_VerifyExpandCaching() { var graph = new RuntimeGraph(new[] { new RuntimeDescription("a"), new RuntimeDescription("d"), new RuntimeDescription("b", new[] { "a" }), new RuntimeDescription("e", new[] { "d" }), new RuntimeDescription("f", new[] { "e" }), new RuntimeDescription("c", new[] { "b", "f" }), }); var a = graph.ExpandRuntime("c"); var b = graph.ExpandRuntime("c"); ReferenceEquals(a, b).Should().BeTrue(); }
public IEnumerable <RuntimeFallbacks> Expand(RuntimeGraph runtimeGraph, string runtime) { var importers = FindImporters(runtimeGraph, runtime); foreach (var importer in importers) { // ExpandRuntime return runtime itself as first item so we are skiping it yield return(new RuntimeFallbacks(importer, runtimeGraph.ExpandRuntime(importer).Skip(1))); } }
private static IDictionary <string, IEnumerable <string> > GetCompatibilityMap(RuntimeGraph graph) { Dictionary <string, IEnumerable <string> > compatibilityMap = new Dictionary <string, IEnumerable <string> >(); foreach (var rid in graph.Runtimes.Keys.OrderBy(rid => rid, StringComparer.Ordinal)) { compatibilityMap.Add(rid, graph.ExpandRuntime(rid)); } return(compatibilityMap); }
private IEnumerable <string> FindImporters(RuntimeGraph runtimeGraph, string runtime) { foreach (var runtimePair in runtimeGraph.Runtimes) { var expanded = runtimeGraph.ExpandRuntime(runtimePair.Key); if (expanded.Contains(runtime)) { yield return(runtimePair.Key); } } }
private IEnumerable<string> FindImporters(RuntimeGraph runtimeGraph, string runtime) { foreach (var runtimePair in runtimeGraph.Runtimes) { var expanded = runtimeGraph.ExpandRuntime(runtimePair.Key); if (expanded.Contains(runtime)) { yield return runtimePair.Key; } } }
public void ExpandRuntimes_VerifyChain() { var graph = new RuntimeGraph(new[] { new RuntimeDescription("a"), new RuntimeDescription("b", new[] { "a" }), new RuntimeDescription("c", new[] { "b" }), new RuntimeDescription("d", new[] { "c" }) }); graph.ExpandRuntime("d").Should().BeEquivalentTo(new[] { "d", "c", "b", "a" }); }
public IEnumerable<RuntimeFallbacks> Expand(RuntimeGraph runtimeGraph, IEnumerable<string> runtimes) { foreach (var runtime in runtimes) { var importers = FindImporters(runtimeGraph, runtime); foreach (var importer in importers) { // ExpandRuntime return runtime itself as first item so we are skiping it yield return new RuntimeFallbacks(importer, runtimeGraph.ExpandRuntime(importer).Skip(1)); } } }
public void ExpandShouldExpandRuntimeBasedOnGraph(string start, string expanded) { var graph = new RuntimeGraph(new[] { new RuntimeDescription("win8-x86", new[] { "win8", "win7-x86" }), new RuntimeDescription("win8", new[] { "win7" }), new RuntimeDescription("win7-x86", new[] { "win7" }), new RuntimeDescription("win7"), }); Assert.Equal( expanded.Split(','), graph.ExpandRuntime(start).ToArray()); }
public static string GetBestMatchingRid(RuntimeGraph runtimeGraph, string runtimeIdentifier, IEnumerable <string> availableRuntimeIdentifiers, out bool wasInGraph) { wasInGraph = runtimeGraph.Runtimes.ContainsKey(runtimeIdentifier); HashSet <string> availableRids = new HashSet <string>(availableRuntimeIdentifiers); foreach (var candidateRuntimeIdentifier in runtimeGraph.ExpandRuntime(runtimeIdentifier)) { if (availableRids.Contains(candidateRuntimeIdentifier)) { return(candidateRuntimeIdentifier); } } // No compatible RID found in availableRuntimeIdentifiers return(null); }
private static IEnumerable <RuntimeFallbacks> GetRuntimeFallbacks(string[] runtimeGraphFiles, string runtime) { RuntimeGraph runtimeGraph = RuntimeGraph.Empty; foreach (string runtimeGraphFile in runtimeGraphFiles) { runtimeGraph = RuntimeGraph.Merge(runtimeGraph, JsonRuntimeFormat.ReadRuntimeGraph(runtimeGraphFile)); } foreach (string rid in runtimeGraph.Runtimes.Select(p => p.Key)) { IEnumerable <string> ridFallback = runtimeGraph.ExpandRuntime(rid); if (ridFallback.Contains(runtime)) { // ExpandRuntime return runtime itself as first item so we are skiping it yield return(new RuntimeFallbacks(rid, ridFallback.Skip(1))); } } }
public override bool Execute() { var target = new TargetInfo(TargetFrameworkMoniker, RuntimeIdentifier, string.Empty, isPortable: false); var runtimeFiles = new List <RuntimeFile>(); var nativeFiles = new List <RuntimeFile>(); var resourceAssemblies = new List <ResourceAssembly>(); foreach (var file in Files) { if (!string.IsNullOrEmpty(file.GetMetadata("GeneratedBuildFile"))) { continue; } string filePath = file.ItemSpec; string fileName = Path.GetFileName(filePath); string fileVersion = FileUtilities.GetFileVersion(filePath)?.ToString() ?? string.Empty; Version assemblyVersion = FileUtilities.GetAssemblyName(filePath)?.Version; string cultureMaybe = file.GetMetadata("Culture"); if (!string.IsNullOrEmpty(cultureMaybe)) { resourceAssemblies.Add(new ResourceAssembly(Path.Combine(cultureMaybe, fileName), cultureMaybe)); } else if (assemblyVersion == null) { var nativeFile = new RuntimeFile(fileName, null, fileVersion); nativeFiles.Add(nativeFile); } else { var runtimeFile = new RuntimeFile(fileName, fileVersion: fileVersion, assemblyVersion: assemblyVersion.ToString()); runtimeFiles.Add(runtimeFile); } } var runtimeLibrary = new RuntimeLibrary("package", SharedFrameworkPackName, Version, hash: string.Empty, runtimeAssemblyGroups: new[] { new RuntimeAssetGroup(string.Empty, runtimeFiles) }, nativeLibraryGroups: new[] { new RuntimeAssetGroup(string.Empty, nativeFiles) }, resourceAssemblies, Array.Empty <Dependency>(), hashPath: null, path: $"{SharedFrameworkPackName.ToLowerInvariant()}/{Version}", serviceable: true); IEnumerable <RuntimeFallbacks> runtimeFallbackGraph = Array.Empty <RuntimeFallbacks>(); if (IncludeFallbacksInDepsFile) { RuntimeGraph runtimeGraph = JsonRuntimeFormat.ReadRuntimeGraph(RuntimeIdentifierGraph); runtimeFallbackGraph = runtimeGraph.Runtimes .Select(runtimeDict => runtimeGraph.ExpandRuntime(runtimeDict.Key)) .Where(expansion => expansion.Contains(RuntimeIdentifier)) .Select(expansion => new RuntimeFallbacks(expansion.First(), expansion.Skip(1))); // ExpandRuntime return runtime itself as first item. } var context = new DependencyContext(target, CompilationOptions.Default, Enumerable.Empty <CompilationLibrary>(), new[] { runtimeLibrary }, runtimeFallbackGraph); var depsFileName = string.IsNullOrEmpty(SharedFrameworkDepsNameOverride) ? $"{SharedFrameworkName}.deps.json" : $"{SharedFrameworkDepsNameOverride}.deps.json"; var depsFilePath = Path.Combine(IntermediateOutputPath, depsFileName); try { using var depsStream = File.Create(depsFilePath); new DependencyContextWriter().Write(context, depsStream); GeneratedDepsFile = new TaskItem(depsFilePath); } catch (Exception ex) { // If there is a problem, ensure we don't write a partially complete version to disk. if (File.Exists(depsFilePath)) { File.Delete(depsFilePath); } Log.LogErrorFromException(ex, false); return(false); } return(true); }
public void ExpandRuntimes_UnknownRuntimeVerifySelf() { var graph = new RuntimeGraph(); graph.ExpandRuntime("x").Should().BeEquivalentTo(new[] { "x" }); }