Skip to content

//cuttlefish/package:package_files overhaul - #2984

Merged
Databean merged 2 commits into
google:mainfrom
Databean:package_rule
Aug 12, 2026
Merged

//cuttlefish/package:package_files overhaul#2984
Databean merged 2 commits into
google:mainfrom
Databean:package_rule

Conversation

@Databean

@Databean Databean commented Aug 6, 2026

Copy link
Copy Markdown
Member
  • base_dir is recreated on every rule evaluation, fixing an outstanding issue where files would persist in the output directory beyond being deleted in the build target
  • Most of the implementation is moved to a C++ executable
  • package_executable is separated from package_files. this allows referencing 0 to many executables from a package, rather than always exactly one.
  • When possible, hard links are created instead of copies.

Bug: b/429012834

@Databean
Databean requested a review from jmacnak August 6, 2026 23:47
@Databean
Databean force-pushed the package_rule branch 3 times, most recently from 7e7a090 to 0d9ddff Compare August 8, 2026 01:26
@Databean Databean added the kokoro:run Run e2e tests. label Aug 8, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Aug 8, 2026

@jmacnak jmacnak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Most of the implementation is moved to a C++ executable

Sorry if I am missing something. Is there a motivation for this? Couldn't _package_files_impl be upated to perform the rm -rf ctx.attr.base_dir as the first step?

@Databean

Databean commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

Should have mentioned, one of the issues I ran into is https://www.github.com/bazelbuild/bazel/issues/21782 : if the entire directory is considered the output with declare_directory, then bazel will reject any declare_file members inside of it. Semantically, the directory is the output, rather than a list of known files inside of it, as we care about stale files present inside of it.

I think #2998 is the strategy you're proposing, for running rm -r first. Without being able to declare_directory the entire directory, it uses a placeholder file next to it as a substitute. However, I think bazel sandboxing prevents it from observing the directory, because it's not a declared output:

ERROR: /mnt/build/standalone/android-cuttlefish/base/cvd/cuttlefish/package/BUILD.bazel:8:14: ClearOutputDirectory cuttlefish/package/cuttlefish-common.placeholder failed: (Exit 1): bash failed: error executing ClearOutputDirectory command (from target //cuttlefish/package:common) /bin/bash -c 'rm -r bazel-out/k8-fastbuild/bin/cuttlefish/package/cuttlefish-common && touch bazel-out/k8-fastbuild/bin/cuttlefish/package/cuttlefish-common.placeholder'

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
rm: cannot remove 'bazel-out/k8-fastbuild/bin/cuttlefish/package/cuttlefish-common': No such file or directory
Target //cuttlefish/package:common failed to build

This can be worked around by disabling the sandbox using --spawn_strategy=local, which is not ideal. The implementation declares the placeholder file as an input to every generated file to try to force it to run first.

Using declare_directory pushes us into using a single run or run_shell which has to produce the entire directory.

@jmacnak

jmacnak commented Aug 10, 2026

Copy link
Copy Markdown
Member

Ahh makes sense. Could you add a comment either around _package_executable_impl or in packager.cc‎ explaining the bazel limitation?

@Databean
Databean force-pushed the package_rule branch 4 times, most recently from cd70aa3 to f63cdf5 Compare August 12, 2026 00:47
@Databean

Copy link
Copy Markdown
Member Author

Added a comment, and pushed some more fixes to the debian rules script.

Also added a workaround for Bazel chmod-ing all output files ( https://www.github.com/bazelbuild/bazel/issues/5588 ) which can propagate back to any source files hard linked in.

@Databean

Databean commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reviews!

Also added a fix to package_executable:

-    ctx.actions.symlink(
-        output = executable_link,
-        target_path = base_dir.basename + "/" + ctx.attr.executable,
+    ctx.actions.run_shell(
+        mnemonic = "OutputSymlink",
+        outputs = [executable_link],
+        inputs = ctx.attr.package[DefaultInfo].files,
+        command = "ln -s " + base_dir.basename + "/" + ctx.attr.executable + " " + executable_link.path,
     )

With ctx.actions.symlink, running bazel run //cuttlefish/package:cvd did not check if //cuttlefish/package:common needed to be rebuilt for source file changes. Using ctx.actions.run_shell has an inputs attribute which reports the dependency edge correctly.

@Databean
Databean force-pushed the package_rule branch 2 times, most recently from bd67f60 to 0370371 Compare August 12, 2026 02:06
@Databean Databean added the kokoro:run Run e2e tests. label Aug 12, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Aug 12, 2026
@Databean
Databean enabled auto-merge August 12, 2026 02:12
- base_dir is recreated on every rule evaluation, fixing an outstanding
  issue where files would persist in the output directory beyond being
  deleted in the build target
- Most of the implementation is moved to a C++ executable
- package_executable is separated from package_files. this allows
  referencing 0 to many executables from a package, rather than always
  exactly one.
- When possible, hard links are created instead of copies.

Bug: b/429012834
@Databean Databean added the kokoro:run Run e2e tests. label Aug 12, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label Aug 12, 2026
@Databean
Databean added this pull request to the merge queue Aug 12, 2026
Merged via the queue into google:main with commit f965d50 Aug 12, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants