-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Issue #33697] New standalone info
command
#36943
base: release/8.0.2xx
Are you sure you want to change the base?
[Issue #33697] New standalone info
command
#36943
Conversation
Hi @Markliniubility - thanks for your interest in this! I can't take a look in depth at this right now due to conference activities, but I hope to get to it early next week. Sorry for the delay there. |
cmd.Should().Pass(); | ||
cmd.StdOut.Should().MatchRegex(InfoTextRegex); |
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.
consider using Verify for these tests so you can ensure that the entire format doesn't change without having to keep big literal strings in source code.
Assert.True(parsedJson[Sdk].Type == JTokenType.Object, "SDK should be an object."); | ||
Assert.True(parsedJson[RuntimeEnv].Type == JTokenType.Object, "RuntimeEnvironment should be an object."); | ||
Assert.True(parsedJson[Workloads].Type == JTokenType.Array, "Workloads should be an array."); | ||
} |
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.
same here - let Verify handle JSON diffing for you
Reporter.Output.WriteLine($" OS Platform: {RuntimeEnvironment.OperatingSystemPlatform}"); | ||
Reporter.Output.WriteLine($" RID: {GetDisplayRid(versionFile)}"); | ||
Reporter.Output.WriteLine($" Base Path: {AppContext.BaseDirectory}"); | ||
PrintWorkloadsInfo(); |
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.
This is a great start! I would love to see the information that the dotnet
host provides here as well. In the current dotnet --info
command that's the
- Host,
- .NET SDKs installed,
- .NET runtimes installed,
- Other architectures found,
- Environment Variables, and
- global.json file
sections. Especially the SDKs/Runtimes sections in a parseable format would be useful for folks.
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.
Thank you for the feedback and apologies for the late response! I was exploring how to integrate the information into the new info command. I realized that the existing --info
command have these information hard coded for printing in some C++ files in dotnet/runtime
.
Though we have ways to acquire information about SDKs installed and runtimes installed from the dotnet/runtime C++ files: Interop.cs
, as currently, I didn't find ways to acquire Host and Other architectures file information within dotnet/sdk
. Therefore, A new standalone info command may need to make modifications to the dotnet/runtime
project in this file, by adding get_environmental_variable, get_host_info, get_global_json functions.
If you happen to know any other way to get host information without making modifications to dotnet/runtime
, or any existing methods within dotnet/sdk
to get those information, it would be really helpful. Making changes to dotnet/runtime
, which involves complex and low-level C++ code, is a significant undertaking and difficult to debug with.
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.
Options:
- Expose the missing pieces of information from corehost so SDK can utilize it via interop for this new command.
- We are currently using RapidJSON in corehost to parse runtime json files. We can use it to emit info in JSON format when -f json arg (or any of its variants; --format json, --format=json) is set in a separate function like
print_muxer_info_json
, which will inject the host-specific parts (not very clean solution but doable..) - Without changing the corehost; spawn a process with
unset unset DOTNET_ROOT; dotnet --info
command, capture and parse result, convert to JSON and print. (worse than#2
because process spawning is expensive and not provided by all supported platforms)
I think the first option is preferred, but I will defer to @elinor-fung and @vitek-karas. Lets hear their thoughts. :)
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.
^^
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 would prefer to do everything in managed code - we've discussed this in the past and the consensus was that the current design where part of the output is produced by the managed code and part of it is from native code is not what we want. Some of the downsides:
- It produces partially localized output - the host parts are not localized (ever), while the SDK parts are.
- It's complex to maintain (and confusing to work on).
As to what mechanism to use to expose the necessary information to managed code:
- Introduce a new
hostfxr
API - or rather modify the existing. Effectively modify this struct to include the necessary info: https://github.com/dotnet/runtime/blob/c28bec4d3d63849c9e60dee1e7174b9a180a7e55/src/native/corehost/hostfxr.h#L311-L323. - Expose this information as runtime properties. This would have to use the new "on demand" runtime properties which are not yet wired to
AppContext.GetData
, so that would have to be added as well.
Personally - this feels more aligned with the hostfxr_dotnet_environment_info
. But I don't feel strongly either way.
versionFile.BuildRid; | ||
} | ||
|
||
public class RuntimeEnvironmentInfo |
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'd put these classes that define the JSON model in a separate file.
|
||
public class RuntimeEnvironmentInfo | ||
{ | ||
public string Name { get; set; } |
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.
Please use JsonPropertyName to set the camelCase name style defined in baronfel's original issue.
Thank you all for the comments! Working on it now and hopefully I will finish addressing them by early next week |
|
||
public string ToJson() | ||
{ | ||
return JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true }); |
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.
For this relatively simple JSON content personally I would go with just Utf8JsonWriter
. Maintaining the classes just for serialization feels like an overkill (and it will need lot of attributes to change the property names to camel case and so on).
There's also a performance consideration. Currently this uses reflection based serialization which brings in a lot of dependencies on the reflection stack which is pretty expensive. Since we're writing this as new code, we should try to make it better than that. If you decide to still go with object based serialization, then this should use the source generator. If you go with the direct JSON writer approach the problem goes away as well.
Two general comments: JSON Format No-SDK @baronfel, @elinor-fung for opinions and thoughts... |
This is a good point. In the (recent) past, there were changes made in the output of This new command can provide a strong contract (spec, tests, versioning etc.) and maintain compatibility within the implementation, while |
Personally, I would like to keep the format of |
Agree in general with @vitek-karas - this new endpoint would become the documented, compatible-across-releases way to get structured information about your SDK environment. We should ask the host team to add any endpoints required to achieve data parity with |
Do you know how that interaction works with the CLI in this repo? I'm wondering... does the dotnet host ignore everything else when |
@MiYanni when Otherwise the Host calls the The host is only comparing via the first argument here, so theoretically new options/arguments could be added to |
I'm sorry - I missed that this is Now that I know that... honestly I would prefer if we made these changes to
The host recognizes |
Yes, this 50-50 split in writing to console (first from C# then from C++) as part of executing |
I think we should do this - it would require some versioning magic but that doable (the host has to work against any SDK, so it would have to know to do the old thing for the old SDK and the new thing for the new SDK and unfortunately this can't be done through an API since the host literally runs the SDK as an app).
Tentative yes - this is hostfxr, so size is not really a big concern (although self-contained apps would pay it without a need unfortunately). As you said we would have to spec it out and have some kind of validation to keep the host and SDK in sync on the format. |
In the SDK CLI syntax, the command would be |
Therefore, correct me if I am wrong, here are some steps we need to implement this new standalone info command.
As for now, shall I wait for the completion of 1 by corehost team, or shall I look into the corehost and potentially submit a PR (which I am not very certain how to make the versioning magic work..) |
We'd be happy to accept a PR for this in the corehost, but I agree that there's some design work to be done first. I think a good start would be to open an issue in the runtime repo to discuss how to expose the additional information (should be relatively simple API change), and then another one how to avoid producing the "host" part of Please be patient with us for the next 2 weeks as lot of people are on holidays. |
Sorry for the delay (I was quite unsure about what to change in the runtime codebase and how to test my change): I just brought up the issues in dotnet runtime. dotnet/runtime#98735. |
I really like how |
Old PR triage: @baronfel not sure where we landed with having a separate command here. |
We do want this separate command, but the linked runtime issue needs to be fleshed out to fully replace --info with this more full-featured command. |
#33697 @baronfel
Demo as below. Happy to discuss if there is any change needed: