Skip to content

Commit

Permalink
Merge branch 'eero/root-hash' into 'master'
Browse files Browse the repository at this point in the history
Add target to print root files hash

Prints a hash of the files being included in rootfs. This will allow us to verify that rearrangement MRs have no real changes.

```
bazel run ic-os/<variant>/envs/<version>:echo-root-files-hash
``` 

See merge request dfinity-lab/public/ic!19222
  • Loading branch information
Bownairo committed May 13, 2024
2 parents a943af7 + 12da62e commit 8f05180
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
27 changes: 26 additions & 1 deletion ic-os/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ load("//bazel:output_files.bzl", "output_files")
load("//gitlab-ci/src/artifacts:upload.bzl", "upload_artifacts")
load("//ic-os/bootloader:defs.bzl", "build_grub_partition")
load("//ic-os/rootfs:boundary-guestos.bzl", boundary_rootfs_files = "rootfs_files")
load("//toolchains/sysimage:toolchain.bzl", "build_container_base_image", "build_container_filesystem", "disk_image", "ext4_image", "inject_files", "sha256sum", "tar_extract", "upgrade_image")
load("//toolchains/sysimage:toolchain.bzl", "build_container_base_image", "build_container_filesystem", "disk_image", "ext4_image", "inject_files", "sha256sum", "tar_extract", "tree_hash", "upgrade_image")

def icos_build(
name,
Expand Down Expand Up @@ -118,6 +118,31 @@ def icos_build(
tags = ["manual"],
)

# Helpful tool to print a hash of all input rootfs files
tree_hash(
name = "root-files-hash",
src = image_deps["rootfs_files"],
tags = ["manual"],
)

native.genrule(
name = "echo-root-files-hash",
srcs = [
":root-files-hash",
],
outs = ["root-files-hash-script"],
cmd = """
HASH="$(location :root-files-hash)"
cat <<EOF > $@
#!/usr/bin/env bash
set -euo pipefail
cat $$HASH
EOF
""",
executable = True,
tags = ["manual"],
)

# -------------------- Extract root partition --------------------

ext4_image(
Expand Down
25 changes: 25 additions & 0 deletions toolchains/sysimage/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,28 @@ sha256sum = rule(
),
},
)

def _tree_hash_impl(ctx):
out = ctx.actions.declare_file(ctx.label.name)
input_paths = []
for src in sorted(ctx.attr.src.items(), key = lambda v: v[1]):
input_paths.append(src[0].files.to_list()[0].path)
input_paths = " ".join(input_paths)

ctx.actions.run_shell(
inputs = ctx.files.src,
outputs = [out],
command = "cat {} | sha256sum | sed -e 's/ \\+-//' > {}".format(input_paths, out.path),
)

return [DefaultInfo(files = depset([out]), runfiles = ctx.runfiles([out]))]

tree_hash = rule(
implementation = _tree_hash_impl,
attrs = {
"src": attr.label_keyed_string_dict(
allow_files = True,
mandatory = True,
),
},
)

0 comments on commit 8f05180

Please sign in to comment.