mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
Both tools need a corpus of real assemblies and neither had a way to get one: nugetfuzz-all.ps1 walks the catalog in publish order, which is fine for a crash sweep but makes a poor readability corpus, and the alternative was picking package ids by hand. The ids come from an empty search query, which orders by download count. Downloading them reuses nugetfuzz, which already resolves versions, matches target frameworks and walks the dependency closure into the same cache decompdiff reads; --download-only stops it before it decompiles, since the sweep is the expensive part and a corpus only needs the files. The result is a list of lib directories rather than a single root, because a package already restored on this machine is used from the machine-wide NuGet cache instead of being copied into ours, and a corpus that silently omitted those would misrepresent what was tested. Assisted-by: Claude:claude-opus-5[1m]:Claude Codepull/4078/head
3 changed files with 115 additions and 4 deletions
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env pwsh |
||||
# Downloads the N most-downloaded packages on nuget.org into the cache that decompdiff |
||||
# uses as its corpus (~/.cache/nugetfuzz), together with their dependency closures. |
||||
# |
||||
# The download, TFM selection and dependency walk all live in nugetfuzz.cs already, so |
||||
# this only picks the ids and hands them over: an empty query against the search service |
||||
# returns packages ordered by download count. |
||||
# |
||||
# usage: ./nuget-top.ps1 [-Count n] [-ListOnly] [-Out path] [-Skip n] |
||||
# ponytail: no per-id retry; a package that fails to download is reported and skipped |
||||
|
||||
[CmdletBinding()] |
||||
param( |
||||
[int]$Count = 100, |
||||
[int]$Skip = 0, # start further down the ranking, to extend an existing corpus |
||||
[switch]$ListOnly, # write the id list, download nothing |
||||
[string]$Out |
||||
) |
||||
|
||||
$ErrorActionPreference = 'Stop' |
||||
Set-Location $PSScriptRoot |
||||
|
||||
# Required by the local OpenSSL configuration to validate the SHA-1 signed packages. |
||||
if (-not $env:OPENSSL_ENABLE_SHA1_SIGNATURES) { |
||||
$env:OPENSSL_ENABLE_SHA1_SIGNATURES = '1' |
||||
} |
||||
|
||||
$state = Join-Path $PSScriptRoot 'crawl' |
||||
New-Item -ItemType Directory -Force -Path $state | Out-Null |
||||
if (-not $Out) { |
||||
$Out = Join-Path $state "top-$Count.txt" |
||||
} |
||||
|
||||
# The search service caps how far a caller may page; ask for the ids in blocks and stop |
||||
# as soon as it stops handing any back, so a too-large -Count truncates instead of failing. |
||||
$endpoint = 'https://azuresearch-usnc.nuget.org/query' |
||||
$ids = [System.Collections.Generic.List[string]]::new() |
||||
$page = 100 |
||||
while ($ids.Count -lt $Count) { |
||||
$take = [Math]::Min($page, $Count - $ids.Count) |
||||
$uri = "${endpoint}?q=&skip=$($Skip + $ids.Count)&take=$take&prerelease=false&semVerLevel=2.0.0" |
||||
$response = Invoke-RestMethod -Uri $uri |
||||
if (-not $response.data -or $response.data.Count -eq 0) { |
||||
Write-Warning "search returned nothing at skip=$($Skip + $ids.Count); stopping at $($ids.Count) ids" |
||||
break |
||||
} |
||||
foreach ($entry in $response.data) { |
||||
$ids.Add($entry.id) |
||||
} |
||||
} |
||||
|
||||
# Ranking order is worth keeping in the file: it says what a truncated corpus dropped. |
||||
Set-Content -Path $Out -Value $ids |
||||
Write-Host "$($ids.Count) package ids -> $Out" |
||||
|
||||
if ($ListOnly) { |
||||
return |
||||
} |
||||
|
||||
# A package already restored on this machine is used from the machine-wide NuGet cache |
||||
# rather than copied, so the downloaded set is not one directory that can be handed to |
||||
# decompdiff. nugetfuzz names the lib directory it settled on for each package, and that |
||||
# list IS the corpus - one entry per package, at the target framework it chose. |
||||
$corpusFile = [IO.Path]::ChangeExtension($Out, '.corpus.txt') |
||||
dotnet run nugetfuzz.cs -- --download-only "@$Out" | Tee-Object -Variable log |
||||
if ($LASTEXITCODE -ne 0) { |
||||
throw "nugetfuzz exited with $LASTEXITCODE" |
||||
} |
||||
$dirs = $log | ForEach-Object { if ($_ -match '^\s*cached:\s*(.+)$') { $Matches[1].Trim() } } |
||||
Set-Content -Path $corpusFile -Value $dirs |
||||
Write-Host "" |
||||
Write-Host "$($dirs.Count) lib directories -> $corpusFile" |
||||
Write-Host "decompdiff --old <ref> --new <ref> -o report `$(cat $corpusFile)" |
||||
Loading…
Reference in new issue