-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Qyriad <[email protected]> Co-Authored-By: eldritch horrors <[email protected]>
- Loading branch information
1 parent
a66a708
commit 036f9ac
Showing
28 changed files
with
794 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../.version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import glob | ||
import sys | ||
|
||
# meson expects makefile-style dependency declarations, i.e. | ||
# | ||
# target: dependency... | ||
# | ||
# meson seems to pass depfiles straight on to ninja even though | ||
# it also parses the file itself (or at least has code to do so | ||
# in its tree), so we must live by ninja's rules: only slashes, | ||
# spaces and octothorpes can be escaped, anything else is taken | ||
# literally. since the rules for these aren't even the same for | ||
# all three we will just fail when we encounter any of them (if | ||
# asserts are off for some reason the depfile will likely point | ||
# to nonexistant paths, making everything phony and thus fine.) | ||
for path in glob.glob(sys.argv[1] + '/**', recursive=True): | ||
assert '\\' not in path | ||
assert ' ' not in path | ||
assert '#' not in path | ||
print("ignored:", path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This script is a helper for this project's Meson buildsystem, to replace its | ||
usage of `nix eval --write-to`. Writing a JSON object as a nested directory | ||
tree is more generic, easier to maintain, and far, far less cursed. Nix | ||
has 'good' support for JSON output. Let's just use it. | ||
""" | ||
|
||
import argparse | ||
from pathlib import Path | ||
import json | ||
import sys | ||
|
||
name = 'json-to-tree.py' | ||
|
||
def log(*args, **kwargs): | ||
kwargs['file'] = sys.stderr | ||
return print(f'{name}:', *args, **kwargs) | ||
|
||
def write_dict_to_directory(current_directory: Path, data: dict, files_written=0): | ||
current_directory.mkdir(parents=True, exist_ok=True) | ||
for key, value in data.items(): | ||
nested_path = current_directory / key | ||
match value: | ||
case dict(nested_data): | ||
files_written += write_dict_to_directory(nested_path, nested_data) | ||
|
||
case str(content): | ||
nested_path.write_text(content) | ||
files_written += 1 | ||
|
||
case rest: | ||
assert False, \ | ||
f'should have been called on a dict or string, not {type(rest)=}\n\t{rest=}' | ||
|
||
return files_written | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(name) | ||
parser.add_argument('-i', '--input', type=argparse.FileType('r'), default='-', | ||
help='The JSON input to operate on and output as a directory tree', | ||
) | ||
parser.add_argument('-o', '--output', type=Path, required=True, | ||
help='The place to put the directory tree', | ||
) | ||
args = parser.parse_args() | ||
|
||
json_string = args.input.read() | ||
|
||
try: | ||
data = json.loads(json_string) | ||
except json.JSONDecodeError: | ||
log(f'could not decode JSON from input: {json_string}') | ||
raise | ||
|
||
|
||
files_written = write_dict_to_directory(args.output, data) | ||
log(f'wrote {files_written} files') | ||
|
||
sys.exit(main()) |
Oops, something went wrong.