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

[mono] new Sdk that selects mono runtime components #54432

Merged
49 commits merged into from
Jul 8, 2021
Merged
Changes from 2 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5bab843
Work in progress: new Sdk that selects mono runtime components
lambdageek Jun 18, 2021
fad6101
Add props and targets description to the components doc
lambdageek Jun 21, 2021
cb34023
condition the _MonoRuntimeAvailableComponents by RuntimeIdentifier
lambdageek Jun 22, 2021
efc5caf
[cmake] Write a component-manifest.props file during build
lambdageek Jun 23, 2021
d974927
Build Microsoft.NETCore.App.Runtime.Mono.<RID>.Sdk shared framework n…
lambdageek Jun 23, 2021
cc468e3
put the compoonent-manifest.targets into the Sdk
lambdageek Jun 23, 2021
d5aae8f
delete WIP in mono/nuget/
lambdageek Jun 23, 2021
b213b70
fixup static component names in component-manifest.targets
lambdageek Jun 23, 2021
731a419
delete fixed fixme
lambdageek Jun 23, 2021
82dd4f2
add missing $
lambdageek Jun 23, 2021
a0a3803
fix whitespace
lambdageek Jun 23, 2021
a440aa2
[cmake] switch to configure_file instead of file(CONFIGURE)
lambdageek Jun 23, 2021
434a38b
add missing trailing slashes in .props.in file
lambdageek Jun 23, 2021
71c2376
Add new Sdk packs to the workload manifest
lambdageek Jun 23, 2021
3fe371b
rework component-manifest.targets to use ItemGroups; move to new SDK
lambdageek Jun 25, 2021
d3bc250
Rename shared framework to Microsoft.NETCore.App.Runtime.Mono.<RID>.P…
lambdageek Jun 25, 2021
8b5fd0a
Update manifest to include the new Props.Sdk and MonoTargets.Sdk
lambdageek Jun 25, 2021
dd03117
Move RuntimeConfigParserTask into Microsoft.NET.Runtime.MonoTargets.Sdk
lambdageek Jun 25, 2021
12cd2a6
Add iossimulator-x86 props
lambdageek Jun 25, 2021
e6651b2
update components design doc
lambdageek Jun 25, 2021
8d1e674
Fix typo
lambdageek Jun 29, 2021
b9be77f
improve docs
lambdageek Jun 29, 2021
db6a828
Add _MonoRuntimeComponentDontLink target output
lambdageek Jun 29, 2021
5c88b3e
Drop component-manifest.props into runtime pack build/ directory
lambdageek Jun 30, 2021
8a791ea
remove Microsoft.NETCore.App.Mono.Props.Sdk
lambdageek Jun 30, 2021
016c88a
Import component-manifest.props from the runtime pack
lambdageek Jun 30, 2021
49f5a65
Fix typos
lambdageek Jun 30, 2021
66b33df
Apply suggestions from code review
lambdageek Jul 2, 2021
a217d4e
Add JsonToItemsTaskFactory
lambdageek Jul 2, 2021
c3cee96
fix whitespace
lambdageek Jul 2, 2021
438f3ec
Do some validation earlier in _MonoComputeAvailableComponentDefinitions
lambdageek Jul 2, 2021
29420e2
Read component-manifest.json using the JsonToItemsTaskFactory
lambdageek Jul 2, 2021
58015a0
remove ResolvedRuntimePack import from WorkloadManifest.targets
lambdageek Jul 2, 2021
d3071da
Generate component-manifest.json in CMakeLists.txt
lambdageek Jul 2, 2021
756e5a6
Fix some copy-paste nits
lambdageek Jul 2, 2021
372df69
Use RuntimeFlavor==mono for runtime pack build directory
lambdageek Jul 7, 2021
2cc01b6
Apply suggestions from code review
lambdageek Jul 7, 2021
065a2bb
rename component-manifest to RuntimeComponentManifest
lambdageek Jul 7, 2021
6957bcc
fixup nullability annotations
lambdageek Jul 7, 2021
dae9aeb
fix whitespace
lambdageek Jul 7, 2021
d5e6f0e
fix formatting
lambdageek Jul 7, 2021
eb0d0d4
Misc fixes to JsonToItemsTaskFactory
lambdageek Jul 7, 2021
4874bd4
Rename MonoRuntimeComponentManifestReadTask
lambdageek Jul 7, 2021
011e7ab
undo nullability annotation
lambdageek Jul 7, 2021
c332f7b
fix incorrect task parameter name
lambdageek Jul 7, 2021
7d6ca6d
Remove Identity metadata from dictionary at json parsing time
lambdageek Jul 7, 2021
174065e
Throw correct json deserializer exceptions
lambdageek Jul 7, 2021
5ffc175
Catch JsonException in an async function
lambdageek Jul 7, 2021
6213067
fixup comments
lambdageek Jul 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/tasks/JsonToItemsTaskFactory/JsonToItemsTaskFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
Expand Down Expand Up @@ -198,10 +199,11 @@ public bool TryGetJson(string jsonFilePath, [NotNullWhen(true)] out JsonModelRoo
json = null;
return false;
}
json = JsonSerializer.DeserializeAsync<JsonModelRoot>(file, JsonOptions).AsTask().Result;
json = GetJsonAsync(jsonFilePath, file).Result;
if (json == null)
{
Log.LogError($"Failed to deserialize json from file {jsonFilePath}");
// the async task may have already caught an exception and logged it.
if (!Log.HasLoggedErrors) Log.LogError($"Failed to deserialize json from file {jsonFilePath}");
return false;
}
return true;
Expand All @@ -213,6 +215,21 @@ public bool TryGetJson(string jsonFilePath, [NotNullWhen(true)] out JsonModelRoo
}
}

public async Task<JsonModelRoot?> GetJsonAsync(string jsonFilePath, FileStream file)
{
JsonModelRoot? json = null;
try
{
json = await JsonSerializer.DeserializeAsync<JsonModelRoot>(file, JsonOptions).ConfigureAwait(false);
}
catch (JsonException e)
{
Log.LogError($"Failed to deserialize json from file '{jsonFilePath}', JSON Path: {e.Path}, Line: {e.LineNumber}, Position: {e.BytePositionInLine}");
Log.LogErrorFromException(e, showStackTrace: false, showDetail: true, file: null);
}
return json;
}

internal void LogParsedJson (JsonModelRoot json)
radical marked this conversation as resolved.
Show resolved Hide resolved
{
if (json.Properties != null)
Expand Down Expand Up @@ -353,20 +370,20 @@ public override JsonModelItem Read(ref Utf8JsonReader reader, Type typeToConvert
case JsonTokenType.String:
var stringItem = reader.GetString();
if (string.IsNullOrEmpty(stringItem))
throw new Exception ("deserialized json string item was null or the empty string");
throw new JsonException ("deserialized json string item was null or the empty string");
return new JsonModelItem(stringItem!, metadata: null);
case JsonTokenType.StartObject:
var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(ref reader, options);
if (dict == null)
return null!;
var idict = new Dictionary<string, string> (dict, StringComparer.OrdinalIgnoreCase);
if (!idict.TryGetValue("Identity", out var identity) || string.IsNullOrEmpty(identity))
throw new Exception ("deserialized json dictionary item did not have a non-empty Identity metadata");
throw new JsonException ("deserialized json dictionary item did not have a non-empty Identity metadata");
else
idict.Remove("Identity");
return new JsonModelItem(identity, metadata: idict);
default:
throw new Exception();
throw new NotSupportedException();
Copy link
Member

Choose a reason for hiding this comment

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

token type in the message might be useful for debugging

Copy link
Member Author

Choose a reason for hiding this comment

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

The JsonSerializer catches and decorates NotSupportedException with location and type info https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-converters-how-to?pivots=dotnet-5-0#notsupportedexception

}
}
public override void Write(Utf8JsonWriter writer, JsonModelItem value, JsonSerializerOptions options)
Expand Down