diff --git a/constructor/main.py b/constructor/main.py index 79fa8c3ef..a9b082dbd 100644 --- a/constructor/main.py +++ b/constructor/main.py @@ -69,7 +69,7 @@ def get_output_filename(info): def main_build(dir_path, output_dir='.', platform=cc_platform, verbose=True, cache_dir=DEFAULT_CACHE_DIR, dry_run=False, conda_exe="conda.exe", - config_filename="construct.yaml"): + config_filename="construct.yaml", debug=False): logger.info('platform: %s', platform) if not os.path.isfile(conda_exe): sys.exit("Error: Conda executable '%s' does not exist!" % conda_exe) @@ -88,6 +88,7 @@ def main_build(dir_path, output_dir='.', platform=cc_platform, info['_platform'] = platform info['_download_dir'] = join(cache_dir, platform) info['_conda_exe'] = abspath(conda_exe) + info['_debug'] = debug itypes = get_installer_type(info) if platform != cc_platform and 'pkg' in itypes and not cc_platform.startswith('osx-'): @@ -467,7 +468,7 @@ def main(): main_build(dir_path, output_dir=out_dir, platform=args.platform, verbose=args.verbose, cache_dir=args.cache_dir, dry_run=args.dry_run, conda_exe=conda_exe, - config_filename=args.config_filename) + config_filename=args.config_filename, debug=args.debug) if __name__ == '__main__': diff --git a/constructor/osxpkg.py b/constructor/osxpkg.py index b3831ec7f..3d324b068 100644 --- a/constructor/osxpkg.py +++ b/constructor/osxpkg.py @@ -507,7 +507,8 @@ def pkgbuild_script(name, info, src, dst='postinstall', **kwargs): identifier=info.get("reverse_domain_identifier"), install_location=info.get("default_location_pkg"), ) - rm_rf(SCRIPTS_DIR) + if not info.get('_debug'): + rm_rf(SCRIPTS_DIR) def create(info, verbose=False): diff --git a/constructor/shar.py b/constructor/shar.py index aa5988435..b655d9808 100644 --- a/constructor/shar.py +++ b/constructor/shar.py @@ -199,4 +199,5 @@ def create(info, verbose=False): os.unlink(tarball) os.chmod(shar_path, 0o755) - shutil.rmtree(tmp_dir) + if not info.get('_debug'): + shutil.rmtree(tmp_dir) diff --git a/constructor/winexe.py b/constructor/winexe.py index 74cf2e4da..b869dde69 100644 --- a/constructor/winexe.py +++ b/constructor/winexe.py @@ -488,7 +488,8 @@ def create(info, verbose=False): if signing_tool: signing_tool.verify_signature(info['_outpath']) - shutil.rmtree(tmp_dir) + if not info.get('_debug'): + shutil.rmtree(tmp_dir) if __name__ == '__main__': diff --git a/news/910-debug b/news/910-debug new file mode 100644 index 000000000..da59c99f7 --- /dev/null +++ b/news/910-debug @@ -0,0 +1,19 @@ +### Enhancements + +* When `--debug` is used, do not delete temporary workspaces to facilitate inspection. (#910) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +* Run SH tests in `-x` mode if `CONSTRUCTOR_DEBUG=1` is set. (#910) diff --git a/tests/test_examples.py b/tests/test_examples.py index c0a744783..cf862f368 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -38,7 +38,7 @@ CONDA_EXE, CONDA_EXE_VERSION = identify_conda_exe(CONSTRUCTOR_CONDA_EXE) if CONDA_EXE_VERSION is not None: CONDA_EXE_VERSION = Version(CONDA_EXE_VERSION) -CONSTRUCTOR_DEBUG = bool(os.environ.get("CONSTRUCTOR_DEBUG")) +CONSTRUCTOR_DEBUG = os.environ.get("CONSTRUCTOR_DEBUG", "").lower() in ("1", "true", "yes") if artifacts_path := os.environ.get("CONSTRUCTOR_EXAMPLES_KEEP_ARTIFACTS"): KEEP_ARTIFACTS_PATH = Path(artifacts_path) KEEP_ARTIFACTS_PATH.mkdir(parents=True, exist_ok=True) @@ -189,7 +189,10 @@ def _run_installer_sh(installer, install_dir, installer_input=None, timeout=420, if installer_input: cmd = ["/bin/sh", installer] else: - cmd = ["/bin/sh", installer, "-b", "-p", install_dir] + cmd = ["/bin/sh"] + if CONSTRUCTOR_DEBUG: + cmd.append("-x") + cmd += [installer, "-b", "-p", install_dir] return _execute(cmd, installer_input=installer_input, timeout=timeout, check=check)