Skip to content

Commit

Permalink
Fix bug in the Jenkins install dir hack
Browse files Browse the repository at this point in the history
The root cause was that incorrect indentation had turned the two for
loops into a nested for loop that would set the paths before the loop
assigning to _install_dir was complete.
  • Loading branch information
arichardson committed Aug 11, 2023
1 parent e4278e8 commit 66fd69f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
68 changes: 35 additions & 33 deletions pycheribuild/jenkins_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,39 @@
def jenkins_override_install_dirs_hack(cheri_config: CheriConfig, install_prefix: Path):
expected_install_path = Path(f"{cheri_config.output_root}{install_prefix}")
# Ugly workaround to override all install dirs to go to the tarball
for tgt in target_manager.targets(cheri_config):
if isinstance(tgt, SimpleTargetAlias):
continue
cls = tgt.project_class
if issubclass(cls, Project) and not isinstance(tgt, MultiArchTargetAlias):
cls._default_install_dir_fn = Path(expected_install_path)
i = inspect.getattr_static(cls, "_install_dir")
assert isinstance(i, CommandLineConfigOption)
# But don't change it if it was specified on the command line. Note: This also does the config
# inheritance: i.e. setting --cheribsd/install-dir will also affect cheribsd-cheri/cheribsd-mips
# noinspection PyTypeChecker
from_cmdline = i.load_option(cheri_config, cls, cls, return_none_if_default=True)
if from_cmdline is not None:
status_update("Install directory for", cls.target, "was specified on commandline:", from_cmdline)
else:
cls._install_dir = cheri_config.output_root
cls._check_install_dir_conflict = False
all_targets = [
x for x in target_manager.targets(cheri_config)
if not isinstance(x, (SimpleTargetAlias, MultiArchTargetAlias)) and issubclass(x.project_class, Project)
]
for target in all_targets:
cls = target.project_class
cls._default_install_dir_fn = Path(expected_install_path)
i = inspect.getattr_static(cls, "_install_dir")
assert isinstance(i, CommandLineConfigOption)
# But don't change it if it was specified on the command line. Note: This also does the config
# inheritance: i.e. setting --cheribsd/install-dir will also affect cheribsd-cheri/cheribsd-mips
# noinspection PyTypeChecker
from_cmdline = i.load_option(cheri_config, cls, cls, return_none_if_default=True)
if from_cmdline is not None:
status_update("Install directory for", cls.target, "was specified on commandline:", from_cmdline)
else:
cls._install_dir = cheri_config.output_root
cls._check_install_dir_conflict = False

Target.instantiating_targets_should_warn = False
# Override the installation directory for all enabled targets
for name in cheri_config.targets:
target = target_manager.get_target_raw(name)
# noinspection PyProtectedMember
project = target._get_or_create_project_no_setup(None, cheri_config, caller=None)
if isinstance(project, Project):
# Using "/" as the install prefix results inconsistently prefixing some paths with '/usr/'.
# To avoid this, just use the full install path as the prefix.
if install_prefix == Path("/"):
project._install_prefix = expected_install_path
project.destdir = Path("/")
else:
project._install_prefix = install_prefix
project.destdir = cheri_config.output_root
assert project.real_install_root_dir == expected_install_path
Target.instantiating_targets_should_warn = False
# Now that we have set the _install_dir member, override the prefix/destdir after instantiating.
for target in all_targets:
# noinspection PyProtectedMember
project = target._get_or_create_project_no_setup(None, cheri_config, caller=None)
assert isinstance(project, Project)
i = inspect.getattr_static(target.project_class, "_install_dir")
assert isinstance(i, Path)
# Using "/" as the install prefix results inconsistently prefixing some paths with '/usr/'.
# To avoid this, just use the full install path as the prefix.
if install_prefix == Path("/"):
project._install_prefix = expected_install_path
project.destdir = Path("/")
else:
project._install_prefix = install_prefix
project.destdir = cheri_config.output_root
assert project.real_install_root_dir == expected_install_path
2 changes: 0 additions & 2 deletions tests/test_argument_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,6 @@ def _check_install_dirs(args, expected_install_dir):
)


@pytest.mark.xfail(reason="Bug after refactoring")
def test_jenkins_hack_disk_image():
# Regression test for the refactoring of the Jenkins installation directories hack:
# After refactoring the disk image target was trying to look for files in tarball/ instead of using
Expand All @@ -1398,5 +1397,4 @@ def test_jenkins_hack_disk_image():
"disk-image-aarch64", config, BuildCheriBSDDiskImage,
)
assert disk_image.disk_image_path == Path("/tmp/tarball/cheribsd-aarch64.img")
# FIXME: this is failing
assert disk_image.rootfs_dir == Path("/tmp/tarball/rootfs")

0 comments on commit 66fd69f

Please sign in to comment.