Skip to content

Commit

Permalink
fix path for Windows Full scenario and handle async script download s…
Browse files Browse the repository at this point in the history
…cenario
  • Loading branch information
YuliiaKovalova committed Jun 27, 2024
1 parent 0907c8c commit 6196063
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 54 deletions.
7 changes: 2 additions & 5 deletions eng/BootStrapMsBuild.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<Project>

<!--
Construct a location of MSBuild bootstrap folder - to be used for deployment and for tests
relying on bootstrapped MSBuild
-->
<!-- Construct a location of MSBuild bootstrap folder - to be used for deployment and for tests relying on bootstrapped MSBuild -->

<PropertyGroup Condition="!$(TargetFramework.StartsWith('net4'))">
<NetVersion>8.0.302</NetVersion>
Expand All @@ -12,7 +9,7 @@
<PropertyGroup>
<BootstrapDestination>$(ArtifactsBinDir)bootstrap\</BootstrapDestination>
<BootstrapDestination Condition="'$(Platform)' == 'x64' or '$(Platform)' == 'arm64'">$(BootstrapDestination)$(Platform)\</BootstrapDestination>
<BootstrapDestination>$(BootstrapDestination)$(TargetFramework.ToLowerInvariant())\sdk\$(NetVersion)\</BootstrapDestination>
<BootstrapDestination>$(BootstrapDestination)$(TargetFramework.ToLowerInvariant())\MSBuild\</BootstrapDestination>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))">
Expand Down
4 changes: 2 additions & 2 deletions eng/BootStrapMsBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,11 @@

<!-- The copying of these dependencies is required by bootstrap\**\sdk\**\NuGet.RestoreEx.targets. Otherwise NuGet.Build.Tasks.dll can not be found. -->
<Copy SourceFiles="@(_NuGetRuntimeDependencies)"
DestinationFolder="$(BootstrapDestination)"
DestinationFolder="$(InstallDir)sdk\$(NetVersion)\"
SkipUnchangedFiles="true" />

<Copy SourceFiles="@(FreshlyBuiltNetBinaries)"
DestinationFiles="@(FreshlyBuiltNetBinaries->'$(InstallDir)sdk\$(NetVersion)\%(RecursiveDir)%(Filename)%(Extension)')" />
DestinationFiles="@(FreshlyBuiltNetBinaries->'$(InstallDir)sdk\$(NetVersion)\%(RecursiveDir)%(Filename)%(Extension)')" />

</Target>

Expand Down
5 changes: 2 additions & 3 deletions eng/cibuild_bootstrapped_msbuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ try {

if ($msbuildEngine -eq 'vs')
{
$buildToolPath = Join-Path $bootstrapRoot "net472\sdk\Current\Bin\MSBuild.exe"
$buildToolPath = Join-Path $bootstrapRoot "net472\MSBuild\Current\Bin\MSBuild.exe"
$buildToolCommand = "";
$buildToolFramework = "net472"
}
Expand All @@ -87,8 +87,7 @@ try {
$buildToolPath = Join-Path $bootstrapRoot "net8.0\dotnet.exe"

# Must be consistent with the version in BootStrapMsBuild.props
$netVersion="8.0.302"
$buildToolCommand = Join-Path $bootstrapRoot "net8.0\sdk" $netVersion "MSBuild.dll";
$buildToolCommand = Join-Path $bootstrapRoot "net8.0\sdk\8.0.302\MSBuild.dll";

$buildToolFramework = "net8.0"
}
Expand Down
6 changes: 3 additions & 3 deletions eng/cibuild_bootstrapped_msbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ then
fi

bootstrapRoot="$Stage1Dir/bin/bootstrap"
# Must be consistent with the version in BootStrapMsBuild.props
netVersion="8.0.302"

if [ $host_type = "core" ]
then
_InitializeBuildTool="$bootstrapRoot/net8.0/dotnet"
_InitializeBuildToolCommand="$bootstrapRoot/net8.0/sdk/$netVersion/MSBuild.dll"

# Must be consistent with the version in BootStrapMsBuild.props
_InitializeBuildToolCommand="$bootstrapRoot/net8.0/sdk/8.0.302/MSBuild.dll"
_InitializeBuildToolFramework="net8.0"
else
echo "Unsupported hostType ($host_type)"
Expand Down
53 changes: 35 additions & 18 deletions src/MSBuild.Bootstrap.Utils/Tasks/InstallDotNetCoreTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
using System.IO;
using System.Net.Http;
using System.Runtime.InteropServices;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

using AsyncTasks = System.Threading.Tasks;

namespace MSBuild.Bootstrap.Utils.Tasks
{
public sealed class InstallDotNetCoreTask : Task
Expand All @@ -23,33 +26,38 @@ public InstallDotNetCoreTask()
Version = string.Empty;
}

[Required]
public string InstallDir { get; set; }

[Required]
public string DotNetInstallScriptRootPath { get; set; }

[Required]
public string Version { get; set; }

private bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

public override bool Execute()
{
ScriptExecutionSettings executionSettings = SetupScriptsExecutionSettings();
if (!File.Exists(executionSettings.ScriptsFullPath))
{
DownloadScript(executionSettings.ScriptName, executionSettings.ScriptsFullPath);
AsyncTasks.Task.Run(() => DownloadScriptAsync(executionSettings.ScriptName, executionSettings.ScriptsFullPath)).GetAwaiter().GetResult();
}

MakeScriptExecutable(executionSettings.ScriptsFullPath);

return RunScript(executionSettings);
}

private async void DownloadScript(string scriptName, string scriptPath)
private async AsyncTasks.Task DownloadScriptAsync(string scriptName, string scriptPath)
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync($"{DotNetInstallBaseUrl}{scriptName}");
HttpResponseMessage response = await client.GetAsync($"{DotNetInstallBaseUrl}{scriptName}").ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
string scriptContent = await response.Content.ReadAsStringAsync();
string scriptContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (!string.IsNullOrEmpty(scriptContent))
{
File.WriteAllText(scriptPath, scriptContent);
Expand Down Expand Up @@ -84,11 +92,22 @@ private void MakeScriptExecutable(string scriptPath)
{
_ = process.Start();
process.WaitForExit();

if (process.ExitCode != 0)
{
string errors = process.StandardError.ReadToEnd() ?? string.Empty;
Log.LogError($"Install-scripts can not be made executable due to the errors: {errors}.");
}
}
}

private bool RunScript(ScriptExecutionSettings executionSettings)
{
if (Log.HasLoggedErrors)
{
return false;
}

using (Process process = new Process { StartInfo = executionSettings.StartInfo })
{
bool started = process.Start();
Expand All @@ -102,7 +121,7 @@ private bool RunScript(ScriptExecutionSettings executionSettings)
if (process.ExitCode != 0)
{
string errors = process.StandardError.ReadToEnd() ?? string.Empty;
Log.LogError("Install-scripts execution errors: " + errors);
Log.LogError($"Install-scripts execution errors: {errors}");
}
}
else
Expand All @@ -114,19 +133,6 @@ private bool RunScript(ScriptExecutionSettings executionSettings)
return !Log.HasLoggedErrors;
}

private bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

private struct ScriptExecutionSettings(string executableName, ProcessStartInfo startInfo, string scriptName, string scriptsFullPath)
{
public string ExecutableName { get; } = executableName;

public ProcessStartInfo StartInfo { get; } = startInfo;

public string ScriptName { get; } = scriptName;

public string ScriptsFullPath { get; } = scriptsFullPath;
}

private ScriptExecutionSettings SetupScriptsExecutionSettings()
{
string scriptExtension = IsWindows ? "ps1" : "sh";
Expand All @@ -148,6 +154,17 @@ private ScriptExecutionSettings SetupScriptsExecutionSettings()

return new ScriptExecutionSettings(executableName, startInfo, $"{ScriptName}.{scriptExtension}", scriptPath);
}

private struct ScriptExecutionSettings(string executableName, ProcessStartInfo startInfo, string scriptName, string scriptsFullPath)
{
public string ExecutableName { get; } = executableName;

public ProcessStartInfo StartInfo { get; } = startInfo;

public string ScriptName { get; } = scriptName;

public string ScriptsFullPath { get; } = scriptsFullPath;
}
}
}

Expand Down

This file was deleted.

0 comments on commit 6196063

Please sign in to comment.