Skip to content

Commit

Permalink
fix(scripts/fetch_binary): dmd source now hashed in unpacked form.
Browse files Browse the repository at this point in the history
  • Loading branch information
dukc authored and PetarKirov committed May 18, 2024
1 parent 3cde025 commit 34848d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 16 additions & 4 deletions scripts/fetch_binary.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ alias UrlFormatter =

alias PlatformQuery = Platform[] function(Version) @safe pure;

struct CompilerInfo { UrlFormatter urlFormatter; PlatformQuery platforms; }
enum UnpackingNeeded : bool { no, yes }

struct CompilerInfo {
UrlFormatter urlFormatter;
PlatformQuery platforms;
UnpackingNeeded unpackingNeed;
}

@safe pure string suffix(Platform p) => p.startsWith("windows") ?
"7z" : "tar.xz";
Expand All @@ -38,6 +44,7 @@ enum CompilerInfo[Compiler] supportedPlatforms = [
compVersion => [
"linux", "osx", "freebsd-64", "windows"
],
UnpackingNeeded.no,
),
Compiler.dmd_src: CompilerInfo(
(platform, compilerVersion) =>
Expand All @@ -48,6 +55,7 @@ enum CompilerInfo[Compiler] supportedPlatforms = [
compVersion.split(".")[1].to!int >= 101 ? [] : ["druntime"],
["phobos", "tools"]
].join,
UnpackingNeeded.yes,
),
Compiler.ldc: CompilerInfo(
(platform, compilerVersion) =>
Expand All @@ -60,6 +68,7 @@ enum CompilerInfo[Compiler] supportedPlatforms = [
"osx-arm64", "osx-x86_64",
"windows-x64", "windows-x86"
],
UnpackingNeeded.no,
),
Compiler.ldc_src: CompilerInfo(
(platform, compilerVersion) =>
Expand All @@ -68,6 +77,7 @@ enum CompilerInfo[Compiler] supportedPlatforms = [
compVersion => [
"src"
],
UnpackingNeeded.no,
),
];

Expand Down Expand Up @@ -149,13 +159,15 @@ void main(string[] args) {

auto jobs = compilerVersions.map!(compilerVersion =>
platforms.map!(platform =>
tuple(compilerVersion, platform, getUrl(platform, compilerVersion))
tuple(compilerVersion, platform, getUrl(platform, compilerVersion),
compilerInfo.unpackingNeed)
).array
).joiner.array;

foreach (job; jobs.parallel) {
const compilerVersion = job[0], platform = job[1], url = job[2];
hashes[compilerVersion][platform] = prefech(!liveRun, url);
const compilerVersion = job[0], platform = job[1], url = job[2],
unpack = job[3];
hashes[compilerVersion][platform] = prefech(!liveRun, url, unpack);
}

if (!liveRun) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ alias Platform = string;
alias Hash = string;
alias Url = string;

Hash prefech(bool dryRun, Url url) =>
Hash prefech(bool dryRun, Url url, bool unpack = false) =>
executeCommand(
dryRun,
`nix store prefetch-file --json "%s" | jq -r '.hash'`
.format(url)
`nix-hash --to-sri --type sha256 $( nix-prefetch-url %s "%s" )`
.format(unpack ? "--unpack" : "", url)
).strip;


Expand Down

0 comments on commit 34848d8

Please sign in to comment.