Skip to content

Allow buildozer target to be aliased#23

Merged
fmeum merged 1 commit intomainfrom
buildozer-alias
Jan 25, 2025
Merged

Allow buildozer target to be aliased#23
fmeum merged 1 commit intomainfrom
buildozer-alias

Conversation

@fmeum
Copy link
Copy Markdown
Owner

@fmeum fmeum commented Jan 16, 2025

Closes #17

@fmeum fmeum force-pushed the buildozer-alias branch 3 times, most recently from 1c7862c to 7b5a9e2 Compare January 16, 2025 08:06
Co-authored-by: Spencer Putt <sputt@alumni.iu.edu>
@fmeum fmeum marked this pull request as ready for review January 16, 2025 08:34
@fmeum
Copy link
Copy Markdown
Owner Author

fmeum commented Jan 16, 2025

@sputt

@fmeum fmeum merged commit be01120 into main Jan 25, 2025
@fmeum fmeum deleted the buildozer-alias branch January 25, 2025 06:55
Comment thread BUILD.bazel
@@ -1,15 +1,17 @@
# A buildozer binary that will run in the root repository's workspace directory
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Based on this comment, I think we should be able to have a target like this:

py_binary(
    name = "foo",
    srcs = ["foo.py"],
    args = [
        "--buildozer",
        "$(rootpath @buildozer)",
    ],
    data = [
        "@buildozer",
    ],
...
)

However, we had to make sure buildozer_binary repo visible to the main repo, otherwise rlocation would fail to resolve. Is this intended or could be improved?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We shell out $(rootpath @buildozer) from the foo.py, if that matters.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

It's meant to be usable without any use_repos, but you have to use a runfiles library to find it (you can get the path via $(rlocationpath @buildozer)) and set the env vars for subprocesses, see https://github.com/bazel-contrib/rules_python/tree/main/python/runfiles

Let me know if that doesn't work.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you mean we should use Rlocation in Python code instead of rootpath in BUILD.bazel? Or maybe it is env.update(r.EnvVars()) that really matters?

I will give it a try.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OK I see rlocationpath in BUILD.bazel and Rlocation in Python resolve to different paths:

.../execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/tools/foo/foo.runfiles/_main/buildozer+/buildozer
.../execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/external/buildozer+/buildozer

The first path doesn't even exist. rootpath could resolve to the correct path .../execroot/_main/bazel-out/darwin_arm64-fastbuild/bin/tools/foo/foo.runfiles/_main/../buildozer+/buildozer, but subprocessing that fails for finding buildozer.exec.

Using Rlocation together with env update does work.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Rlocation + setting env vars is what is guaranteed to work on all platforms, even if further subprocesses use runfiles. That's what the runfiles library can guarantee (caveat: if processes change the CWD, they need to ensure that runfiles env vars are absolute).

Everything else is "may work, may not work, may break in the future" territory.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

That is very good to know. We will refactor this part of our code to go with Rlocation+env. Thank you so much for the help!

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.

2 participants