Skip to content

Commit

Permalink
Do not print from kompile by default (#4510)
Browse files Browse the repository at this point in the history
* Adds a parameter `tool_mode=False` to `kompile`. The subprocess will
only write to `std{out,err}` if set to `True`. These streams will still
be written to log.
* `kompile`, `_kast`, `_kprove`, `_krun` no longer translate the
`CalledProcessError` to `RuntimeError`.
*  `_kprove`, `_krun` no longer write to `stderr`.
  • Loading branch information
tothtamas28 authored Jul 10, 2024
1 parent 54e7c65 commit 67ffc46
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 45 deletions.
12 changes: 6 additions & 6 deletions pyk/src/pyk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections.abc import Iterable
from contextlib import contextmanager
from pathlib import Path
from subprocess import CalledProcessError
from tempfile import NamedTemporaryFile
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -270,9 +271,8 @@ def explore_context() -> Iterator[KCFGExplore]:

try:
proofs = prove_rpc.prove_rpc(options=options)
except RuntimeError as err:
_, _, _, cpe = err.args
exit_with_process_error(cpe)
except CalledProcessError as err:
exit_with_process_error(err)
for proof in sorted(proofs, key=lambda p: p.id):
print('\n'.join(proof.summary.lines))
if proof.failed and options.failure_info:
Expand Down Expand Up @@ -353,10 +353,10 @@ def exec_kompile(options: KompileCommandOptions) -> None:
warnings_to_errors=options.warnings_to_errors,
ignore_warnings=options.ignore_warnings,
no_exc_wrap=options.no_exc_wrap,
tool_mode=True,
)
except RuntimeError as err:
_, _, _, _, cpe = err.args
exit_with_process_error(cpe)
except CalledProcessError as err:
exit_with_process_error(err)


def exec_run(options: RunOptions) -> None:
Expand Down
3 changes: 2 additions & 1 deletion pyk/src/pyk/krepl/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from argparse import ArgumentParser
from dataclasses import dataclass
from functools import cached_property
from subprocess import CalledProcessError
from typing import TYPE_CHECKING, Generic, TypeVar, final

from cmd2 import Cmd, with_argparser, with_category
Expand Down Expand Up @@ -76,7 +77,7 @@ def init_state(self) -> KState:
output=KRunOutput.KORE,
depth=0,
)
except RuntimeError as err:
except CalledProcessError as err:
raise ReplError('Failed to load program') from err

pattern = KoreParser(proc_res.stdout).pattern()
Expand Down
30 changes: 13 additions & 17 deletions pyk/src/pyk/ktool/kompile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from enum import Enum
from functools import cached_property
from pathlib import Path
from subprocess import CalledProcessError
from typing import TYPE_CHECKING, final

from ..utils import abs_or_rel_to, check_dir_path, check_file_path, run_process_2, single
Expand Down Expand Up @@ -283,8 +282,10 @@ def __call__(
no_exc_wrap: bool = False,
debug: bool = False,
verbose: bool = False,
# ---
cwd: Path | None = None,
check: bool = True,
tool_mode: bool = False,
bug_report: BugReport | None = None,
outer_parsed_json: bool = False,
) -> Path:
Expand Down Expand Up @@ -331,22 +332,17 @@ def __call__(
if ignore_warnings:
args += ['-Wno', ','.join(ignore_warnings)]

try:
proc_res = run_process_2(args, write_stderr=True, logger=_LOGGER, cwd=cwd, check=check)
except CalledProcessError as err:
raise RuntimeError(
f'Command kompile exited with code {err.returncode} for: {self.base_args.main_file}',
err.stdout,
err.stderr,
err.returncode,
err,
) from err

if proc_res.stdout:
out = proc_res.stdout.rstrip()
print(out)
if bug_report:
bug_report.add_file_contents(out, Path('kompile.log'))
proc_res = run_process_2(
args,
write_stdout=tool_mode,
write_stderr=tool_mode,
logger=_LOGGER,
cwd=cwd,
check=check,
)

if bug_report and proc_res.stdout:
bug_report.add_file_contents(proc_res.stdout.rstrip(), Path('kompile.log'))

definition_dir = output_dir if output_dir else _default_output_dir(self.base_args.main_file)
assert definition_dir.is_dir()
Expand Down
8 changes: 1 addition & 7 deletions pyk/src/pyk/ktool/kprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from enum import Enum
from functools import cached_property
from pathlib import Path
from subprocess import CalledProcessError
from tempfile import NamedTemporaryFile
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -107,12 +106,7 @@ def _kast(
gen_glr_parser=gen_glr_parser,
)

try:
return run_process_2(args, write_stderr=True, logger=_LOGGER, check=check)
except CalledProcessError as err:
raise RuntimeError(
f'Command kast exited with code {err.returncode} for: {file}', err.stdout, err.stderr
) from err
return run_process_2(args, logger=_LOGGER, check=check)


def gen_glr_parser(
Expand Down
11 changes: 3 additions & 8 deletions pyk/src/pyk/ktool/kprove.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from enum import Enum
from itertools import chain
from pathlib import Path
from subprocess import CalledProcessError
from typing import TYPE_CHECKING

from ..cli.utils import check_dir_path, check_file_path
Expand Down Expand Up @@ -96,13 +95,9 @@ def _kprove(
dry_run=dry_run,
)

try:
run_args = tuple(chain(command, [str(spec_file)], typed_args, args))
return run_process_2(run_args, write_stderr=True, logger=_LOGGER, env=env, check=check)
except CalledProcessError as err:
raise RuntimeError(
f'Command kprove exited with code {err.returncode} for: {spec_file}', err.stdout, err.stderr, err
) from err
run_args = tuple(chain(command, [str(spec_file)], typed_args, args))

return run_process_2(run_args, logger=_LOGGER, env=env, check=check)


def _build_arg_list(
Expand Down
7 changes: 1 addition & 6 deletions pyk/src/pyk/ktool/krun.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,7 @@ def _krun(
else:
bug_report.add_command(args)

try:
return run_process(args, check=check, pipe_stderr=pipe_stderr, logger=logger or _LOGGER, exec_process=debugger)
except CalledProcessError as err:
raise RuntimeError(
f'Command krun exited with code {err.returncode} for: {input_file}', err.stdout, err.stderr
) from err
return run_process(args, check=check, pipe_stderr=pipe_stderr, logger=logger or _LOGGER, exec_process=debugger)


def _build_arg_list(
Expand Down

0 comments on commit 67ffc46

Please sign in to comment.