Unable to use stamp information in `java_binary`'s MANIFEST.MF
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 28/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- java
- 领域
- build-system
调研方向
从 java_binary 的 deploy_manifest_lines 属性开始,并使用 .bazelrc 和 BUILD.bazel 示例重现该问题。检查 workspace status 如何通过 bazel-out/stable-status.txt 和 bazel-out/volatile-status.txt 暴露,然后定义一种受支持的方式,使自定义值能够传递到 META-INF/MANIFEST.MF,并在生成的 test_deploy.jar 中验证结果。
由索引模型根据 Issue 内容生成。
描述
As far as I can tell, it currently isn't possible to use the output from --workspace_status_command in java_* rules. Specifically, it seems like a fairly common use-case (and coincidentally, what I'm currently trying to do 😉) would be to include some form of build information (revision / build date / whatever) in the MANIFEST.MF of a .jar file.
Expected behaviour: able to --stamp a java_binary with custom variables
Actual behaviour: unable to pass through any custom variables to deploy_manifest_lines
Steps to reproduce:
As a fairly trivial reproduction:
# .bazelrc
common --stamp --workspace_status_command=/usr/bin/true --embed_label="Hello"
# BUILD.bazel
java_binary(name = "test", ..., deploy_manifest_lines = [ "Custom-Label: {{BUILD_EMBED_LABEL}}" ])
Running bazel build :test_deploy.jar && unzip -p bazel-bin/test_deploy.jar META-INF/MANIFEST.MF outputs:
...
Custom-Label: {{BUILD_EMBED_LABEL}}
...
rather than the desired:
...
Custom-Label: Hello
...
Extra information
I'm not 100% sure if this has changed in newer versions of rules_java (having a quick glance at the source, it seemed not?) but at least as of v7.x the attribute for deploy_manifest_lines only accepts a list of strings, and states:
The contents of this attribute are not subject to "Make variable" substitution.
It seems like there are maybe two related problems*, one is specific to rules_java and the other is a more general Bazel thing:
java_binaryonly accepts fixed strings fordeploy_manifest_lines- Bazel does not provide convenient access to workspace status vars in macros or custom rules.
From what I've seen in some other places (e.g. rules_oci) there's no good solution to (2), so the pattern seems to be to allow providing a single file to use, and then having a command that generates that file by also reading from the bazel-out/stable-status.txt and bazel-out/volatile-status.txt files, e.g.
# BUILD.bazel
java_manifest(name = "manifest", lines = {"Custom-Label": "{{BUILD_EMBED_LABEL}}")
java_binary(name = "test", ..., deploy_manifest_lines = ":manifest")
* I imagine some people will argue this is a feature, but it doesn't feel like it from here!
If it's possible to do it without generating an intermediate file, that would be even better, but I suspect that won't be the case (at least without some major work to Bazel itself...)!
- 主要语言
- Starlark
- 星标
- 103
- 派生
- 102
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazelbuild/rules_java 的其他 Issue
-
P4
难度 4/5 3-5 天 新手友好度 55/100
bazelbuild/rules_java#360 · 4 条评论 · 2 个 reaction ·
-
P4
难度 5/5 一周以上 新手友好度 35/100
bazelbuild/rules_java#354 · 8 条评论 ·
-
P3 question
难度 3/5 1-2 天 新手友好度 45/100
bazelbuild/rules_java#339 · 1 条评论 ·
-
P3
难度 4/5 3-5 天 新手友好度 35/100
bazelbuild/rules_java#325 · 8 条评论 ·
-
P4
难度 4/5 3-5 天 新手友好度 35/100
bazelbuild/rules_java#316 · 2 个 reaction ·
查看 bazelbuild/rules_java 的全部 Issue
相似的 Issue
-
type/automation type/tech-debt
难度 2/5 1-3 小时 新手友好度 78/100
-
priority: p3
难度 2/5 1-3 小时 新手友好度 72/100
googleapis/librarian#7636 ·
-
package-update
难度 2/5 1-3 小时 新手友好度 72/100
oSoWoSo/vOid_Community_repOsitory#147 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
-
agentic-workflows cascade-suspected
难度 1/5 1 小时以内 新手友好度 88/100