From b986511545dbf47e262dfbd8b2437fd3c5bc0f02 Mon Sep 17 00:00:00 2001 From: Alexander van der Grinten Date: Thu, 24 Oct 2024 13:33:51 +0200 Subject: [PATCH] cli: Add --debug-cfg-files --- xbstrap/__init__.py | 10 +++++++++- xbstrap/base.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/xbstrap/__init__.py b/xbstrap/__init__.py index 75bea6d..d118f73 100755 --- a/xbstrap/__init__.py +++ b/xbstrap/__init__.py @@ -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)" ) @@ -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): diff --git a/xbstrap/base.py b/xbstrap/base.py index f6ac99e..ee1882f 100644 --- a/xbstrap/base.py +++ b/xbstrap/base.py @@ -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 @@ -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"] @@ -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: