Replaces custom archiving tasks with build_tools implementation (#3905)
* TarGzFileCreateFromDirectory * Replace ArchiveDirectory with BuildTools implementation * Fix archive naming * Because sometimes XML cares about whitespace... * Create Packages Directory * Cleanup
This commit is contained in:
parent
9446a81a25
commit
1bf9795374
5 changed files with 189 additions and 126 deletions
|
@ -9,7 +9,7 @@
|
||||||
<UsingTask TaskName="DotNetTest" AssemblyFile="$(CLIBuildDll)" />
|
<UsingTask TaskName="DotNetTest" AssemblyFile="$(CLIBuildDll)" />
|
||||||
<UsingTask TaskName="DownloadFile" AssemblyFile="$(CLIBuildDll)" />
|
<UsingTask TaskName="DownloadFile" AssemblyFile="$(CLIBuildDll)" />
|
||||||
<UsingTask TaskName="ExtractArchive" AssemblyFile="$(CLIBuildDll)" />
|
<UsingTask TaskName="ExtractArchive" AssemblyFile="$(CLIBuildDll)" />
|
||||||
<UsingTask TaskName="ArchiveDirectory" AssemblyFile="$(CLIBuildDll)" />
|
<UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(BuildToolsDir)/Microsoft.DotNet.Build.Tasks.dll"/>
|
||||||
|
|
||||||
<Import Project="prepare/CheckPrereqs.targets" />
|
<Import Project="prepare/CheckPrereqs.targets" />
|
||||||
|
|
||||||
|
@ -213,10 +213,10 @@
|
||||||
Inputs="@(ZipTemplatesInput)"
|
Inputs="@(ZipTemplatesInput)"
|
||||||
Outputs="@(ZipTemplatesOutput)">
|
Outputs="@(ZipTemplatesOutput)">
|
||||||
|
|
||||||
<ArchiveDirectory InputDirectory="%(DotNetNewArchive.FullPath)"
|
<ZipFileCreateFromDirectory
|
||||||
FileName="$([System.IO.Path]::GetFileName(%(DotNetNewArchive.FullPath)))"
|
SourceDirectory="%(DotNetNewArchive.FullPath)"
|
||||||
OutputDirectory="%(DotNetNewArchive.RelativeDir)"
|
DestinationArchive="%(DotNetNewArchive.RelativeDir)/$([System.IO.Path]::GetFileName(%(DotNetNewArchive.FullPath))).zip"
|
||||||
ForceZipArchive="true" />
|
OverwriteDestination="True" />
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
FinishBuild" />
|
FinishBuild" />
|
||||||
|
|
||||||
<!-- UploadToAzure target comes from Build Tools -->
|
<!-- UploadToAzure target comes from Build Tools -->
|
||||||
<Target Name="PublishArtifacts"
|
<Target Name="PublishArtifacts"
|
||||||
DependsOnTargets="SetupAzureBlobInformation;
|
DependsOnTargets="SetupAzureBlobInformation;
|
||||||
GenerateVersionBadge;
|
GenerateVersionBadge;
|
||||||
GatherItemsForPattern;
|
GatherItemsForPattern;
|
||||||
UploadToAzure;
|
UploadToAzure;
|
||||||
PublishDebFilesToDebianRepo;
|
PublishDebFilesToDebianRepo;
|
||||||
PublishCliVersionBadge" />
|
PublishCliVersionBadge" />
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
<CloudDropAccessToken>$(STORAGE_KEY)</CloudDropAccessToken>
|
<CloudDropAccessToken>$(STORAGE_KEY)</CloudDropAccessToken>
|
||||||
<CloudDropAccountName>$(STORAGE_ACCOUNT)</CloudDropAccountName>
|
<CloudDropAccountName>$(STORAGE_ACCOUNT)</CloudDropAccountName>
|
||||||
<DotnetBlobRootUrl>https://$(CloudDropAccountName).blob.core.windows.net/$(ContainerName)</DotnetBlobRootUrl>
|
<DotnetBlobRootUrl>https://$(CloudDropAccountName).blob.core.windows.net/$(ContainerName)</DotnetBlobRootUrl>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="GatherItemsForPattern">
|
<Target Name="GatherItemsForPattern">
|
||||||
|
@ -51,10 +51,10 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ForPublishing>
|
<ForPublishing>
|
||||||
<RelativeBlobPath>$(Product)/$(NugetVersion)/$([System.String]::Copy('%(Filename)%(Extension)').Replace('\' ,'/'))</RelativeBlobPath>
|
<RelativeBlobPath>$(Product)/$(NugetVersion)/$([System.String]::Copy('%(Filename)%(Extension)').Replace('\' ,'/'))</RelativeBlobPath>
|
||||||
</ForPublishing>
|
</ForPublishing>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="PublishDebFilesToDebianRepo" Condition=" '$(OSName)' == 'ubuntu' ">
|
<Target Name="PublishDebFilesToDebianRepo" Condition=" '$(OSName)' == 'ubuntu' ">
|
||||||
<Error Condition="'$(REPO_ID)' == ''" Text="REPO_ID must be set as an environment variable for debian publishing." />
|
<Error Condition="'$(REPO_ID)' == ''" Text="REPO_ID must be set as an environment variable for debian publishing." />
|
||||||
|
|
|
@ -1,16 +1,44 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="14.0" DefaultTargets="Layout" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="14.0" DefaultTargets="Layout" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
|
||||||
<UsingTask TaskName="ArchiveDirectory" AssemblyFile="$(CLIBuildDll)" />
|
|
||||||
|
|
||||||
<Target Name="SetupGenerateArchivesInputsOutputs" DependsOnTargets="Init">
|
<UsingTask TaskName="ZipFileCreateFromDirectory" AssemblyFile="$(BuildToolsDir)/Microsoft.DotNet.Build.dll"/>
|
||||||
|
<UsingTask TaskName="TarGzFileCreateFromDirectory" AssemblyFile="$(CLIBuildDll)" />
|
||||||
|
|
||||||
|
<Target Name="GenerateArchives"
|
||||||
|
DependsOnTargets="Init;
|
||||||
|
Layout;
|
||||||
|
SetupGenerateArchivesInputsOutputs;
|
||||||
|
MakePackagesDir;"
|
||||||
|
Inputs="%(GenerateArchivesInputsOutputs.Inputs)"
|
||||||
|
Outputs="%(GenerateArchivesInputsOutputs.Outputs)">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<GenerateArchivesDestinationArchive>$(ArchiveOutputDirectory)/%(GenerateArchivesInputsOutputs.OutFileName)$(ArchiveExtension)</GenerateArchivesDestinationArchive>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ZipFileCreateFromDirectory
|
||||||
|
Condition=" '$(OSName)' == 'win' "
|
||||||
|
SourceDirectory="%(GenerateArchivesInputsOutputs.InputDirectory)"
|
||||||
|
DestinationArchive="$(GenerateArchivesDestinationArchive)" />
|
||||||
|
|
||||||
|
<TarGzFileCreateFromDirectory
|
||||||
|
Condition=" '$(OSName)' != 'win' "
|
||||||
|
SourceDirectory="%(GenerateArchivesInputsOutputs.InputDirectory)"
|
||||||
|
DestinationArchive="$(GenerateArchivesDestinationArchive)" />
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Archives Include="$(GenerateArchivesDestinationArchive)" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<Target Name="SetupGenerateArchivesInputsOutputs"
|
||||||
|
DependsOnTargets="Init">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ArchiveOutputDirectory>$(PackagesDirectory)</ArchiveOutputDirectory>
|
<ArchiveOutputDirectory>$(PackagesDirectory)</ArchiveOutputDirectory>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<GeneratedArchives Include="$(ArchiveOutputDirectory)/%(LayoutDefinition.NameWithVersion)$(ArchiveExtension)" />
|
|
||||||
|
|
||||||
<GenerateArchivesInputsOutputs Include="%(LayoutDefinition.Name)">
|
<GenerateArchivesInputsOutputs Include="%(LayoutDefinition.Name)">
|
||||||
<Inputs>%(LayoutDefinition.OutputFiles)</Inputs>
|
<Inputs>%(LayoutDefinition.OutputFiles)</Inputs>
|
||||||
<Outputs>$(ArchiveOutputDirectory)/%(LayoutDefinition.NameWithVersion)$(ArchiveExtension)</Outputs>
|
<Outputs>$(ArchiveOutputDirectory)/%(LayoutDefinition.NameWithVersion)$(ArchiveExtension)</Outputs>
|
||||||
|
@ -20,20 +48,8 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="GenerateArchives"
|
<Target Name="MakePackagesDir">
|
||||||
DependsOnTargets="Init;Layout;SetupGenerateArchivesInputsOutputs"
|
<MakeDir Directories="$(PackagesDirectory)" />
|
||||||
Inputs="%(GenerateArchivesInputsOutputs.Inputs)"
|
|
||||||
Outputs="%(GenerateArchivesInputsOutputs.Outputs)">
|
|
||||||
|
|
||||||
<ArchiveDirectory
|
|
||||||
FileName="%(GenerateArchivesInputsOutputs.OutFileName)"
|
|
||||||
OutputDirectory="$(ArchiveOutputDirectory)"
|
|
||||||
InputDirectory="%(GenerateArchivesInputsOutputs.InputDirectory)" >
|
|
||||||
|
|
||||||
<Output TaskParameter="OutputArchive"
|
|
||||||
ItemName="Archives" />
|
|
||||||
</ArchiveDirectory>
|
|
||||||
|
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using System.IO.Compression;
|
|
||||||
using Microsoft.Build.Framework;
|
|
||||||
using Microsoft.Build.Utilities;
|
|
||||||
using Microsoft.DotNet.Cli.Build.Framework;
|
|
||||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
|
||||||
{
|
|
||||||
public class ArchiveDirectory : Task
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
public string FileName { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string OutputDirectory { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string InputDirectory { get; set; }
|
|
||||||
|
|
||||||
public bool ForceZipArchive { get; set; }
|
|
||||||
|
|
||||||
[Output]
|
|
||||||
public string OutputArchive { get; set; }
|
|
||||||
|
|
||||||
public override bool Execute()
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(InputDirectory))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CurrentPlatform.IsPlatform(BuildPlatform.Windows) || ForceZipArchive)
|
|
||||||
{
|
|
||||||
OutputArchive = GenerateZip();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
OutputArchive = GenerateTarGz();
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.LogMessage($"Created Archive '{OutputArchive}'");
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GenerateZip()
|
|
||||||
{
|
|
||||||
var extension = ".zip";
|
|
||||||
var outFile = Path.Combine(OutputDirectory, FileName + extension);
|
|
||||||
|
|
||||||
CreateZipFromDirectory(InputDirectory, outFile);
|
|
||||||
|
|
||||||
return outFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GenerateTarGz()
|
|
||||||
{
|
|
||||||
var extension = ".tar.gz";
|
|
||||||
var outFile = Path.Combine(OutputDirectory, FileName + extension);
|
|
||||||
|
|
||||||
CreateTarGzFromDirectory(InputDirectory, outFile);
|
|
||||||
|
|
||||||
return outFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CreateZipFromDirectory(string directory, string outputArchivePath)
|
|
||||||
{
|
|
||||||
FS.Mkdirp(Path.GetDirectoryName(outputArchivePath));
|
|
||||||
|
|
||||||
if (File.Exists(outputArchivePath))
|
|
||||||
{
|
|
||||||
File.Delete(outputArchivePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
ZipFile.CreateFromDirectory(directory, outputArchivePath, CompressionLevel.Optimal, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CreateTarGzFromDirectory(string directory, string outputArchivePath)
|
|
||||||
{
|
|
||||||
FS.Mkdirp(Path.GetDirectoryName(outputArchivePath));
|
|
||||||
|
|
||||||
if (File.Exists(outputArchivePath))
|
|
||||||
{
|
|
||||||
File.Delete(outputArchivePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
Cmd("tar", "-czf", outputArchivePath, "-C", directory, ".")
|
|
||||||
.Execute()
|
|
||||||
.EnsureSuccessful();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
143
build_projects/dotnet-cli-build/TarGzFileCreateFromDirectory.cs
Normal file
143
build_projects/dotnet-cli-build/TarGzFileCreateFromDirectory.cs
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
// 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 System;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Build.Framework;
|
||||||
|
using Microsoft.Build.Utilities;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Build.Tasks
|
||||||
|
{
|
||||||
|
public sealed class TarGzFileCreateFromDirectory : ToolTask
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The path to the directory to be archived.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public string SourceDirectory { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The path of the archive to be created.
|
||||||
|
/// </summary>
|
||||||
|
[Required]
|
||||||
|
public string DestinationArchive { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates if the destination archive should be overwritten if it already exists.
|
||||||
|
/// </summary>
|
||||||
|
public bool OverwriteDestination { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If zipping an entire folder without exclusion patterns, whether to include the folder in the archive.
|
||||||
|
/// </summary>
|
||||||
|
public bool IncludeBaseDirectory { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An item group of regular expressions for content to exclude from the archive.
|
||||||
|
/// </summary>
|
||||||
|
public ITaskItem[] ExcludePatterns { get; set; }
|
||||||
|
|
||||||
|
protected override bool ValidateParameters()
|
||||||
|
{
|
||||||
|
base.ValidateParameters();
|
||||||
|
|
||||||
|
var retVal = true;
|
||||||
|
|
||||||
|
if (File.Exists(DestinationArchive))
|
||||||
|
{
|
||||||
|
if (OverwriteDestination == true)
|
||||||
|
{
|
||||||
|
Log.LogMessage(MessageImportance.Low, $"{DestinationArchive} will be overwritten");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.LogError($"'{DestinationArchive}' already exists. Did you forget to set '{nameof(OverwriteDestination)}' to true?");
|
||||||
|
|
||||||
|
retVal = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SourceDirectory = Path.GetFullPath(SourceDirectory);
|
||||||
|
|
||||||
|
SourceDirectory = SourceDirectory.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||||
|
? SourceDirectory
|
||||||
|
: SourceDirectory + Path.DirectorySeparatorChar;
|
||||||
|
|
||||||
|
if (!Directory.Exists(SourceDirectory))
|
||||||
|
{
|
||||||
|
Log.LogError($"SourceDirectory '{SourceDirectory} does not exist.");
|
||||||
|
|
||||||
|
retVal = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Execute()
|
||||||
|
{
|
||||||
|
return base.Execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string ToolName
|
||||||
|
{
|
||||||
|
get { return "tar"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override MessageImportance StandardOutputLoggingImportance
|
||||||
|
{
|
||||||
|
get { return MessageImportance.High; } // or else the output doesn't get logged by default
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string GenerateFullPathToTool()
|
||||||
|
{
|
||||||
|
return "tar";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string GenerateCommandLineCommands()
|
||||||
|
{
|
||||||
|
return $"{GetDestinationArchive()} {GetSourceSpecification()}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetSourceSpecification()
|
||||||
|
{
|
||||||
|
if (IncludeBaseDirectory)
|
||||||
|
{
|
||||||
|
var parentDirectory = Directory.GetParent(SourceDirectory).Parent.FullName;
|
||||||
|
|
||||||
|
var sourceDirectoryName = Path.GetFileName(Path.GetDirectoryName(SourceDirectory));
|
||||||
|
|
||||||
|
return $"--directory {parentDirectory} {sourceDirectoryName} {GetExcludes()}";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $"--directory {SourceDirectory} {GetExcludes()} \".\"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDestinationArchive()
|
||||||
|
{
|
||||||
|
return $"-czf {DestinationArchive}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetExcludes()
|
||||||
|
{
|
||||||
|
var excludes = String.Empty;
|
||||||
|
|
||||||
|
if (ExcludePatterns != null)
|
||||||
|
{
|
||||||
|
foreach (var excludeTaskItem in ExcludePatterns)
|
||||||
|
{
|
||||||
|
excludes += $" --exclude {excludeTaskItem.ItemSpec}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return excludes;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LogToolCommand(string message)
|
||||||
|
{
|
||||||
|
base.LogToolCommand($"{base.GetWorkingDirectory()}> {message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue