From ecf736444b7b3e3a0c8b04b622e2eadab72d1e83 Mon Sep 17 00:00:00 2001 From: Davis Goodin Date: Wed, 22 Aug 2018 20:13:05 -0500 Subject: [PATCH 1/3] Detect package cache blocking source-built uptake Detect when a source-built package exists, but a different package exists in the package cache directory. NuGet restore short-circuits when the package id/version specified is already in the cache, so the source-built one won't be used by downstream repos. --- build.proj | 12 ++ repos/dir.targets | 14 ++- .../CheckCacheForSourceBuiltNupkgConflicts.cs | 107 ++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/CheckCacheForSourceBuiltNupkgConflicts.cs diff --git a/build.proj b/build.proj index 8dcb948d89..6741e65941 100644 --- a/build.proj +++ b/build.proj @@ -47,6 +47,18 @@ + + + + + + From 784bd929385f469636a9e9a4600cd2398358648b Mon Sep 17 00:00:00 2001 From: Davis Goodin Date: Mon, 27 Aug 2018 13:55:15 -0500 Subject: [PATCH 3/3] Gather usages when useful --- build.proj | 12 --- dir.props | 1 + repos/dir.targets | 58 +++++++++----- ...s => GetSourceBuiltNupkgCacheConflicts.cs} | 80 +++++++++---------- 4 files changed, 78 insertions(+), 73 deletions(-) rename tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/{CheckCacheForSourceBuiltNupkgConflicts.cs => GetSourceBuiltNupkgCacheConflicts.cs} (54%) diff --git a/build.proj b/build.proj index 6741e65941..8dcb948d89 100644 --- a/build.proj +++ b/build.proj @@ -47,18 +47,6 @@ - - - - - - diff --git a/repos/dir.targets b/repos/dir.targets index a3293fa4c3..a0bdbb0313 100644 --- a/repos/dir.targets +++ b/repos/dir.targets @@ -7,7 +7,7 @@ - + @@ -177,9 +177,29 @@ - + + + + + + + + <_ReportDir>$(ConflictingPackageReportDir)before-$(RepositoryName)/ + <_ReportDataFile>$(_ReportDir)usage.json + + + + + + + - - - - - - - - - - - + - - - @@ -367,6 +374,19 @@ DataFile="$(PackageReportDataFile)" /> + + + + + + + + + + + + diff --git a/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/CheckCacheForSourceBuiltNupkgConflicts.cs b/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/GetSourceBuiltNupkgCacheConflicts.cs similarity index 54% rename from tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/CheckCacheForSourceBuiltNupkgConflicts.cs rename to tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/GetSourceBuiltNupkgCacheConflicts.cs index 4b4bfd2ca7..77f8eedfb4 100644 --- a/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/CheckCacheForSourceBuiltNupkgConflicts.cs +++ b/tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks/GetSourceBuiltNupkgCacheConflicts.cs @@ -19,7 +19,7 @@ namespace Microsoft.DotNet.SourceBuild.Tasks /// This usually results in prebuilt packages being used, which can either break the build or /// end up in the outputs. /// - public class CheckCacheForSourceBuiltNupkgConflicts : Task + public class GetSourceBuiltNupkgCacheConflicts : Task { /// /// Items containing package id and version of each source-built package. @@ -40,60 +40,56 @@ public class CheckCacheForSourceBuiltNupkgConflicts : Task [Required] public string PackageCacheDir { get; set; } + [Output] + public ITaskItem[] ConflictingPackageInfos { get; set; } + public override bool Execute() { DateTime startTime = DateTime.Now; - bool anyPackageNotIdentical = false; + ConflictingPackageInfos = SourceBuiltPackageInfos + .Where(item => + { + string sourceBuiltPath = item.ItemSpec; + string id = item.GetMetadata("PackageId"); + string version = item.GetMetadata("PackageVersion"); - foreach (ITaskItem item in SourceBuiltPackageInfos) - { - string sourceBuiltPath = item.ItemSpec; - string id = item.GetMetadata("PackageId"); - string version = item.GetMetadata("PackageVersion"); + string packageCachePath = Path.Combine( + PackageCacheDir, + id.ToLowerInvariant(), + version, + $"{id.ToLowerInvariant()}.{version}.nupkg"); - string packageCachePath = Path.Combine( - PackageCacheDir, - id.ToLowerInvariant(), - version, - $"{id.ToLowerInvariant()}.{version}.nupkg"); + if (!File.Exists(packageCachePath)) + { + Log.LogMessage( + MessageImportance.Low, + $"OK: Package not found in package cache: {id} {version}"); + return false; + } - if (!File.Exists(packageCachePath)) - { Log.LogMessage( MessageImportance.Low, - $"OK: Package not found in package cache: {id} {version}"); - continue; - } + $"Package id/version found in package cache, verifying: {id} {version}"); - Log.LogMessage( - MessageImportance.Low, - $"Package id/version found in package cache, verifying: {id} {version}"); + bool identical = File.ReadAllBytes(sourceBuiltPath) + .SequenceEqual(File.ReadAllBytes(packageCachePath)); - bool identical = File.ReadAllBytes(sourceBuiltPath) - .SequenceEqual(File.ReadAllBytes(packageCachePath)); + if (!identical) + { + Log.LogMessage( + MessageImportance.Low, + "BAD: Source-built nupkg is not byte-for-byte identical " + + $"to nupkg in cache: {id} {version}"); + return true; + } - if (!identical) - { - anyPackageNotIdentical = true; Log.LogMessage( - MessageImportance.High, - "Watch out! Source-built nupkg is not byte-for-byte identical " + - $"to nupkg in cache: {id} {version}"); - } - - Log.LogMessage( - MessageImportance.Low, - $"OK: Package in cache is identical to source-built: {id} {version}"); - } - - if (anyPackageNotIdentical) - { - Log.LogMessage( - MessageImportance.High, - "To find usages that may have caused this issue, consider running " + - "'./build.sh /t:FindSourceBuiltUsages' (or ps1 equivalent)"); - } + MessageImportance.Low, + $"OK: Package in cache is identical to source-built: {id} {version}"); + return false; + }) + .ToArray(); // Tell the user about this task, in case it takes a while. Log.LogMessage(