-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable "portable" RID graph when targeting .NET 8 and higher (#34279)
- Loading branch information
Showing
15 changed files
with
648 additions
and
25 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Layout/toolset-tasks/UpdatePortableRuntimeIdentifierGraph.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Microsoft.DotNet.Cli.Build | ||
{ | ||
public class UpdatePortableRuntimeIdentifierGraph : Task | ||
{ | ||
[Required] | ||
public string InputFile { get; set; } | ||
|
||
[Required] | ||
public string OutputFile { get; set; } | ||
|
||
|
||
// ItemSpec should be a RID, and "Imports" metadata should be a semicolon-separated list of RIDs that the ItemSpec RID imports | ||
public ITaskItem[] AdditionalRuntimeIdentifiers { get; set; } | ||
|
||
public override bool Execute() | ||
{ | ||
JToken json; | ||
|
||
using (var file = File.OpenText(InputFile)) | ||
using (JsonTextReader reader = new JsonTextReader(file)) | ||
{ | ||
json = JObject.ReadFrom(reader); | ||
} | ||
|
||
JObject runtimes = (JObject) json["runtimes"]; | ||
|
||
if (AdditionalRuntimeIdentifiers != null) | ||
{ | ||
foreach (var rid in AdditionalRuntimeIdentifiers) | ||
{ | ||
var importedRids = rid.GetMetadata("Imports").Split(';'); | ||
runtimes.Add(rid.ItemSpec, new JObject(new JProperty("#import", new JArray(importedRids)))); | ||
} | ||
} | ||
|
||
using (var file = File.CreateText(OutputFile)) | ||
using (var writer = new JsonTextWriter(file) { Formatting = Formatting.Indented }) | ||
{ | ||
json.WriteTo(writer); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/Tests/Microsoft.NET.Build.Tests/RuntimeIdentifierGraphTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.NET.TestFramework; | ||
using Microsoft.NET.TestFramework.Assertions; | ||
using Microsoft.NET.TestFramework.Commands; | ||
using Microsoft.NET.TestFramework.ProjectConstruction; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.NET.Build.Tests | ||
{ | ||
public class RuntimeIdentifierGraphTests : SdkTest | ||
{ | ||
public RuntimeIdentifierGraphTests(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[InlineData("net7.0", null, true)] | ||
[InlineData("net8.0", null, false)] | ||
[InlineData("net7.0", "false", false)] | ||
[InlineData("net8.0", "true", true)] | ||
public void ItUsesCorrectRuntimeIdentifierGraph(string targetFramework, string useRidGraphValue, bool shouldUseFullRidGraph) | ||
{ | ||
var testProject = new TestProject() | ||
{ | ||
TargetFrameworks = targetFramework, | ||
IsExe = true | ||
}; | ||
|
||
if (useRidGraphValue != null) | ||
{ | ||
testProject.AdditionalProperties["UseRidGraph"] = useRidGraphValue; | ||
} | ||
|
||
testProject.RecordProperties("RuntimeIdentifierGraphPath"); | ||
|
||
var testAsset = _testAssetsManager.CreateTestProject(testProject, identifier: targetFramework + "_" + (useRidGraphValue ?? "null")); | ||
|
||
var buildCommand = new BuildCommand(testAsset); | ||
|
||
buildCommand.Execute() | ||
.Should() | ||
.Pass(); | ||
|
||
var runtimeIdentifierGraphPath = testProject.GetPropertyValues(testAsset.TestRoot)["RuntimeIdentifierGraphPath"]; | ||
|
||
if (shouldUseFullRidGraph) | ||
{ | ||
Path.GetFileName(runtimeIdentifierGraphPath).Should().Be("RuntimeIdentifierGraph.json"); | ||
} | ||
else | ||
{ | ||
Path.GetFileName(runtimeIdentifierGraphPath).Should().Be("PortableRuntimeIdentifierGraph.json"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters