Skip to content

Commit

Permalink
Meson the rest
Browse files Browse the repository at this point in the history
Co-Authored-By: Qyriad <[email protected]>
Co-Authored-By: eldritch horrors <[email protected]>
  • Loading branch information
3 people committed Aug 12, 2024
1 parent 4c485d0 commit b79c558
Show file tree
Hide file tree
Showing 28 changed files with 794 additions and 3 deletions.
3 changes: 3 additions & 0 deletions build-utils-meson/export/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ foreach dep : deps_public_subproject
endforeach
requires_public += deps_public

extra_pkg_config_variables = get_variable('extra_pkg_config_variables', {})
import('pkgconfig').generate(
this_library,
filebase : meson.project_name(),
Expand All @@ -20,11 +21,13 @@ import('pkgconfig').generate(
requires : requires_public,
requires_private : requires_private,
libraries_private : libraries_private,
variables : extra_pkg_config_variables,
)

meson.override_dependency(meson.project_name(), declare_dependency(
include_directories : include_dirs,
link_with : this_library,
compile_args : ['-std=c++2a'],
dependencies : deps_public_subproject + deps_public,
variables : extra_pkg_config_variables,
))
1 change: 1 addition & 0 deletions doc/manual/.version
22 changes: 22 additions & 0 deletions doc/manual/generate-deps.py
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)
61 changes: 61 additions & 0 deletions doc/manual/json-to-tree.py
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())
Loading

0 comments on commit b79c558

Please sign in to comment.