Leopold | 7fbf104 | 2023-01-06 19:57:37 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | # Tell wrapper to not touch sandbox |
| 5 | export MONOGON_SYSROOT_REBUILD=1 |
| 6 | |
| 7 | # Packages to install. Make sure to document the reason for including each package. |
| 8 | PKGS=( |
| 9 | # Common base toolchain used across the tree. |
| 10 | "binutils" |
| 11 | "gcc" |
| 12 | "python3" |
| 13 | "python-unversioned-command" |
| 14 | "glibc-static" |
| 15 | |
| 16 | # Kernel build |
| 17 | "flex" |
| 18 | "bison" |
| 19 | "elfutils-libelf-devel" |
| 20 | "openssl-devel" |
| 21 | "diffutils" |
| 22 | "bc" |
| 23 | "perl" |
| 24 | "lz4" |
| 25 | |
| 26 | # EDK2 |
| 27 | "libuuid-devel" |
| 28 | "util-linux" |
| 29 | "nasm" |
| 30 | "acpica-tools" |
| 31 | |
| 32 | # TPM emulator for testing |
| 33 | "swtpm-tools" |
| 34 | |
| 35 | # Clang/LLVM (for EFI toolchain) |
| 36 | "clang" |
| 37 | "llvm" |
| 38 | "lld" |
| 39 | |
| 40 | # image_gcp rule |
| 41 | "tar" |
| 42 | |
| 43 | # ktest |
| 44 | "qemu-system-x86-core" |
| 45 | |
| 46 | # musl-host-gcc |
| 47 | "rsync" |
| 48 | "xz" |
| 49 | |
| 50 | # Packages included to stabilize SAT solution when there are equal scores. |
| 51 | "fedora-release-identity-container" |
| 52 | "coreutils-single" |
| 53 | "curl-minimal" |
| 54 | "libcurl-minimal" |
| 55 | "glibc-langpack-en" |
| 56 | "selinux-policy-minimum" |
| 57 | ) |
| 58 | |
| 59 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 60 | REPO=third_party/sandboxroot/repo.yaml |
| 61 | BAZEL_ARGS="--noworkspace_rc --bazelrc ${DIR}/../../.bazelrc.sandboxroot" |
| 62 | |
| 63 | # Fetch latest repository metadata |
| 64 | bazel ${BAZEL_ARGS} run //:bazeldnf -- fetch --repofile $REPO |
| 65 | |
| 66 | # Write BUILD.bazel template |
| 67 | cat <<EOF > ${DIR}/BUILD.bazel.in |
| 68 | load("@bazeldnf//:deps.bzl", "rpmtree") |
| 69 | load("@bazeldnf//:def.bzl", "bazeldnf") |
| 70 | |
| 71 | bazeldnf( |
| 72 | name = "sandboxroot", |
| 73 | command = "sandbox", |
| 74 | tar = ":sandbox", |
| 75 | ) |
| 76 | |
| 77 | EOF |
| 78 | |
| 79 | touch ${DIR}/repositories.bzl.in |
| 80 | |
| 81 | # Create new sandbox root |
| 82 | bazel ${BAZEL_ARGS} \ |
| 83 | run //:bazeldnf -- rpmtree \ |
| 84 | --repofile third_party/sandboxroot/repo.yaml \ |
| 85 | --name sandbox \ |
| 86 | --nobest \ |
| 87 | --buildfile third_party/sandboxroot/BUILD.bazel.in \ |
| 88 | --workspace third_party/sandboxroot/repositories.bzl.in \ |
| 89 | ${PKGS[@]} |
| 90 | |
| 91 | # Verify package signatures |
| 92 | bazel ${BAZEL_ARGS} run //:bazeldnf -- verify \ |
| 93 | --repofile third_party/sandboxroot/repo.yaml \ |
| 94 | --workspace third_party/sandboxroot/repositories.bzl.in |
| 95 | |
| 96 | # Write out repositories.bzl and clean up. |
| 97 | # |
| 98 | # Ideally, bazeldnf would support the format natively: |
| 99 | # https://github.com/rmohr/bazeldnf/issues/26 |
| 100 | cat <<EOF > ${DIR}/repositories.bzl |
| 101 | load("@bazeldnf//:deps.bzl", "rpm") |
| 102 | |
| 103 | def sandbox_dependencies(): |
| 104 | $(cat ${DIR}/repositories.bzl.in | sed 's/^/ /') |
| 105 | EOF |
| 106 | |
| 107 | mv ${DIR}/BUILD.bazel.in ${DIR}/BUILD.bazel |
| 108 | rm ${DIR}/repositories.bzl.in |