Skip to content
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
6 changes: 5 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
<BaseArtifactsPath>$(MSBuildThisFileDirectory)artifacts\</BaseArtifactsPath>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
<NoWarn>$(NoWarn);NU5128;SA0001</NoWarn>
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
<!--
Disabling static graph restore due to a bug related to NuGetAuditSuppress.
See: https://github.com/NuGet/Home/issues/14300
-->
<RestoreUseStaticGraphEvaluation>false</RestoreUseStaticGraphEvaluation>
<RestoreSerializeGlobalProperties>true</RestoreSerializeGlobalProperties>
<UseArtifactsOutput>false</UseArtifactsOutput>
<IsTestProject Condition="$(MSBuildProjectName.EndsWith('UnitTests'))">true</IsTestProject>
Expand Down
6 changes: 5 additions & 1 deletion Directory.Solution.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<Project>
<PropertyGroup>
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
<!--
Disabling static graph restore due to a bug related to NuGetAuditSuppress.
See: https://github.com/NuGet/Home/issues/14300
-->
<RestoreUseStaticGraphEvaluation>false</RestoreUseStaticGraphEvaluation>
<RestoreSerializeGlobalProperties>true</RestoreSerializeGlobalProperties>
</PropertyGroup>
</Project>
49 changes: 43 additions & 6 deletions src/UniversalPackages/DownloadUniversalPackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,12 @@ private void CreatePackageListJson(IReadOnlyCollection<UniversalPackage> package
// Download only if needed
if (!Directory.Exists(artifactToolPath))
{
bool downloadResult = DownloadAndExtractArchive("ArtifactTool", releaseInfo.Value.DownloadUri, artifactToolPath, isZip: true);
bool downloadResult = DownloadAndExtractArchive(
"ArtifactTool",
releaseInfo.Value.DownloadUri,
artifactToolPath,
GetArtifactToolExeName(),
isZip: true);
if (!downloadResult)
{
return null;
Expand All @@ -421,8 +426,7 @@ private void CreatePackageListJson(IReadOnlyCollection<UniversalPackage> package

string? GetArtifactToolExePath(string dir)
{
string exeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "artifacttool.exe" : "artifacttool";
string exePath = Path.Combine(dir, exeName);
string exePath = Path.Combine(dir, GetArtifactToolExeName());
if (File.Exists(exePath))
{
return exePath;
Expand All @@ -431,6 +435,9 @@ private void CreatePackageListJson(IReadOnlyCollection<UniversalPackage> package
Log.LogError($"ArtifactTool '{exePath}' was not found.");
return null;
}

static string GetArtifactToolExeName()
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "artifacttool.exe" : "artifacttool";
}

private (string Version, string DownloadUri)? GetArtifactToolReleaseInfo(string osName, string arch, string patVar)
Expand Down Expand Up @@ -621,7 +628,12 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
// Download only if needed
if (!Directory.Exists(credentialProviderDir))
{
bool downloadResult = DownloadAndExtractArchive("Artifacts Credential Provider", releaseInfo.Value.DownloadUri, credentialProviderDir, isZip: RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
bool downloadResult = DownloadAndExtractArchive(
"Artifacts Credential Provider",
releaseInfo.Value.DownloadUri,
credentialProviderDir,
GetArtifactsCredentialProviderRelativePath(),
isZip: RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
if (!downloadResult)
{
return null;
Expand All @@ -638,7 +650,9 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
return null;
}

string GetArtifactsCredentialProviderExePath(string dir) => Path.Combine(dir, "plugins", "netcore", "CredentialProvider.Microsoft", exeName);
string GetArtifactsCredentialProviderExePath(string dir) => Path.Combine(dir, GetArtifactsCredentialProviderRelativePath());

string GetArtifactsCredentialProviderRelativePath() => Path.Combine("plugins", "netcore", "CredentialProvider.Microsoft", exeName);
}

private (string Version, string DownloadUri)? GetArtifactsCredentialProviderReleaseInfo()
Expand Down Expand Up @@ -737,7 +751,7 @@ private string GetArtifactToolReleaseInfoUrl(string osName, string arch)
return (version, downloadUri);
}

private bool DownloadAndExtractArchive(string displayName, string downloadUri, string path, bool isZip)
private bool DownloadAndExtractArchive(string displayName, string downloadUri, string path, string exeRelativePath, bool isZip)
{
string? archiveDownloadPath = null;
string? archiveExtractPath = null;
Expand Down Expand Up @@ -766,6 +780,28 @@ private bool DownloadAndExtractArchive(string displayName, string downloadUri, s
if (isZip)
{
ZipFile.ExtractToDirectory(archiveDownloadPath, archiveExtractPath);

// Zip archives do not preserve Unix file permissions, so we need to set the executable bit manually.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string exePath = Path.Combine(archiveExtractPath, exeRelativePath);
if (!File.Exists(exePath))
{
Log.LogError($"Failed to set executable bit on {exePath}. File not found.");
return false;
}

int exitCode = ProcessHelper.Execute(
"/bin/chmod",
$"+x \"{exePath}\"",
processStdOut: message => Log.LogMessage(MessageImportance.Low, message),
processStdErr: message => Log.LogError(message));
if (exitCode != 0)
{
Log.LogError($"Failed to set executable bit on {exePath}. chmod failed with exit code: {exitCode}");
return false;
}
}
}
else
{
Expand All @@ -792,6 +828,7 @@ private bool DownloadAndExtractArchive(string displayName, string downloadUri, s
destination.Delete(true);
}

Log.LogMessage(MessageImportance.Low, $"Moving {archiveExtractPath} to {destination.FullName}");
destination.Parent?.Create();
Directory.Move(archiveExtractPath, destination.FullName);

Expand Down