Skip to content

Commit

Permalink
Format files in projects/cross/*.py
Browse files Browse the repository at this point in the history
Arguably a lot of this is uglier due to the added newlines but it is the
de-facto style for python, so we should follow that.
  • Loading branch information
arichardson committed Feb 20, 2024
1 parent 626fc50 commit 732985d
Show file tree
Hide file tree
Showing 53 changed files with 2,503 additions and 1,277 deletions.
82 changes: 44 additions & 38 deletions pycheribuild/projects/cross/apache.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
class BuildPcre(CrossCompileAutotoolsProject):
target = "pcre"

repository = SubversionRepository("svn://vcs.pcre.org/pcre",
default_branch="code/trunk")
repository = SubversionRepository("svn://vcs.pcre.org/pcre", default_branch="code/trunk")

native_install_dir = DefaultInstallDir.BOOTSTRAP_TOOLS

Expand All @@ -54,21 +53,22 @@ def configure(self, **kwargs):

class BuildApr(CrossCompileAutotoolsProject):
target = "apr"
repository = GitRepository("https://github.com/CTSRD-CHERI/apr.git",
default_branch="cheri")
repository = GitRepository("https://github.com/CTSRD-CHERI/apr.git", default_branch="cheri")

dependencies = ("libexpat",)

native_install_dir = DefaultInstallDir.BOOTSTRAP_TOOLS

def setup(self):
super().setup()
self.configure_args.extend([
"--enable-threads",
"--enable-posix-shm",
"--with-devrandom",
"--with-expat=" + str(BuildExpat.get_install_dir(self)),
])
self.configure_args.extend(
[
"--enable-threads",
"--enable-posix-shm",
"--with-devrandom",
"--with-expat=" + str(BuildExpat.get_install_dir(self)),
]
)
if self.build_type.is_debug:
self.configure_args.append("--enable-debug")

Expand All @@ -79,17 +79,18 @@ def setup(self):

if not self.compiling_for_host():
# Can't determine these when cross-compiling
self.configure_environment.update(ac_cv_file__dev_zero="yes",
ac_cv_mmap__dev_zero="yes",
# XXX: This might be yes on Linux
ac_cv_func_setpgrp_void="no",
ac_cv_struct_rlimit="yes",
ac_cv_func_sem_open="yes",
apr_cv_process_shared_works="yes",
apr_cv_mutex_robust_shared="yes",
# XXX: This might be yes on Linux
apr_cv_tcp_nodelay_with_cork="no",
)
self.configure_environment.update(
ac_cv_file__dev_zero="yes",
ac_cv_mmap__dev_zero="yes",
# XXX: This might be yes on Linux
ac_cv_func_setpgrp_void="no",
ac_cv_struct_rlimit="yes",
ac_cv_func_sem_open="yes",
apr_cv_process_shared_works="yes",
apr_cv_mutex_robust_shared="yes",
# XXX: This might be yes on Linux
apr_cv_tcp_nodelay_with_cork="no",
)

def configure(self, **kwargs):
self.run_cmd("./buildconf", cwd=self.source_dir)
Expand All @@ -98,21 +99,22 @@ def configure(self, **kwargs):

class BuildApache(CrossCompileAutotoolsProject):
target = "apache"
repository = GitRepository("https://github.com/CTSRD-CHERI/apache-httpd.git",
default_branch="2.4.x-cheri")
repository = GitRepository("https://github.com/CTSRD-CHERI/apache-httpd.git", default_branch="2.4.x-cheri")

dependencies = ("apr", "pcre")

def setup(self):
super().setup()
self.configure_args.extend([
"--enable-layout=FreeBSD",
"--enable-http",
"--enable-mod-ssl",
"--with-expat=" + str(BuildExpat.get_install_dir(self)),
"--with-pcre=" + str(BuildPcre.get_install_dir(self)),
"--with-apr=" + str(BuildApr.get_install_dir(self)),
])
self.configure_args.extend(
[
"--enable-layout=FreeBSD",
"--enable-http",
"--enable-mod-ssl",
"--with-expat=" + str(BuildExpat.get_install_dir(self)),
"--with-pcre=" + str(BuildPcre.get_install_dir(self)),
"--with-apr=" + str(BuildApr.get_install_dir(self)),
]
)
if self.build_type.is_debug:
self.configure_args.append("--enable-debugger-mode")

Expand All @@ -130,12 +132,16 @@ def configure(self, **kwargs):

# gen_test_char rules in server/ assume a native build
if not self.compiling_for_host():
self.run_cmd(str(self.host_CC), "-DCROSS_COMPILE", "-c",
self.source_dir / "server" / "gen_test_char.c",
"-o", "gen_test_char.lo",
cwd=self.build_dir / "server")
self.run_cmd(str(self.host_CC), "gen_test_char.lo", "-o",
"gen_test_char", cwd=self.build_dir / "server")
self.run_cmd(
str(self.host_CC),
"-DCROSS_COMPILE",
"-c",
self.source_dir / "server" / "gen_test_char.c",
"-o",
"gen_test_char.lo",
cwd=self.build_dir / "server",
)
self.run_cmd(str(self.host_CC), "gen_test_char.lo", "-o", "gen_test_char", cwd=self.build_dir / "server")


class BuildSSLProc(CrossCompileCMakeProject):
Expand Down Expand Up @@ -163,4 +169,4 @@ def setup(self):
super().setup()
self.configure_args.append(
"--with-sslproc=" + str(BuildSSLProc.get_install_dir(self)),
)
)
13 changes: 7 additions & 6 deletions pycheribuild/projects/cross/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@


class BuildBash(CrossCompileAutotoolsProject):
repository = GitRepository("https://github.com/CTSRD-CHERI/bash",
default_branch="cheri")
repository = GitRepository("https://github.com/CTSRD-CHERI/bash", default_branch="cheri")
cross_install_dir = DefaultInstallDir.ROOTFS_OPTBASE
path_in_rootfs = "/usr/local"
set_as_root_shell = BoolConfigOption("set-as-root-shell", show_help=True,
help="Set root's shell to bash (in the target rootfs)")
set_as_root_shell = BoolConfigOption(
"set-as-root-shell", show_help=True, help="Set root's shell to bash (in the target rootfs)"
)

def setup(self):
super().setup()
Expand All @@ -63,12 +63,13 @@ def install(self, **kwargs):
self.create_symlink(Path("/usr/local/bin/bash"), self.destdir / "bin/bash", relative=False)
self.add_unique_line_to_file(self.destdir / "etc/shells", "/usr/local/bin/bash")
if self.set_as_root_shell:

def rewrite(old):
new = []
for line in old:
fields = line.split(':')
fields = line.split(":")
if len(fields) == 10 and fields[0] == "root":
line = ':'.join(fields[0:9] + ["/usr/local/bin/bash"])
line = ":".join(fields[0:9] + ["/usr/local/bin/bash"])
new.append(line)
return new

Expand Down
50 changes: 33 additions & 17 deletions pycheribuild/projects/cross/benchmark_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@

# We also build benchmarks for hybrid to see whether those compilation flags change the results
class BenchmarkMixin(_BenchmarkMixinBase):
supported_architectures = (CompilationTargets.ALL_CHERIBSD_TARGETS_WITH_HYBRID_FOR_PURECAP_ROOTFS +
CompilationTargets.ALL_NATIVE)
supported_architectures = (
CompilationTargets.ALL_CHERIBSD_TARGETS_WITH_HYBRID_FOR_PURECAP_ROOTFS + CompilationTargets.ALL_NATIVE
)
default_build_type = BuildType.RELEASE
prefer_full_lto_over_thin_lto = True

Expand All @@ -59,10 +60,15 @@ def optimization_flags(self):
return ["-O3"]
return super().optimization_flags

def run_fpga_benchmark(self, benchmarks_dir: Path, *, output_file: "Optional[str]" = None,
benchmark_script: "Optional[str]" = None,
benchmark_script_args: "Optional[list[str]]" = None,
extra_runbench_args: "Optional[list[str]]" = None):
def run_fpga_benchmark(
self,
benchmarks_dir: Path,
*,
output_file: "Optional[str]" = None,
benchmark_script: "Optional[str]" = None,
benchmark_script_args: "Optional[list[str]]" = None,
extra_runbench_args: "Optional[list[str]]" = None,
):
assert benchmarks_dir is not None
assert output_file is not None, "output_file must be set to a valid value"
xtarget = self.crosscompile_target
Expand All @@ -80,12 +86,16 @@ def run_fpga_benchmark(self, benchmarks_dir: Path, *, output_file: "Optional[str
basic_args = []
if self.config.benchmark_with_qemu:
from ...projects.build_qemu import BuildQEMU

qemu_path = BuildQEMU.qemu_binary(self)
qemu_ssh_socket = find_free_port()
if not qemu_path.exists():
self.fatal("QEMU binary", qemu_path, "doesn't exist")
basic_args += ["--use-qemu-instead-of-fpga", "--qemu-path=" + str(qemu_path),
"--qemu-ssh-port=" + str(qemu_ssh_socket.port)]
basic_args += [
"--use-qemu-instead-of-fpga",
"--qemu-path=" + str(qemu_path),
"--qemu-ssh-port=" + str(qemu_ssh_socket.port),
]
elif not self.compiling_for_mips(include_purecap=True):
self.fatal("run_fpga_benchmark has not been updated for RISC-V/AArch64")
return
Expand All @@ -101,11 +111,13 @@ def run_fpga_benchmark(self, benchmarks_dir: Path, *, output_file: "Optional[str
env_var = "LD_64_PRELOAD"
else:
env_var = "LD_PRELOAD"
pre_cmd = "export {}={};".format(env_var,
shlex.quote("/tmp/benchdir/" + self.config.benchmark_ld_preload.name))
pre_cmd = "export {}={};".format(
env_var, shlex.quote("/tmp/benchdir/" + self.config.benchmark_ld_preload.name)
)
if env_var == "LD_64C_PRELOAD":
pre_cmd += "export {}={};".format("LD_CHERI_PRELOAD",
shlex.quote("/tmp/benchdir/" + self.config.benchmark_ld_preload.name))
pre_cmd += "export {}={};".format(
"LD_CHERI_PRELOAD", shlex.quote("/tmp/benchdir/" + self.config.benchmark_ld_preload.name)
)
runbench_args.append("--pre-command=" + pre_cmd)
if self.config.benchmark_fpga_extra_args:
basic_args.extend(self.config.benchmark_fpga_extra_args)
Expand All @@ -115,6 +127,7 @@ def run_fpga_benchmark(self, benchmarks_dir: Path, *, output_file: "Optional[str
runbench_args.append("--interact")

from ...projects.cross.cheribsd import BuildCheriBsdMfsKernel, ConfigPlatform

if self.config.benchmark_with_qemu:
# When benchmarking with QEMU we always spawn a new instance
target = self.target_info
Expand All @@ -128,10 +141,12 @@ def run_fpga_benchmark(self, benchmarks_dir: Path, *, output_file: "Optional[str
# use a bitfile from jenkins. TODO: add option for overriding
assert xtarget.is_riscv(include_purecap=True)
basic_args.append("--jenkins-bitfile")
mfs_kernel = BuildCheriBsdMfsKernel.get_instance_for_cross_target(xtarget.get_rootfs_target(), self.config,
caller=self)
kernel_config = mfs_kernel.default_kernel_config(ConfigPlatform.GFE,
benchmark=not self.config.benchmark_with_debug_kernel)
mfs_kernel = BuildCheriBsdMfsKernel.get_instance_for_cross_target(
xtarget.get_rootfs_target(), self.config, caller=self
)
kernel_config = mfs_kernel.default_kernel_config(
ConfigPlatform.GFE, benchmark=not self.config.benchmark_with_debug_kernel
)
kernel_image = mfs_kernel.get_kernel_install_path(kernel_config)
basic_args.append("--kernel-img=" + str(kernel_image))
else:
Expand All @@ -150,4 +165,5 @@ def run_fpga_benchmark(self, benchmarks_dir: Path, *, output_file: "Optional[str
qemu_ssh_socket.socket.close()
self.run_cmd(
[str(cheribuild_path / "vcu118-bsd-boot.py"), *basic_args, "-vvvvv", "runbench", *runbench_args],
give_tty_control=True)
give_tty_control=True,
)
Loading

0 comments on commit 732985d

Please sign in to comment.