diff --git a/src/SourceBuild/content/eng/build.targets b/src/SourceBuild/content/eng/build.targets index 630307028..048d2b89b 100644 --- a/src/SourceBuild/content/eng/build.targets +++ b/src/SourceBuild/content/eng/build.targets @@ -1,18 +1,23 @@ + - - + + + + + - - + + + diff --git a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/Archive.cs b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/Archive.cs index e7943c0a3..7a572b356 100644 --- a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/Archive.cs +++ b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/Archive.cs @@ -2,17 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Immutable; using System.Formats.Tar; using System.IO; using System.IO.Compression; using System.Linq; -using System.Reflection; -using System.Reflection.Metadata; -using System.Reflection.PortableExecutable; using System.Threading; using System.Threading.Tasks; -using static ArchiveExtensions; public abstract class Archive : IDisposable { @@ -134,4 +129,32 @@ public abstract class Archive : IDisposable _archive.Dispose(); } } + + public static (string Version, string Rid, string extension) GetInfoFromArchivePath(string path) + { + string extension; + if (path.EndsWith(".tar.gz")) + { + extension = ".tar.gz"; + } + else if (path.EndsWith(".zip")) + { + extension = ".zip"; + } + else + { + throw new ArgumentException($"Invalid archive extension '{path}': must end with .tar.gz or .zip"); + } + + string filename = Path.GetFileName(path)[..^extension.Length]; + var dashDelimitedParts = filename.Split('-'); + var (rid, versionString) = dashDelimitedParts switch + { + ["dotnet", "sdk", var first, var second, var third, var fourth] when PathWithVersions.IsVersionString(first) => (third + '-' + fourth, first + '-' + second), + ["dotnet", "sdk", var first, var second, var third, var fourth] when PathWithVersions.IsVersionString(third) => (first + '-' + second, third + '-' + fourth), + _ => throw new ArgumentException($"Invalid archive file name '{filename}': file name should include full build version and rid in the format dotnet-sdk--{extension} or dotnet-sdk--{extension}") + }; + + return (versionString, rid, extension); + } } diff --git a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/GetClosestOfficialSdk.cs b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/GetClosestOfficialSdk.cs index 1eca113e1..8ea6b4f83 100644 --- a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/GetClosestOfficialSdk.cs +++ b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/GetClosestOfficialSdk.cs @@ -1,14 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System; -using System.Diagnostics; using System.IO; using System.Net; using System.Net.Http; -using System.Runtime.InteropServices; using System.Threading.Tasks; using Microsoft.Build.Framework; + public class GetClosestOfficialSdk : Microsoft.Build.Utilities.Task { [Required] @@ -24,7 +22,7 @@ public class GetClosestOfficialSdk : Microsoft.Build.Utilities.Task public async Task ExecuteAsync() { - var (versionString, rid, extension) = GetInfoFromArchivePath(BuiltSdkPath); + var (versionString, rid, extension) = Archive.GetInfoFromArchivePath(BuiltSdkPath); string downloadUrl = GetLatestOfficialSdkUrl(versionString, rid, extension); @@ -63,31 +61,4 @@ public class GetClosestOfficialSdk : Microsoft.Build.Utilities.Task return $"https://aka.ms/dotnet/{channel}/daily/dotnet-sdk-{rid}{extension}"; } - static (string Version, string Rid, string extension) GetInfoFromArchivePath(string path) - { - string extension; - if (path.EndsWith(".tar.gz")) - { - extension = ".tar.gz"; - } - else if (path.EndsWith(".zip")) - { - extension = ".zip"; - } - else - { - throw new ArgumentException($"Invalid archive extension '{path}': must end with .tar.gz or .zip"); - } - - string filename = Path.GetFileName(path)[..^extension.Length]; - var dashDelimitedParts = filename.Split('-'); - var (rid, versionString) = dashDelimitedParts switch - { - ["dotnet", "sdk", var first, var second, var third, var fourth] when PathWithVersions.IsVersionString(first) => (third + '-' + fourth, first + '-' + second), - ["dotnet", "sdk", var first, var second, var third, var fourth] when PathWithVersions.IsVersionString(third) => (first + '-' + second, third + '-' + fourth), - _ => throw new ArgumentException($"Invalid archive file name '{filename}': file name should include full build version and rid in the format dotnet-sdk--{extension} or dotnet-sdk--{extension}") - }; - - return (versionString, rid, extension); - } } diff --git a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/GetSingleTarballItem.cs b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/GetSingleTarballItem.cs new file mode 100644 index 000000000..9641ad505 --- /dev/null +++ b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/GetSingleTarballItem.cs @@ -0,0 +1,51 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using Microsoft.Build.Framework; + +public class GetSingleTarballItem : Microsoft.Build.Utilities.Task +{ + [Required] + public required ITaskItem[] SdkTarballItems { get; init; } + + [Output] + public string BestSdkTarballItem { get; set; } = ""; + + public override bool Execute() + { + List tarballItems = new (); + foreach(var item in SdkTarballItems) + { + try + { + var (versionString, rid, extension) = Archive.GetInfoFromArchivePath(item.ItemSpec); + tarballItems.Add(item.ItemSpec); + } + catch (ArgumentException e) + { + Log.LogMessage(MessageImportance.High, e.Message); + continue; + } + } + switch (tarballItems.Count){ + case 0: + Log.LogMessage(MessageImportance.High, "No valid tarball items found"); + BestSdkTarballItem = ""; + break; + case 1: + Log.LogMessage(MessageImportance.High, $"{tarballItems[0]} is the only valid tarball item found"); + BestSdkTarballItem = tarballItems[0]; + break; + default: + tarballItems.Sort((a,b) => a.Length - b.Length); + Log.LogMessage(MessageImportance.High, $"Multiple valid tarball items found: '{string.Join("', '", tarballItems)}'"); + BestSdkTarballItem = tarballItems[0]; + Log.LogMessage(MessageImportance.High, $"Choosing '{BestSdkTarballItem}"); + break; + } + return true; + } + +} diff --git a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/PathWithVersions.cs b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/PathWithVersions.cs index e8e3d7c9d..bc2af0c6b 100644 --- a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/PathWithVersions.cs +++ b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/PathWithVersions.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Generic; using System.IO; using System.Text; diff --git a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/ZipArchiveExtensions.cs b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/ZipArchiveExtensions.cs index 08c3c6cef..4b67efea0 100644 --- a/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/ZipArchiveExtensions.cs +++ b/src/SourceBuild/content/eng/tools/tasks/Microsoft.DotNet.SourceBuild.Tasks.SdkArchiveDiff/ZipArchiveExtensions.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq;