Skip to content

Commit

Permalink
Fix latest ruff checks and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
arichardson committed Mar 22, 2024
1 parent 5984f75 commit 656d150
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
args: [ "--fix=lf" ]
- id: check-case-conflict
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.3.0' # Ruff version.
rev: 'v0.3.4' # Ruff version.
hooks:
- id: ruff
stages: [ push, commit, manual ]
Expand Down
15 changes: 6 additions & 9 deletions pycheribuild/boot_cheribsd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,15 @@ def set_ld_library_path_with_sysroot(qemu: CheriBSDInstance):
noncheri_ld_lib_path_var = "LD_LIBRARY_PATH" if not qemu.xtarget.is_cheri_purecap() else "LD_64_LIBRARY_PATH"
cheri_ld_lib_path_var = "LD_LIBRARY_PATH" if qemu.xtarget.is_cheri_purecap() else "LD_64C_LIBRARY_PATH"
qemu.run(
"export {var}=/{lib}:/usr/{lib}:/usr/local/{lib}:/sysroot/{lib}:/sysroot/usr/{lib}:/sysroot/{hybrid}/lib:"
"/sysroot/usr/local/{lib}:/sysroot/{noncheri}/lib:${var}".format(
lib=non_cheri_libdir,
hybrid=hybrid_install_prefix,
noncheri=nocheri_install_prefix,
var=noncheri_ld_lib_path_var,
),
f"export {noncheri_ld_lib_path_var}=/{non_cheri_libdir}:/usr/{non_cheri_libdir}:/usr/local/{non_cheri_libdir}:"
f"/sysroot/{non_cheri_libdir}:/sysroot/usr/{non_cheri_libdir}:/sysroot/{hybrid_install_prefix}/lib:"
f"/sysroot/usr/local/{non_cheri_libdir}:/sysroot/{nocheri_install_prefix}/lib:${noncheri_ld_lib_path_var}",
timeout=3,
)
qemu.run(
"export {var}=/{l}:/usr/{l}:/usr/local/{l}:/sysroot/{l}:/sysroot/usr/{l}:/sysroot/usr/local/{l}:"
"/sysroot/{prefix}/lib:${var}".format(prefix=purecap_install_prefix, l=cheri_libdir, var=cheri_ld_lib_path_var),
f"export {cheri_ld_lib_path_var}=/{cheri_libdir}:/usr/{cheri_libdir}:/usr/local/{cheri_libdir}:"
f"/sysroot/{cheri_libdir}:/sysroot/usr/{cheri_libdir}:/sysroot/usr/local/{cheri_libdir}:"
f"/sysroot/{purecap_install_prefix}/lib:${cheri_ld_lib_path_var}",
timeout=3,
)
if cheri_ld_lib_path_var == "LD_64C_LIBRARY_PATH":
Expand Down
5 changes: 3 additions & 2 deletions pycheribuild/projects/cross/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ def run_tests(self):
self.fatal("running x86 tests is not implemented yet")
return
# testing, not benchmarking -> run only once: (-s small / -s large?)
test_command = "cd '/build/{dirname}' && ./run_jenkins-bluehive.sh -d0 -r1 -s {size} {version}".format(
dirname=self.bundle_dir.name, size=self.benchmark_size, version=self.benchmark_version
test_command = (
f"cd '/build/{self.bundle_dir.name}' && "
f"./run_jenkins-bluehive.sh -d0 -r1 -s {self.benchmark_size} {self.benchmark_version}"
)
self.target_info.run_cheribsd_test_script(
"run_simple_tests.py", "--test-command", test_command, "--test-timeout", str(120 * 60), mount_builddir=True
Expand Down
5 changes: 2 additions & 3 deletions pycheribuild/projects/cross/doom.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def install(self, **kwargs):
self.install_dir / "bin" / wad,
overwrite=True,
mode=0o755,
contents='#!/bin/sh\nexec {0}/bin/chocolate-doom -iwad {0}/{1} "$@"\n'.format(
self.install_prefix, wadpath
),
contents=f"#!/bin/sh\n"
f'exec {self.install_prefix}/bin/chocolate-doom -iwad {self.install_prefix}/{wadpath} "$@"\n',
)
5 changes: 2 additions & 3 deletions pycheribuild/projects/cross/opensbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ def install(self, **kwargs):

def _fw_jump_path(self) -> Path:
# share/opensbi/lp64/generic/firmware//fw_payload.bin
return self.install_dir / "share/opensbi/{abi}/generic/firmware/fw_jump.elf".format(
abi=self.target_info.get_riscv_abi(self.crosscompile_target, softfloat=True)
)
abi = self.target_info.get_riscv_abi(self.crosscompile_target, softfloat=True)
return self.install_dir / f"share/opensbi/{abi}/generic/firmware/fw_jump.elf"

@classmethod
def get_nocap_instance(cls, caller, cpu_arch=CPUArchitecture.RISCV64) -> "BuildOpenSBI":
Expand Down
5 changes: 3 additions & 2 deletions pycheribuild/projects/cross/simple_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ def run_tests(self):
return
self.create_test_dir(self.build_dir / "test-dir")
# testing, not benchmarking -> run only once: (-s small / -s large?)
test_command = "cd /build/test-dir && ./run_jenkins-bluehive.sh -d0 -r1 -o {output} -a {tgt}".format(
tgt=self.archname_column, output=self.default_statcounters_csv_name
test_command = (
f"cd /build/test-dir && "
f"./run_jenkins-bluehive.sh -d0 -r1 -o {self.default_statcounters_csv_name} -a {self.archname_column}"
)
self.target_info.run_cheribsd_test_script(
"run_simple_tests.py", "--test-command", test_command, "--test-timeout", str(120 * 60), mount_builddir=True
Expand Down
5 changes: 2 additions & 3 deletions pycheribuild/projects/disk_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,9 +954,8 @@ def __process(self):

if not self.makefs_cmd or not self.makefs_cmd.exists():
self.fatal(
"Missing makefs command ('{}')! Should be found in FreeBSD build dir ({})".format(
self.makefs_cmd, freebsd_builddir
),
f"Missing makefs command ('{self.makefs_cmd}')! "
f"Should be found in FreeBSD build dir ({freebsd_builddir})",
fixit_hint="Pass an explicit path to makefs by setting the MAKEFS_CMD environment variable",
)
self.info("Disk image will be saved to", self.disk_image_path)
Expand Down
28 changes: 14 additions & 14 deletions pycheribuild/projects/fvp_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,16 @@ def compile(self, **kwargs):
with tempfile.TemporaryDirectory() as td:
self._compile(Path(td))

def _compile(self, fake_compiler_dir: Path):
def _compile(self, fake_cc_dir: Path):
acpica_build = BuildMorelloACPICA.get_build_dir(self, cross_target=CompilationTargets.NATIVE)
iasl = acpica_build / "generate/unix/bin/iasl"
if not iasl.exists():
self.fatal("Missing iasl tool, run the", BuildMorelloACPICA.target, "first.")
# Create the fake compiler directory with the tools and a clang wrapper script that forces bfd
# Also disable lto since we don't install the LLVM LTO plugin
self.write_file(
fake_compiler_dir / "clang",
contents="""#!/usr/bin/env python3
fake_cc_dir / "clang",
contents=f"""#!/usr/bin/env python3
import subprocess
import sys
Expand All @@ -324,12 +324,12 @@ def _compile(self, fake_compiler_dir: Path):
if arg.startswith("-Wl,-plugin-opt="):
continue
args.append(arg)
subprocess.check_call(["{real_clang}", "-B{fake_dir}"] + args + ["-fuse-ld=bfd", "-fno-lto", "-Qunused-arguments"])
""".format(real_clang=self.CC, fake_dir=fake_compiler_dir),
subprocess.check_call(["{self.CC}", "-B{fake_cc_dir}"] + args + ["-fuse-ld=bfd", "-fno-lto", "-Qunused-arguments"])
""",
overwrite=True,
mode=0o755,
)
self.run_cmd(fake_compiler_dir / "clang", "-v") # check that the script works
self.run_cmd(fake_cc_dir / "clang", "-v") # check that the script works
for i in (
"llvm-objcopy",
"llvm-objdump",
Expand All @@ -344,14 +344,14 @@ def _compile(self, fake_compiler_dir: Path):
"size",
"llvm-size",
):
self.create_symlink(self.sdk_bindir / i, fake_compiler_dir / i, relative=False)
self.create_symlink(self.sdk_bindir / i, fake_cc_dir / i, relative=False)

# EDK2 needs bfd until the lld target is merged
bfd_path = BuildGDB.get_install_dir(self, cross_target=CompilationTargets.NATIVE) / "bin/ld.bfd"
if not bfd_path.exists():
self.fatal("Missing ld.bfd, please run `cheribuild.py gdb-native --reconfigure`")
self.create_symlink(bfd_path, fake_compiler_dir / "ld", relative=False)
self.create_symlink(bfd_path, fake_compiler_dir / "ld.bfd", relative=False)
self.create_symlink(bfd_path, fake_cc_dir / "ld", relative=False)
self.create_symlink(bfd_path, fake_cc_dir / "ld.bfd", relative=False)
firmware_ver = (
self.run_cmd(
"git",
Expand All @@ -370,12 +370,12 @@ def _compile(self, fake_compiler_dir: Path):
# FIRMWARE_VER="${FIRMWARE_VER}-dirty"
# fi
with self.set_env(
CROSS_COMPILE=str(fake_compiler_dir) + "/",
CLANG_BIN=fake_compiler_dir,
CROSS_COMPILE=str(fake_cc_dir) + "/",
CLANG_BIN=fake_cc_dir,
EDK2_TOOLCHAIN="CLANG38",
VERBOSE=1,
IASL_PREFIX=str(iasl.parent) + "/",
PATH=str(fake_compiler_dir) + ":" + os.getenv("PATH"),
PATH=str(fake_cc_dir) + ":" + os.getenv("PATH"),
):
platform_desc = "Platform/ARM/Morello/MorelloPlatformFvp.dsc"
if not (self.source_dir / "edk2-platforms" / platform_desc).exists():
Expand All @@ -384,8 +384,8 @@ def _compile(self, fake_compiler_dir: Path):
. edksetup.sh --reconfig
make -C BaseTools
export PACKAGES_PATH=:{self.source_dir}:{self.source_dir}/edk2-platforms:
export CLANG38_AARCH64_PREFIX={fake_compiler_dir}/llvm-
export CLANG38_BIN={fake_compiler_dir}/
export CLANG38_AARCH64_PREFIX={fake_cc_dir}/llvm-
export CLANG38_BIN={fake_cc_dir}/
build -n {self.config.make_jobs} -a AARCH64 -t CLANG38 -p {platform_desc} \
-b {self.build_mode} -s -D EDK2_OUT_DIR=Build/morellofvp -D PLAT_TYPE_FVP \
-D ENABLE_MORELLO_CAP -D FIRMWARE_VER={firmware_ver}"""
Expand Down
8 changes: 4 additions & 4 deletions pycheribuild/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def __get__(self, instance, owner=None) -> Type_T:
try:
cache = instance.__dict__
except AttributeError: # not all objects have __dict__ (e.g. class defines slots)
msg = "No '__dict__' attribute on {} instance to cache {} property.".format(
type(instance).__name__, self.attrname
msg = (
f"No '__dict__' attribute on {type(instance).__name__} instance to cache {self.attrname} property."
)
raise TypeError(msg) from None
val = cache.get(self.attrname, _NOT_FOUND)
Expand All @@ -191,8 +191,8 @@ def __get__(self, instance, owner=None) -> Type_T:
cache[self.attrname] = val
except TypeError:
msg = (
"The '__dict__' attribute on {} instance does not support item assignment for"
" caching {} property.".format(type(instance).__name__, self.attrname)
f"The '__dict__' attribute on {type(instance).__name__} instance does not support "
f"item assignment for caching {self.attrname} property."
)
raise TypeError(msg) from None
return val
Expand Down
9 changes: 4 additions & 5 deletions test-scripts/run_morello_webkit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@

def setup_webkit_tests(qemu: boot_cheribsd.CheriBSDInstance, _: argparse.Namespace) -> None:
qemu.checked_run(
"export LD_LIBRARY_PATH=/opt/{ta}/webkit/lib:/usr/local/{ta}/lib/".format(ta=qemu.xtarget.generic_arch_suffix),
f"export LD_LIBRARY_PATH=/opt/{qemu.xtarget.generic_arch_suffix}/webkit/lib:"
f"/usr/local/{qemu.xtarget.generic_arch_suffix}/lib/",
)


Expand Down Expand Up @@ -81,10 +82,8 @@ def run_webkit_tests(qemu: boot_cheribsd.CheriBSDInstance, args: argparse.Namesp
starttime = datetime.datetime.utcnow()
try:
qemu.checked_run(
"/opt/{ta}/webkit/bin/jsc /source/PerformanceTests/SunSpider/tests/sunspider-1.0.2/{test}".format(
ta=qemu.xtarget.generic_arch_suffix,
test=test,
),
f"/opt/{qemu.xtarget.generic_arch_suffix}/webkit/bin/jsc"
f" /source/PerformanceTests/SunSpider/tests/sunspider-1.0.2/{test}",
timeout=300,
)
except boot_cheribsd.CheriBSDCommandFailed as e:
Expand Down

0 comments on commit 656d150

Please sign in to comment.