Skip to content

Commit

Permalink
Merge branch 'aseitz/pprinter-chroot-compile' into 'main'
Browse files Browse the repository at this point in the history
Support chroot compilation via binary printer for nightly tests

See merge request rewriting/ddisasm!1193
  • Loading branch information
aeflores committed Mar 28, 2024
2 parents c008329 + 79c86f1 commit 25426ea
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions tests/disassemble_reassemble_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import os
import shlex
import shutil
import stat
import subprocess
import tempfile
from dataclasses import dataclass
from pathlib import Path
from timeit import default_timer as timer
Expand Down Expand Up @@ -242,18 +244,46 @@ def binary_print(
binary_path,
]

if compiler:
cmd.append(f"--use-gcc={compiler}")
if build_object:
cmd.append("--object")
for flag in extra_flags:
cmd.append(f"--compiler-arg={flag}")

print("# Binary printing", ir_path, "into", binary_path)
return subprocess.run(
cmd,
check=check,
)
with contextlib.ExitStack() as stack:
if MAKE_CHROOT:
# Generate a script that executes the compiler in the chroot, and
# instruct gtirb-pprinter to use this script instead of gcc.
chroot_args = build_chroot_wrapper()
chroot_args.append(compiler or "gcc")
chroot_args.append("$@")
script_content = (
"#!/bin/bash\n"
# Copy intermediate files generated by gtirb-pprinter into the
# chroot tmp directory, so they exist where they are specified
# by the arguments generated by gtirb-pprinter.
f"cp -r /tmp {MAKE_CHROOT_ROOT}\n"
# Run gcc in the chroot.
f'{" ".join(chroot_args)}\n'
# gtirb-pprinter creates results in /tmp and then copies to
# the destination, so we have to copy /tmp files back.
f"cp -r {MAKE_CHROOT_ROOT}/tmp/* /tmp\n"
# Clean up the files we created.
f"rm -r {MAKE_CHROOT_ROOT}/tmp/*\n"
)

tmpdir = Path(stack.enter_context(tempfile.TemporaryDirectory()))
chroot_script = tmpdir / "compile.sh"
chroot_script.write_text(script_content)
chroot_script.chmod(chroot_script.stat().st_mode | stat.S_IXUSR)

cmd.append(f"--use-gcc={chroot_script}")
elif compiler:
cmd.append(f"--use-gcc={compiler}")
if build_object:
cmd.append("--object")
for flag in extra_flags:
cmd.append(f"--compiler-arg={flag}")

print("# Binary printing", ir_path, "into", binary_path)
return subprocess.run(
cmd,
check=check,
)


def link(
Expand Down

0 comments on commit 25426ea

Please sign in to comment.