Skip to content

Commit f02ecf5

Browse files
authored
Re-enable leak detection parameters. (#1867)
* Re-enable leak detection parameters. * Use our copy of SourceLink to build. * Remove signatures from poisoned packages. * Port updates from release/2.1 branch. * Remove reference to obsolete task project. * Exclude some more files we don't care about. * Address code review comment.
1 parent 337413b commit f02ecf5

File tree

5 files changed

+45
-12
lines changed

5 files changed

+45
-12
lines changed

.vsts.pipelines/builds/matrix.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ stages:
1616
name: centos71
1717
jobParameters:
1818
imageName: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-7-359e48e-20200313130914
19-
reportPrebuiltLeaks: false
19+
reportPrebuiltLeaks: true
2020
matrix:
2121
# Temporarily disable unit tests until entire product builds.
2222
# See https://github.com/dotnet/source-build/issues/1549
@@ -43,7 +43,7 @@ stages:
4343
name: centos8
4444
jobParameters:
4545
imageName: mcr.microsoft.com/dotnet-buildtools/prereqs:centos-8-source-build-20200402192642-9e679d4
46-
reportPrebuiltLeaks: false
46+
reportPrebuiltLeaks: true
4747
systemLibunwind: false
4848
matrix:
4949
Production: {}

eng/SourceBuild.Tarball.targets

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,16 @@
320320
<MSBuild
321321
Projects="$(LeakDetectionProjectFile)"
322322
Targets="Restore"
323-
Properties="RestoreSources=$(SourceBuiltPackagesPath)%3B$(TarballRootDir)packages/prebuilt%3bhttps://api.nuget.org/v3/index.json"/>
323+
Properties="
324+
RestoreSources=$(SourceBuiltPackagesPath)%3B$(TarballRootDir)packages/prebuilt%3bhttps://api.nuget.org/v3/index.json;
325+
DotNetPackageVersionPropsPath=$(PackageVersionPropsPath)"/>
324326

325327
<MSBuild
326328
Projects="$(LeakDetectionProjectFile)"
327329
Targets="Publish"
328-
Properties="OutputPath=$(TarballRootDir)tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection/"/>
330+
Properties="
331+
OutputPath=$(TarballRootDir)tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection/;
332+
DotNetPackageVersionPropsPath=$(PackageVersionPropsPath)"/>
329333
</Target>
330334

331335
<Target Name="CopyTarballFiles">

tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection/CheckForPoison.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public class CheckForPoison : Task
5151
/// </summary>
5252
public bool FailOnPoisonFound { get; set; }
5353

54+
/// <summary>
55+
/// Use this directory instead of the system temp directory for staging.
56+
/// Intended for Linux systems with limited /tmp space, like Azure VMs.
57+
/// </summary>
58+
public string OverrideTempPath { get; set; }
59+
5460
private static readonly string[] ZipFileExtensions =
5561
{
5662
".zip",
@@ -78,6 +84,7 @@ public class CheckForPoison : Task
7884
".gitkeep",
7985
".rels",
8086
"LICENSE",
87+
"prefercliruntime",
8188
"RunCsc",
8289
"RunVbc",
8390
};
@@ -103,6 +110,7 @@ public class CheckForPoison : Task
103110
".png",
104111
".props",
105112
".psmdcp",
113+
".rtf",
106114
".scss",
107115
".svg",
108116
".targets",
@@ -140,7 +148,7 @@ public override bool Execute()
140148
}
141149
else
142150
{
143-
//Log.LogError($"No leaked files found in output. Either something is broken or it is the future and we have fixed all leaks - please verify and remove this error if so (and default {nameof(FailOnPoisonFound)} to true).");
151+
Log.LogError($"No leaked files found in output. Either something is broken or it is the future and we have fixed all leaks - please verify and remove this error if so (and default {nameof(FailOnPoisonFound)} to true).");
144152
return false;
145153
}
146154

@@ -154,15 +162,19 @@ public override bool Execute()
154162
/// <param name="catalogedPackagesFilePath">File path to the file hash catalog</param>
155163
/// <param name="markerFileName">Marker file name to check for in poisoned nupkgs</param>
156164
/// <returns>List of poisoned packages and files found and reasons for each</returns>
157-
internal static IEnumerable<PoisonedFileEntry> GetPoisonedFiles(IEnumerable<string> initialCandidates, string catalogedPackagesFilePath, string markerFileName)
165+
internal IEnumerable<PoisonedFileEntry> GetPoisonedFiles(IEnumerable<string> initialCandidates, string catalogedPackagesFilePath, string markerFileName)
158166
{
159-
var tempDirName = Path.GetRandomFileName();
160-
var tempDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), tempDirName));
161167
IEnumerable<CatalogPackageEntry> catalogedPackages = ReadCatalog(catalogedPackagesFilePath);
162168
var poisons = new List<PoisonedFileEntry>();
163169
var candidateQueue = new Queue<string>(initialCandidates);
164170
// avoid collisions between nupkgs with the same name
165171
var dirCounter = 0;
172+
if (!string.IsNullOrWhiteSpace(OverrideTempPath))
173+
{
174+
Directory.CreateDirectory(OverrideTempPath);
175+
}
176+
var tempDirName = Path.GetRandomFileName();
177+
var tempDir = Directory.CreateDirectory(Path.Combine(OverrideTempPath ?? Path.GetTempPath(), tempDirName));
166178

167179
while (candidateQueue.Any())
168180
{
@@ -172,7 +184,7 @@ internal static IEnumerable<PoisonedFileEntry> GetPoisonedFiles(IEnumerable<stri
172184
// add its contents to the list to be checked.
173185
if (ZipFileExtensions.Concat(TarFileExtensions).Concat(TarGzFileExtensions).Any(e => checking.ToLowerInvariant().EndsWith(e)))
174186
{
175-
var tempCheckingDir = Path.Combine(tempDir.FullName, Path.GetFileNameWithoutExtension(checking) + "." + (++dirCounter).ToString());
187+
var tempCheckingDir = Path.Combine(tempDir.FullName, Path.GetRandomFileName(), Path.GetFileNameWithoutExtension(checking) + "." + (++dirCounter).ToString());
176188
PoisonedFileEntry result = ExtractAndCheckZipFileOnly(catalogedPackages, checking, markerFileName, tempCheckingDir, candidateQueue);
177189
if (result != null)
178190
{
@@ -190,6 +202,7 @@ internal static IEnumerable<PoisonedFileEntry> GetPoisonedFiles(IEnumerable<stri
190202
}
191203

192204
tempDir.Delete(true);
205+
193206
return poisons;
194207
}
195208

@@ -295,7 +308,7 @@ private static PoisonedFileEntry ExtractAndCheckZipFileOnly(IEnumerable<CatalogP
295308
// now extract and look for the marker file
296309
if (ZipFileExtensions.Any(e => zipToCheck.ToLowerInvariant().EndsWith(e)))
297310
{
298-
ZipFile.ExtractToDirectory(zipToCheck, tempDir);
311+
ZipFile.ExtractToDirectory(zipToCheck, tempDir, true);
299312
}
300313
else if (TarFileExtensions.Any(e => zipToCheck.ToLowerInvariant().EndsWith(e)))
301314
{

tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection/MarkAndCatalogPackages.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,20 @@ public class MarkAndCatalogPackages : Task
5353
[Required]
5454
public ITaskItem[] PackagesToMark { get; set; }
5555

56+
/// <summary>
57+
/// Use this directory instead of the system temp directory for staging.
58+
/// Intended for Linux systems with limited /tmp space, like Azure VMs.
59+
/// </summary>
60+
public string OverrideTempPath { get; set; }
61+
5662
public override bool Execute()
5763
{
5864
var tempDirName = Path.GetRandomFileName();
59-
var tempDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), tempDirName));
65+
if (!string.IsNullOrWhiteSpace(OverrideTempPath))
66+
{
67+
Directory.CreateDirectory(OverrideTempPath);
68+
}
69+
var tempDir = Directory.CreateDirectory(Path.Combine(OverrideTempPath ?? Path.GetTempPath(), tempDirName));
6070

6171
var packageEntries = new List<CatalogPackageEntry>();
6272

@@ -79,6 +89,13 @@ public override bool Execute()
7989

8090
foreach (string f in Directory.EnumerateFiles(packageTempPath, "*", SearchOption.AllDirectories))
8191
{
92+
// remove signatures so we don't later fail validation
93+
if (Path.GetFileName(f) == ".signature.p7s")
94+
{
95+
File.Delete(f);
96+
continue;
97+
}
98+
8299
var catalogFileEntry = new CatalogFileEntry();
83100
packageEntry.Files.Add(catalogFileEntry);
84101
catalogFileEntry.Path = Utility.MakeRelativePath(f, packageTempPath);

tools-local/tasks/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection/Microsoft.DotNet.SourceBuild.Tasks.LeakDetection.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project>
2626
<Name>Mono.Cecil</Name>
2727
</ProjectReference>
28-
<ProjectReference Include="../Microsoft.DotNet.SourceBuild.Tasks/Microsoft.DotNet.SourceBuild.Tasks.csproj" />
2928
<ProjectReference Include="../Microsoft.DotNet.SourceBuild.Tasks.XPlat/Microsoft.DotNet.SourceBuild.Tasks.XPlat.csproj" />
3029
</ItemGroup>
3130

0 commit comments

Comments
 (0)