Address review comments

This commit is contained in:
Tom Hvitved
2020-09-09 16:35:37 +02:00
parent 947040aafe
commit 1ce3ac74a1
4 changed files with 22 additions and 11 deletions

View File

@@ -7,7 +7,6 @@ using System.IO;
using Semmle.Util;
using System.Text.RegularExpressions;
using Semmle.Autobuild.Shared;
using System.Net;
namespace Semmle.Autobuild.CSharp
{
@@ -230,7 +229,10 @@ Invoke-Command -ScriptBlock $ScriptBlock";
}
else
{
var downloadDotNetInstallSh = BuildScript.DownloadFile("https://dot.net/v1/dotnet-install.sh", "dotnet-install.sh");
var downloadDotNetInstallSh = BuildScript.DownloadFile(
"https://dot.net/v1/dotnet-install.sh",
"dotnet-install.sh",
e => builder.Log(Severity.Warning, $"Failed to download 'dotnet-install.sh': {e.Message}"));
var chmod = new CommandBuilder(builder.Actions).
RunCommand("chmod").

View File

@@ -4,8 +4,9 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Net;
using System.Net.Http;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
namespace Semmle.Autobuild.Shared
{
@@ -216,12 +217,18 @@ namespace Semmle.Autobuild.Shared
public string EnvironmentExpandEnvironmentVariables(string s) => Environment.ExpandEnvironmentVariables(s);
public void DownloadFile(string address, string fileName)
static async Task DownloadFileAsync(string address, string filename)
{
using var webClient = new WebClient();
webClient.DownloadFile(address, fileName);
using var httpClient = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Get, address);
using var contentStream = await (await httpClient.SendAsync(request)).Content.ReadAsStreamAsync();
using var stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true);
await contentStream.CopyToAsync(stream);
}
public void DownloadFile(string address, string fileName) =>
DownloadFileAsync(address, fileName).Wait();
public static readonly IBuildActions Instance = new SystemBuildActions();
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
namespace Semmle.Autobuild.Shared
{
@@ -196,7 +195,7 @@ namespace Semmle.Autobuild.Shared
/// <summary>
/// Creates a build script that downloads the specified file.
/// </summary>
public static BuildScript DownloadFile(string address, string fileName) =>
public static BuildScript DownloadFile(string address, string fileName, Action<Exception> exceptionCallback) =>
Create(actions =>
{
if (actions.GetDirectoryName(fileName) is string dir && !string.IsNullOrWhiteSpace(dir))
@@ -206,8 +205,9 @@ namespace Semmle.Autobuild.Shared
actions.DownloadFile(address, fileName);
return 0;
}
catch (WebException)
catch (Exception e)
{
exceptionCallback(e);
return 1;
}
});

View File

@@ -1,6 +1,5 @@
using Semmle.Util.Logging;
using System.Linq;
using System.Net;
namespace Semmle.Autobuild.Shared
{
@@ -168,7 +167,10 @@ namespace Semmle.Autobuild.Shared
return 0;
})
&
BuildScript.DownloadFile("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", path)
BuildScript.DownloadFile(
"https://dist.nuget.org/win-x86-commandline/latest/nuget.exe",
path,
e => builder.Log(Severity.Warning, $"Failed to download 'nuget.exe': {e.Message}"))
&
BuildScript.Create(_ =>
{