From 6362220605297601571156c684e9df236052bede Mon Sep 17 00:00:00 2001 From: Lutz Reinhardt Date: Mon, 12 Oct 2026 15:23:10 +0000 Subject: [PATCH] Support directories being passed into ext4() A label like `@vsomeip` consists of directories like `include/`. With `-r` directories are now correctly included in the ext4 image. --- rules/linux/tools/create_image.sh | 2 +- tests/BUILD | 12 ++++++++++++ tests/directory_artifact.bzl | 14 ++++++++++++++ tests/ext4_test.sh | 3 +++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 tests/directory_artifact.bzl diff --git a/rules/linux/tools/create_image.sh b/rules/linux/tools/create_image.sh index b927084..547a8e5 100755 --- a/rules/linux/tools/create_image.sh +++ b/rules/linux/tools/create_image.sh @@ -39,7 +39,7 @@ while [ "$#" -gt 0 ]; do shift 2 ;; F) - "$coreutils" cp "$3" "$stage/$2" + "$coreutils" cp -rL "$3" "$stage/$2" shift 3 ;; L) diff --git a/tests/BUILD b/tests/BUILD index 406819d..c2e13ff 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -13,6 +13,11 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "pkg_mklink") load("@score_rules_imagefs//rules/linux:ext4.bzl", "ext4") +load(":directory_artifact.bzl", "directory_artifact") + +directory_artifact( + name = "directory_artifact", +) pkg_files( name = "rootfs_files", @@ -20,6 +25,12 @@ pkg_files( prefix = "etc", ) +pkg_files( + name = "directory_files", + srcs = [":directory_artifact"], + prefix = "opt", +) + pkg_mklink( name = "hello_link", link_name = "usr/share/hello.txt", @@ -29,6 +40,7 @@ pkg_mklink( ext4( name = "test_image", srcs = [ + ":directory_files", ":hello_link", ":rootfs_files", ], diff --git a/tests/directory_artifact.bzl b/tests/directory_artifact.bzl new file mode 100644 index 0000000..727e485 --- /dev/null +++ b/tests/directory_artifact.bzl @@ -0,0 +1,14 @@ +def _directory_artifact_impl(ctx): + directory = ctx.actions.declare_directory(ctx.label.name) + ctx.actions.run_shell( + outputs = [directory], + command = ( + "mkdir -p {}/nested && printf '%s' ".format(directory.path) + + "'hello from directory artifact' > {}/nested/hello.txt".format(directory.path) + ), + ) + return [DefaultInfo(files = depset([directory]))] + +directory_artifact = rule( + implementation = _directory_artifact_impl, +) diff --git a/tests/ext4_test.sh b/tests/ext4_test.sh index 4d4af84..88eca11 100755 --- a/tests/ext4_test.sh +++ b/tests/ext4_test.sh @@ -20,6 +20,9 @@ image="$1" content=$(DEBUGFS_PAGER=cat debugfs -R "cat /etc/hello.txt" "$image" 2>/dev/null) test "$content" = "hello from ext4" +content=$(DEBUGFS_PAGER=cat debugfs -R "cat /opt/directory_artifact/nested/hello.txt" "$image" 2>/dev/null) +test "$content" = "hello from directory artifact" + DEBUGFS_PAGER=cat debugfs -R "stat /etc/hello.txt" "$image" 2>&1 | grep -q "Type: regular" DEBUGFS_PAGER=cat debugfs -R "stat /usr/share/hello.txt" "$image" 2>&1 | grep -q "Type: symlink" DEBUGFS_PAGER=cat debugfs -R "stat /usr/share/hello.txt" "$image" 2>&1 | grep -q 'Fast link dest: "/etc/hello.txt"'