Skip to content

Commit

Permalink
wip: refactor(script): Factor-out common code
Browse files Browse the repository at this point in the history
  • Loading branch information
PetarKirov committed Sep 29, 2023
1 parent 38748cb commit 8057991
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
24 changes: 2 additions & 22 deletions scripts/fetch_binary.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import std.stdio : stdout, stderr;
import std.string : strip;
import std.typecons : tuple;

import utils;

enum Compiler { dmd, ldc };
alias Version = string;
alias Platform = string;
alias Hash = string;
alias Url = string;

alias UrlFormatter = Url function(Platform platform, Version compilerVersion);

Expand Down Expand Up @@ -123,21 +121,3 @@ void main(string[] args) {
hashes.JSONValue.toPrettyString(JSONOptions.doNotEscapeSlashes)
);
}

Hash prefech(bool dryRun, Url url) =>
executeCommand(
dryRun,
`nix store prefetch-file --json "%s" | jq -r '.hash'`
.format(url)
).strip;

string executeCommand(bool dryRun, string command) {
stderr.writefln(`> %s`, command);
if (dryRun) return null;
const result = executeShell(
command,
null,
Config.stderrPassThrough,
);
return result.status == 0 ? result.output : null;
}
1 change: 1 addition & 0 deletions scripts/update.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env dub

/+ dub.sdl:
name "update-nix-inputs"
dependency "semver" version="~>0.3.4"
Expand Down
28 changes: 28 additions & 0 deletions scripts/utils.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import std.format : format;
import std.process : executeShell, Config;
import std.string : strip;
import std.stdio : stderr;

alias Version = string;
alias Platform = string;
alias Hash = string;
alias Url = string;

Hash prefech(bool dryRun, Url url) =>
executeCommand(
dryRun,
`nix store prefetch-file --json "%s" | jq -r '.hash'`
.format(url)
).strip;


string executeCommand(bool dryRun, string command) {
stderr.writefln(`> %s`, command);
if (dryRun) return null;
const result = executeShell(
command,
null,
Config.stderrPassThrough,
);
return result.status == 0 ? result.output : null;
}

0 comments on commit 8057991

Please sign in to comment.