Skip to content

Commit

Permalink
--no-clean option for kdist build (#4583)
Browse files Browse the repository at this point in the history
fixes: #4481 

By default, `kdist` will delete the output folder of a target before
building it. This adds a `--no-clean` option to `kdist build` which will
be useful for keeping the parse cache of a kompiled semantics when
rebuilding.
  • Loading branch information
gtrepta authored Aug 15, 2024
1 parent 079be45 commit dcd3440
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pyk/src/pyk/kdist/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ def _exec_build(
force: bool,
verbose: bool,
debug: bool,
clean: bool,
) -> None:
kdist.build(
target_ids=_process_targets(targets),
args=_process_args(args),
jobs=jobs,
force=force,
verbose=verbose or debug,
clean=clean,
)


Expand Down Expand Up @@ -130,6 +132,9 @@ def add_target_arg(parser: ArgumentParser, help_text: str) -> None:
)
build_parser.add_argument('-f', '--force', action='store_true', default=False, help='force build')
build_parser.add_argument('-j', '--jobs', metavar='N', type=int, default=1, help='maximal number of build jobs')
build_parser.add_argument(
'--no-clean', dest='clean', action='store_false', default=True, help="Don't clean before building"
)

clean_parser = command_parser.add_parser('clean', help='clean targets')
add_target_arg(clean_parser, 'target to clean')
Expand Down
11 changes: 8 additions & 3 deletions pyk/src/pyk/kdist/_kdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def build(
jobs: int = 1,
force: bool = False,
verbose: bool = False,
clean: bool = True,
) -> None:
args = dict(args) if args else {}
dep_ids = target_cache().resolve_deps(target_ids)
Expand All @@ -108,6 +109,7 @@ def submit(target_id: TargetId) -> None:
args=args,
force=force,
verbose=verbose,
clean=clean,
)
pending[future] = target_id

Expand All @@ -134,6 +136,7 @@ def _build_target(
*,
force: bool,
verbose: bool,
clean: bool,
) -> Path:
target = target_cache().resolve(target_id)
output_dir = self._target_dir(target_id)
Expand All @@ -145,8 +148,9 @@ def _build_target(
if not force and self._up_to_date(target_id, manifest):
return output_dir

shutil.rmtree(output_dir, ignore_errors=True)
output_dir.mkdir(parents=True)
if clean:
shutil.rmtree(output_dir, ignore_errors=True)
output_dir.mkdir(parents=True, exist_ok=True)
manifest_file.unlink(missing_ok=True)

with (
Expand All @@ -156,7 +160,8 @@ def _build_target(
try:
target.target.build(output_dir, deps=self._deps(target), args=args, verbose=verbose)
except Exception as err:
shutil.rmtree(output_dir, ignore_errors=True)
if clean:
shutil.rmtree(output_dir, ignore_errors=True)
raise RuntimeError(f'Build failed: {target_id.full_name}') from err

manifest_file.write_text(json.dumps(manifest))
Expand Down

0 comments on commit dcd3440

Please sign in to comment.