tree-sitter/update: BINARIES -> ARGS.binaries

I want to pass more information in the next step, so binaries are just
one of multiple elements of the json value.

Generate a json file via `format` so that we get nicer
formatting (`lib.generators.toJSON` uses `builtins.toJSON` which does
not add any whitespace).
This commit is contained in:
Profpatsch 2022-09-12 13:02:10 +02:00
parent aa480ba111
commit 923975a604
2 changed files with 12 additions and 9 deletions

View file

@ -405,19 +405,21 @@ let
'';
# implementation of the fetching of repo information from github
fetchImpl = passBinaries "fetchImpl-wrapped" {
curl = "${curl}/bin/curl";
nix-prefetch-git = "${nix-prefetch-git}/bin/nix-prefetch-git";
inherit atomically-write;
fetchImpl = passArgs "fetchImpl-with-args" {
binaries = {
curl = "${curl}/bin/curl";
nix-prefetch-git = "${nix-prefetch-git}/bin/nix-prefetch-git";
inherit atomically-write;
};
}
(writers.writePython3 "fetchImpl" {
flakeIgnore = ["E501"];
} ./update_impl.py);
# Pass the given binaries to the command, in the BINARIES environment variable.
# The binaries are just an attrset from name to executable.
passBinaries = name: binAttrs: script: writeShellScript name ''
env BINARIES=${lib.escapeShellArg (lib.generators.toJSON {} binAttrs)} \
# Pass the given arguments to the command, in the ARGS environment variable.
# The arguments are just a json object that should be available in the script.
passArgs = name: argAttrs: script: writeShellScript name ''
env ARGS="$(< ${jsonFile "${name}-args" argAttrs})" \
${script} "$@"
'';

View file

@ -7,7 +7,8 @@ from typing import Iterator, Any, Literal
debug: bool = True if os.environ.get("DEBUG", False) else False
Bin = str
bins: dict[str, Bin] = json.loads(os.environ["BINARIES"])
args: dict[str, Any] = json.loads(os.environ["ARGS"])
bins: dict[str, Bin] = args["binaries"]
mode: str = sys.argv[1]
jsonArg: dict = json.loads(sys.argv[2])