From 78af3487efa2a51ae6a3dc6444050290d5859656 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Mon, 31 Jul 2023 09:37:20 -0700 Subject: [PATCH] Stop using fixlinks tool during sysroot installation CheriBSD has not installed broken absolute symlinks for many years, we can retire this tool now. --- pycheribuild/files/fixlinks.c | 59 ------------------------- pycheribuild/projects/cross/cheribsd.py | 13 +----- 2 files changed, 1 insertion(+), 71 deletions(-) delete mode 100644 pycheribuild/files/fixlinks.c diff --git a/pycheribuild/files/fixlinks.c b/pycheribuild/files/fixlinks.c deleted file mode 100644 index 72a195d6c..000000000 --- a/pycheribuild/files/fixlinks.c +++ /dev/null @@ -1,59 +0,0 @@ -/* asprintf() prototype needs _GNU_SOURCE on Linux */ -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - DIR *dir = opendir("."); - struct dirent *file; - char *dirname; - int links = 0, fixed = 0; - - while ((file = readdir(dir)) != NULL) - { - char target[1024]; - ssize_t index = - readlink(file->d_name, target, sizeof(target) - 1); - - if (index < 0) { - // Not a symlink? - if (errno == EINVAL) - continue; - - err(EX_OSERR, "error in readlink('%s')", file->d_name); - } - - links++; - - // Fix absolute paths. - if (target[0] == '/') { - target[index] = 0; - - char *newName; - asprintf(&newName, "../..%s", target); - - if (unlink(file->d_name)) - err(EX_OSERR, "Failed to remove old link"); - - if (symlink(newName, file->d_name)) - err(EX_OSERR, "Failed to create link"); - free(newName); - fixed++; - } - } - closedir(dir); - - if (links == 0) - errx(EX_USAGE, "no symbolic links in %s", getcwd(NULL, 0)); - - printf("fixed %d/%d symbolic links\n", fixed, links); -} diff --git a/pycheribuild/projects/cross/cheribsd.py b/pycheribuild/projects/cross/cheribsd.py index 45f2f31f8..889ea78aa 100644 --- a/pycheribuild/projects/cross/cheribsd.py +++ b/pycheribuild/projects/cross/cheribsd.py @@ -60,7 +60,7 @@ from ...config.target_info import AutoVarInit, CrossCompileTarget from ...config.target_info import CompilerType as FreeBSDToolchainKind from ...processutils import latest_system_clang_tool, print_command -from ...utils import OSInfo, ThreadJoiner, cached_property, classproperty, include_local_file, is_jenkins_build +from ...utils import OSInfo, ThreadJoiner, cached_property, classproperty, is_jenkins_build def _arch_suffixed_custom_install_dir(prefix: str) -> "ComputedDefaultValue[Path]": @@ -2017,14 +2017,6 @@ def __init__(self, *args, **kwargs) -> None: self.bsdtar_cmd = "bsdtar" self.install_dir = self.target_info.sdk_root_dir - def fix_symlinks(self) -> None: - # copied from the build_sdk.sh script - # TODO: we could do this in python as well, but this method works - # FIXME: should no longer be needed - fixlinks_src = include_local_file("files/fixlinks.c") - self.run_cmd("cc", "-x", "c", "-", "-o", self.install_dir / "bin/fixlinks", input=fixlinks_src) - self.run_cmd(self.install_dir / "bin/fixlinks", cwd=self.cross_sysroot_path / "usr/lib") - def check_system_dependencies(self) -> None: super().check_system_dependencies() self.check_required_system_tool("bsdtar", cheribuild_target="bsdtar", apt="libarchive-tools") @@ -2106,9 +2098,6 @@ def create_sysroot(self) -> None: if not (self.cross_sysroot_path / "lib/libc.so.7").is_file(): self.fatal(self.cross_sysroot_path, "is missing the libc library, install seems to have failed!") - # fix symbolic links in the sysroot: - self.info("Fixing absolute paths in symbolic links inside lib directory...") - self.fix_symlinks() # create an archive to make it easier to copy the sysroot to another machine self.delete_file(self.sysroot_archive, print_verbose_only=True) self.run_cmd("tar", "-caf", self.sysroot_archive, self.cross_sysroot_path.name,