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

macOS: Show correct arm64 architecture #320

Merged
merged 7 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/LocalizableStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
<value>Uninstalling: {0}.</value>
</data>
<data name="MacOsBundleDisplayNameFormat" xml:space="preserve">
<value>Microsoft .NET Core {0} {1} (x64)</value>
<value>Microsoft .NET Core {0} {1} ({2})</value>
</data>
<data name="CancelingMessage" xml:space="preserve">
<value>Canceling: waiting for the current uninstall to complete.</value>
Expand Down Expand Up @@ -390,4 +390,4 @@ Warning: {0}: {1}
Uninstalling this item will cause Visual Studio for to break.
</value>
</data>
</root>
</root>
39 changes: 18 additions & 21 deletions src/dotnet-core-uninstall/MacOs/FileSystemExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,40 @@ internal class FileSystemExplorer : IBundleCollector

public virtual IEnumerable<Bundle> GetAllInstalledBundles()
{
var nativeArch = IsMacx64Installation(DotNetInstallPath) ? BundleArch.X64 : BundleArch.Arm64;
var sdks = GetInstalledBundles<SdkVersion>(nativeArch, DotNetSdkInstallPath(DotNetInstallPath));
var sdks = GetInstalledBundles<SdkVersion>(DotNetSdkInstallPath(DotNetInstallPath));
var runtimes = GetInstalledBundles<RuntimeVersion>(
nativeArch,
DotNetRuntimeInstallPath(DotNetInstallPath),
DotNetAspAllInstallPath(DotNetInstallPath),
DotNetAspAppInstallPath(DotNetInstallPath),
DotNetHostFxrInstallPath(DotNetInstallPath));

if (Directory.Exists(EmulatedDotNetInstallPath))
{
sdks = sdks.Concat(GetInstalledBundles<SdkVersion>(BundleArch.X64, DotNetSdkInstallPath(EmulatedDotNetInstallPath)));
sdks = sdks.Concat(GetInstalledBundles<SdkVersion>(DotNetSdkInstallPath(EmulatedDotNetInstallPath)));
runtimes = runtimes.Concat(GetInstalledBundles<RuntimeVersion>(
BundleArch.X64,
DotNetRuntimeInstallPath(DotNetInstallPath),
DotNetAspAllInstallPath(DotNetInstallPath),
DotNetAspAppInstallPath(DotNetInstallPath),
DotNetHostFxrInstallPath(DotNetInstallPath)));
DotNetRuntimeInstallPath(EmulatedDotNetInstallPath),
DotNetAspAllInstallPath(EmulatedDotNetInstallPath),
DotNetAspAppInstallPath(EmulatedDotNetInstallPath),
DotNetHostFxrInstallPath(EmulatedDotNetInstallPath)));
Comment on lines +40 to +43
Copy link
Member Author

Choose a reason for hiding this comment

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

This was also addressed in #228

}

return sdks.Concat(runtimes).ToList();
return [..sdks, ..runtimes];
}

private static bool IsMacx64Installation(string path)
private static bool IsMacx64Installation(string sdkVersionPath)
{
try
{
var versionDirs = Directory.GetDirectories(Path.Combine(path, "sdk"));
var rids = File.ReadAllText(Path.Combine(versionDirs[0], "NETCoreSdkRuntimeIdentifierChain.txt"));
return !rids.Contains("arm64");
var rids = File.ReadAllText(Path.Combine(sdkVersionPath, "NETCoreSdkRuntimeIdentifierChain.txt"));
return !rids.Contains("osx-arm64");
}
catch
{
return true;
}
}

private static IEnumerable<Bundle> GetInstalledBundles<TBundleVersion>(BundleArch arch, params string[] paths)
private static IEnumerable<Bundle> GetInstalledBundles<TBundleVersion>(params string[] paths)
where TBundleVersion : BundleVersion, IComparable<TBundleVersion>, new()
{
string bundleTypeString;
Expand All @@ -79,12 +75,12 @@ private static IEnumerable<Bundle> GetInstalledBundles<TBundleVersion>(BundleArc
.GroupBy(tuple => tuple.Version)
.Select(group => Bundle.From(
group.First().Version,
arch,
group.First().Arch,
GetUninstallCommand(group.Select(tuple => tuple.Path)),
string.Format(LocalizableStrings.MacOsBundleDisplayNameFormat, bundleTypeString, group.First().Version.ToString())));
string.Format(LocalizableStrings.MacOsBundleDisplayNameFormat, bundleTypeString, group.First().Version.ToString(), group.First().Arch.ToString().ToLowerInvariant())));
}

private static IEnumerable<(TBundleVersion Version, string Path)> GetInstalledVersionsAndUninstallCommands<TBundleVersion>(string path)
private static IEnumerable<(TBundleVersion Version, string Path, BundleArch Arch)> GetInstalledVersionsAndUninstallCommands<TBundleVersion>(string path)
where TBundleVersion : BundleVersion, IComparable<TBundleVersion>, new()
{
return Directory.Exists(path) ?
Expand All @@ -93,11 +89,12 @@ private static IEnumerable<Bundle> GetInstalledBundles<TBundleVersion>(BundleArc
.Select(dirInfo =>
{
var success = BundleVersion.TryFromInput<TBundleVersion>(dirInfo.Name, out var version);
return (Success: success, Version: version, Path: dirInfo.FullName);
var arch = IsMacx64Installation(dirInfo.FullName) ? BundleArch.X64 : BundleArch.Arm64;
return (Success: success, Version: version, Path: dirInfo.FullName, Arch: arch);
})
.Where(tuple => tuple.Success)
.Select(tuple => (tuple.Version, tuple.Path)) :
new List<(TBundleVersion Version, string Path)>();
.Select(tuple => (tuple.Version, tuple.Path, tuple.Arch)) :
new List<(TBundleVersion Version, string Path, BundleArch Arch)>();
}

private static string GetUninstallCommand(IEnumerable<string> paths)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal static class CommandLineConfigs
public static readonly string HostingBundleOptionName = "hosting-bundle";
public static readonly string X64OptionName = "x64";
public static readonly string X86OptionName = "x86";
public static readonly string Arm64OptionName = "arm64";

public static readonly Option UninstallAllOption = new Option(
"--all",
Expand Down Expand Up @@ -314,7 +315,8 @@ public static BundleArch GetArchSelection(this ParseResult parseResult)
var archSelection = new[]
{
(OptionName: X64OptionName, Arch: BundleArch.X64),
(OptionName: X86OptionName, Arch: BundleArch.X86)
(OptionName: X86OptionName, Arch: BundleArch.X86),
(OptionName: Arm64OptionName, Arch: BundleArch.Arm64)
}
.Where(tuple => parseResult.ValueForOption<bool>($"--{tuple.OptionName}"))
.Select(tuple => tuple.Arch)
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ This tool cannot uninstall versions of the runtime or SDK that are installed usi
<note />
</trans-unit>
<trans-unit id="MacOsBundleDisplayNameFormat">
<source>Microsoft .NET Core {0} {1} (x64)</source>
<target state="new">Microsoft .NET Core {0} {1} (x64)</target>
<source>Microsoft .NET Core {0} {1} ({2})</source>
<target state="new">Microsoft .NET Core {0} {1} ({2})</target>
<note />
</trans-unit>
<trans-unit id="MacRequiredBundleConfirmationPromptOutputFormat">
Expand Down