Skip to content

Commit

Permalink
cli: Add --debug-cfg-files
Browse files Browse the repository at this point in the history
  • Loading branch information
avdgrinten committed Oct 24, 2024
1 parent 3176216 commit b986511
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion xbstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

main_parser = argparse.ArgumentParser()
main_parser.add_argument("-v", dest="verbose", action="store_true", help="verbose")
main_parser.add_argument(
"--debug-cfg-files",
action="store_true",
default=False,
help="write .out.yml files (to debug YAML file processing)",
)
main_parser.add_argument(
"-S", type=str, dest="source_dir", help="source dir (in place of bootstrap.link)"
)
Expand All @@ -34,7 +40,9 @@


def config_for_args(args):
return xbstrap.base.Config(args.build_dir, changed_source_root=args.source_dir)
return xbstrap.base.Config(
args.build_dir, changed_source_root=args.source_dir, debug_cfg_files=args.debug_cfg_files
)


def do_runtool(args):
Expand Down
11 changes: 9 additions & 2 deletions xbstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ def __init__(self, missing=False, updatable=False, timestamp=None):


class Config:
def __init__(self, path, changed_source_root=None):
def __init__(self, path, changed_source_root=None, *, debug_cfg_files=False):
self.debug_cfg_files = debug_cfg_files

self._build_root_override = None if path == "" else path
self._config_path = path
self._root_yml = None
Expand Down Expand Up @@ -225,6 +227,7 @@ def __init__(self, path, changed_source_root=None):

def _read_yml(self, path, *, is_root):
if path.endswith(".y4.yml"):
noext_path = path.removesuffix(".y4.yml")
assert not is_root

y4_args = ["y4"]
Expand All @@ -249,7 +252,11 @@ def _read_yml(self, path, *, is_root):
if y4_result.returncode != 0:
raise GenericError(f"y4 invocation failed: {y4_args}")

yml = yaml.load(y4_result.stdout, Loader=global_yaml_loader)
y4_out = y4_result.stdout
if self.debug_cfg_files:
with open(noext_path + ".out.yml", "w") as f:
f.write(y4_out)
yml = yaml.load(y4_out, Loader=global_yaml_loader)
else:
# Handle plain old YAML files.
with open(path, "r") as f:
Expand Down

0 comments on commit b986511

Please sign in to comment.