Use unzip task instead of custom implementation (#18086)
This commit is contained in:
parent
54c1bddf90
commit
166b96405b
5 changed files with 19 additions and 107 deletions
|
@ -6,7 +6,6 @@
|
||||||
<Import Project="$(GitInfoAllRepoPropsFile)" />
|
<Import Project="$(GitInfoAllRepoPropsFile)" />
|
||||||
|
|
||||||
<UsingTask AssemblyFile="$(LeakDetectionTasksAssembly)" TaskName="MarkAndCatalogPackages" />
|
<UsingTask AssemblyFile="$(LeakDetectionTasksAssembly)" TaskName="MarkAndCatalogPackages" />
|
||||||
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ZipFileExtractToDirectory" />
|
|
||||||
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ReplaceTextInFile" />
|
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ReplaceTextInFile" />
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -113,12 +112,12 @@
|
||||||
DependsOnTargets="UnpackTarballs;BuildXPlatTasks"
|
DependsOnTargets="UnpackTarballs;BuildXPlatTasks"
|
||||||
Inputs="$(MSBuildProjectFullPath)"
|
Inputs="$(MSBuildProjectFullPath)"
|
||||||
Outputs="$(CompletedSemaphorePath)ExtractToolPackage.complete">
|
Outputs="$(CompletedSemaphorePath)ExtractToolPackage.complete">
|
||||||
<ZipFileExtractToDirectory SourceArchive="$(PrebuiltSourceBuiltPackagesPath)Microsoft.DotNet.Arcade.Sdk.$(ARCADE_BOOTSTRAP_VERSION).nupkg"
|
<Unzip SourceFiles="$(PrebuiltSourceBuiltPackagesPath)Microsoft.DotNet.Arcade.Sdk.$(ARCADE_BOOTSTRAP_VERSION).nupkg"
|
||||||
DestinationDirectory="$(ArcadeBootstrapPackageDir)microsoft.dotnet.arcade.sdk/$(ARCADE_BOOTSTRAP_VERSION)/"
|
DestinationFolder="$(ArcadeBootstrapPackageDir)microsoft.dotnet.arcade.sdk/$(ARCADE_BOOTSTRAP_VERSION)"
|
||||||
OverwriteDestination="true" />
|
SkipUnchangedFiles="true" />
|
||||||
|
|
||||||
<!-- TODO: When unpacking using ZipFileExtractToDirectory, this executable file has the wrong
|
<!-- When unpacking, this executable file has the wrong permissions on
|
||||||
permissions. See https://github.com/dotnet/source-build/issues/2259 -->
|
non-windows systems: https://github.com/NuGet/Home/issues/13121. -->
|
||||||
<Exec Command="chmod 755 git-clone-to-dir.sh"
|
<Exec Command="chmod 755 git-clone-to-dir.sh"
|
||||||
WorkingDirectory="$(ArcadeBootstrapPackageDir)microsoft.dotnet.arcade.sdk/$(ARCADE_BOOTSTRAP_VERSION)/tools/SourceBuild/" />
|
WorkingDirectory="$(ArcadeBootstrapPackageDir)microsoft.dotnet.arcade.sdk/$(ARCADE_BOOTSTRAP_VERSION)/tools/SourceBuild/" />
|
||||||
|
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
// Licensed to the .NET Foundation under one or more agreements.
|
|
||||||
// The .NET Foundation licenses this file to you under the MIT license.
|
|
||||||
// See the LICENSE file in the project root for more information.
|
|
||||||
|
|
||||||
using Microsoft.Build.Framework;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.IO.Compression;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Build.Tasks
|
|
||||||
{
|
|
||||||
public sealed class ZipFileExtractToDirectory : BuildTask
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The path to the archive to be extracted.
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
public string SourceArchive { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The path of the directory to extract into.
|
|
||||||
/// </summary>
|
|
||||||
[Required]
|
|
||||||
public string DestinationDirectory { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Indicates if the destination directory should be overwritten if it already exists.
|
|
||||||
/// </summary>
|
|
||||||
public bool OverwriteDestination { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// File entries to include in the extraction. Entries are relative
|
|
||||||
/// paths inside the archive. If null or empty, all files are extracted.
|
|
||||||
/// </summary>
|
|
||||||
public ITaskItem[] Include { get; set; }
|
|
||||||
|
|
||||||
public override bool Execute()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (Directory.Exists(DestinationDirectory))
|
|
||||||
{
|
|
||||||
if (OverwriteDestination)
|
|
||||||
{
|
|
||||||
Log.LogMessage(MessageImportance.Low, $"'{DestinationDirectory}' already exists, trying to delete before unzipping...");
|
|
||||||
Directory.Delete(DestinationDirectory, recursive: true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.LogWarning($"'{DestinationDirectory}' already exists. Did you forget to set '{nameof(OverwriteDestination)}' to true?");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.LogMessage(MessageImportance.High, "Decompressing '{0}' into '{1}'...", SourceArchive, DestinationDirectory);
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(DestinationDirectory));
|
|
||||||
|
|
||||||
using (ZipArchive archive = ZipFile.OpenRead(SourceArchive))
|
|
||||||
{
|
|
||||||
if (Include?.Length > 0)
|
|
||||||
{
|
|
||||||
foreach (ITaskItem entryItem in Include)
|
|
||||||
{
|
|
||||||
ZipArchiveEntry entry = archive.GetEntry(entryItem.ItemSpec);
|
|
||||||
string destinationPath = Path.Combine(DestinationDirectory, entryItem.ItemSpec);
|
|
||||||
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));
|
|
||||||
entry.ExtractToFile(destinationPath, overwrite: false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
archive.ExtractToDirectory(DestinationDirectory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
// We have 2 log calls because we want a nice error message but we also want to capture the callstack in the log.
|
|
||||||
Log.LogError("An exception has occurred while trying to decompress '{0}' into '{1}'.", SourceArchive, DestinationDirectory);
|
|
||||||
Log.LogErrorFromException(e, /*show stack=*/ true, /*show detail=*/ true, DestinationDirectory);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -14,7 +14,6 @@
|
||||||
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WritePackageVersionsProps" />
|
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WritePackageVersionsProps" />
|
||||||
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WritePackageUsageData" />
|
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WritePackageUsageData" />
|
||||||
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WriteUsageReports" />
|
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="WriteUsageReports" />
|
||||||
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ZipFileExtractToDirectory" />
|
|
||||||
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ReplaceTextInFile" />
|
<UsingTask AssemblyFile="$(XPlatSourceBuildTasksAssembly)" TaskName="ReplaceTextInFile" />
|
||||||
|
|
||||||
<Target Name="BuildRepoReferences" Condition="'@(RepositoryReference)' != '' and '$(SkipRepoReferences)' != 'true'">
|
<Target Name="BuildRepoReferences" Condition="'@(RepositoryReference)' != '' and '$(SkipRepoReferences)' != 'true'">
|
||||||
|
@ -272,10 +271,10 @@
|
||||||
<_NupkgDestinationPath Condition="$([System.String]::Copy(%(_BuiltIntermediatePackages.Identity)).Contains('source-build-reference-packages'))">$(ReferencePackagesDir)</_NupkgDestinationPath>
|
<_NupkgDestinationPath Condition="$([System.String]::Copy(%(_BuiltIntermediatePackages.Identity)).Contains('source-build-reference-packages'))">$(ReferencePackagesDir)</_NupkgDestinationPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ZipFileExtractToDirectory Condition="'@(_BuiltIntermediatePackages)' != ''"
|
<Unzip SourceFiles="@(_BuiltIntermediatePackages)"
|
||||||
SourceArchive="%(_BuiltIntermediatePackages.Identity)"
|
DestinationFolder="$(SourceBuiltPackagesPath)extractArtifacts/%(_BuiltIntermediatePackages.FileName)/"
|
||||||
DestinationDirectory="$(SourceBuiltPackagesPath)extractArtifacts/%(_BuiltIntermediatePackages.FileName)/"
|
SkipUnchangedFiles="true"
|
||||||
OverwriteDestination="true" />
|
Condition="'@(_BuiltIntermediatePackages)' != ''" />
|
||||||
|
|
||||||
<ItemGroup Condition="'@(_BuiltIntermediatePackages)' != ''">
|
<ItemGroup Condition="'@(_BuiltIntermediatePackages)' != ''">
|
||||||
<SourceBuiltNupkgFiles Include="$(SourceBuiltPackagesPath)extractArtifacts/**/artifacts/*.nupkg" />
|
<SourceBuiltNupkgFiles Include="$(SourceBuiltPackagesPath)extractArtifacts/**/artifacts/*.nupkg" />
|
||||||
|
@ -439,17 +438,18 @@
|
||||||
Id="%(BuiltSdkPackageOverride.Identity)" />
|
Id="%(BuiltSdkPackageOverride.Identity)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ZipFileExtractToDirectory SourceArchive="%(_ToolPackage.Identity)"
|
<Unzip SourceFiles="%(_ToolPackage.Identity)"
|
||||||
DestinationDirectory="$(SourceBuiltSdksDir)%(_ToolPackage.Id)\"
|
DestinationFolder="$(SourceBuiltSdksDir)%(_ToolPackage.Id)\"
|
||||||
OverwriteDestination="true" />
|
SkipUnchangedFiles="true" />
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ExtractedToolFiles Include="$(SourceBuiltSdksDir)%(_ToolPackage.Id)/**/*netcore*/*.dll" />
|
<ExtractedToolFiles Include="$(SourceBuiltSdksDir)%(_ToolPackage.Id)/**/*netcore*/*.dll" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<Copy SourceFiles="@(ExtractedToolFiles)" DestinationFolder="$(SourceBuiltSdksDir)/" />
|
<Copy SourceFiles="@(ExtractedToolFiles)" DestinationFolder="$(SourceBuiltSdksDir)/" />
|
||||||
|
|
||||||
<!-- TODO: When unpacking using ZipFileExtractToDirectory, this executable file has the wrong
|
<!-- When unpacking, this executable file has the wrong permissions on
|
||||||
permissions. See https://github.com/dotnet/source-build/issues/2259 -->
|
non-windows systems: https://github.com/NuGet/Home/issues/13121. -->
|
||||||
<Exec Command="chmod 755 git-clone-to-dir.sh"
|
<Exec Command="chmod 755 git-clone-to-dir.sh"
|
||||||
Condition=" '%(_ToolPackage.Id)' == 'Microsoft.DotNet.Arcade.Sdk' "
|
Condition=" '%(_ToolPackage.Id)' == 'Microsoft.DotNet.Arcade.Sdk' "
|
||||||
WorkingDirectory="$(SourceBuiltSdksDir)%(_ToolPackage.Id)/tools/SourceBuild/" />
|
WorkingDirectory="$(SourceBuiltSdksDir)%(_ToolPackage.Id)/tools/SourceBuild/" />
|
||||||
|
|
|
@ -35,10 +35,10 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<MakeDir Directories="$(SourceBuildReferencePackagesDestination)" />
|
<MakeDir Directories="$(SourceBuildReferencePackagesDestination)" />
|
||||||
<ZipFileExtractToDirectory Condition="'@(SourceBuildReferencePackagesIntermediatePackage)' != ''"
|
<Unzip SourceFiles="@(SourceBuildReferencePackagesIntermediatePackage)"
|
||||||
SourceArchive="%(SourceBuildReferencePackagesIntermediatePackage.Identity)"
|
DestinationFolder="$(SourceBuildReferencePackagesDestination)extractArtifacts"
|
||||||
DestinationDirectory="$(SourceBuildReferencePackagesDestination)extractArtifacts/"
|
SkipUnchangedFiles="true"
|
||||||
OverwriteDestination="true" />
|
Condition="'@(SourceBuildReferencePackagesIntermediatePackage)' != ''" />
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<SourceBuildReferencePackagesNupkgFiles Include="$(SourceBuildReferencePackagesDestination)extractArtifacts/**/*.nupkg" />
|
<SourceBuildReferencePackagesNupkgFiles Include="$(SourceBuildReferencePackagesDestination)extractArtifacts/**/*.nupkg" />
|
||||||
|
|
|
@ -40,6 +40,5 @@
|
||||||
<UsingTask TaskName="TarGzFileCreateFromDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
|
<UsingTask TaskName="TarGzFileCreateFromDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
<UsingTask TaskName="UpdateRuntimeConfig" AssemblyFile="$(CoreSdkTaskDll)" />
|
<UsingTask TaskName="UpdateRuntimeConfig" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
<UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
|
<UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
|
||||||
<UsingTask TaskName="ZipFileExtractToDirectory" AssemblyFile="$(CoreSdkTaskDll)" />
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue