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

Fix linux for ninja and dotnet checkups #208

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,5 @@ MigrationBackup/

.DS_Store

# Rider
.idea/**
4 changes: 2 additions & 2 deletions UnoCheck/Checkups/DotNetCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public override async Task<DiagnosticResult> Examine(SharedState history)

var remedies = new List<Solution>();

if (Util.CI || Util.IsLinux)
if (Util.CI || !Util.IsWindows)
{
remedies.AddRange(missingSdks
.Select(ms => new DotNetSdkScriptInstallSolution(ms.Version)));
.Select(ms => new DotNetSdkPackageManagerOrScriptInstallSolution(ms.Version)));
}
else
{
Expand Down
8 changes: 5 additions & 3 deletions UnoCheck/Checkups/DotNetNewUnoTemplatesCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class DotNetNewUnoTemplatesCheckup : Checkup

public override async Task<DiagnosticResult> Examine(SharedState history)
{
var dotnetOutput = GetDotNetNewInstalledList();
var dotnetOutput = GetDotNetNewInstalledList(history);

var legacyVersion = GetInstalledVersion(dotnetOutput, _unoLegacyTemplatesOutputRegex);
var version = GetInstalledVersion(dotnetOutput, _unoTemplatesOutputRegex);
Expand Down Expand Up @@ -63,11 +63,13 @@ public override async Task<DiagnosticResult> Examine(SharedState history)
return DiagnosticResult.Ok(this);
}

private string GetDotNetNewInstalledList()
private string GetDotNetNewInstalledList(SharedState? history)
{
var dotnetCommand = new DotNetSdk(history).DotNetExecutable;

// Running 'dotnet new uninstall' without any package ID will list all installed
// dotnet new templates along with their versions.
var processInfo = new ProcessStartInfo("dotnet", "new uninstall");
var processInfo = new ProcessStartInfo(dotnetCommand, "new uninstall");
processInfo.RedirectStandardOutput = true;
processInfo.UseShellExecute = false;
processInfo.EnvironmentVariables["DOTNET_CLI_UI_LANGUAGE"] = "en-US";
Expand Down
31 changes: 15 additions & 16 deletions UnoCheck/Checkups/LinuxNinjaPresenceCheckup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,34 @@ public override bool IsPlatformSupported(Platform platform)
public override async Task<DiagnosticResult> Examine(SharedState history)
{
var shellHasNinjaRunnerResult = ShellProcessRunner.Run("ninja", "--version");
var shellRunnerAptResult = ShellProcessRunner.Run("apt", "--version");

var ninjaVersionExitCode = shellHasNinjaRunnerResult.ExitCode;
var output = shellHasNinjaRunnerResult.GetOutput().Trim();

var shellRunnerAboutLinuxResult = ShellProcessRunner.Run("lsb_release", "-a");

var linuxRelease = shellRunnerAboutLinuxResult.GetOutput().Trim();
var hasNinja = shellHasNinjaRunnerResult.Success;
if (hasNinja)
{
ReportStatus($"Ninja Build Version: {output}", Status.Ok);

var hasNinja = ninjaVersionExitCode == 0;
var hasApt = shellRunnerAptResult.ExitCode == 0;
var isDebianBased = linuxRelease.Contains(Ubuntu) || linuxRelease.Contains(Debian);
return await Task.FromResult(DiagnosticResult.Ok(this));
};

if (!hasNinja && (isDebianBased || hasApt))
var foundPackage = await LinuxPackageManagerWrapper.SearchForPackage(LinuxNinjaSolution.NinjaPackageNamesWithWrappers, true);
if (foundPackage)
{
return await Task.FromResult(
new DiagnosticResult(
Status.Error,
this,
new Suggestion(InstallMessage, new LinuxNinjaSolution())));
new Suggestion(InstallMessage, new LinuxNinjaSolution())
));
}

ReportStatus($"Ninja Build Version: {output}", Status.Ok);

return await Task.FromResult(DiagnosticResult.Ok(this));
return await Task.FromResult(
new DiagnosticResult(
Status.Error,
this,
new Suggestion(InstallMessage, "Ninja-build is missing, follow the installation instructions here: https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages")));
}

private const string Ubuntu = "Ubuntu";
private const string Debian = "Debian";
private const string InstallMessage = "Install Ninja Build";
}
}
30 changes: 21 additions & 9 deletions UnoCheck/DotNet/DotNetSdk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public class DotNetSdk
{
public readonly string[] KnownDotnetLocations;

public readonly FileInfo DotNetExeLocation;
private readonly FileInfo DotNetExeLocation;
public readonly DirectoryInfo DotNetSdkLocation;

public static string DotNetExeName
=> Util.IsWindows ? "dotnet.exe" : "dotnet";

public string DotNetExecutable => Exists ? DotNetExeLocation.FullName : "dotnet";

public DotNetSdk(SharedState sharedState)
{
KnownDotnetLocations = Util.Platform switch
Expand All @@ -47,12 +49,16 @@ public DotNetSdk(SharedState sharedState)
},
Platform.Linux => new string[]
{
// /home/user/share/dotnet/dotnet
// /usr/share/dotnet/dotnet
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
"share",
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
"dotnet",
DotNetExeName)
DotNetExeName),
// ~/.dotnet/dotnet
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".dotnet",
DotNetExeName),
},
_ => new string[] { }
};
Expand All @@ -64,12 +70,13 @@ public DotNetSdk(SharedState sharedState)
if (Directory.Exists(envSdkRoot))
sdkRoot = envSdkRoot;
}

if (string.IsNullOrEmpty(sdkRoot) || !Directory.Exists(sdkRoot))

string environmentOverride = Environment.GetEnvironmentVariable("DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR");
if (!string.IsNullOrEmpty(environmentOverride))
{
sdkRoot = Microsoft.DotNet.NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory();
sdkRoot = environmentOverride;
}

if (string.IsNullOrEmpty(sdkRoot) || !Directory.Exists(sdkRoot))
{
var l = FindDotNetLocations();
Expand All @@ -79,6 +86,11 @@ public DotNetSdk(SharedState sharedState)
}
}

if (string.IsNullOrEmpty(sdkRoot) || !Directory.Exists(sdkRoot))
{
sdkRoot = Microsoft.DotNet.NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory(log: (s) => Util.Log(s.ToString()));
}

sharedState.SetEnvironmentVariable("DOTNET_ROOT", sdkRoot);

// First try and use the actual resolver logic
Expand Down
Loading
Loading