Unable to use stamp information in `java_binary`'s MANIFEST.MF
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 28/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- java
- 領域
- build-system
調査の方向性
java_binary の deploy_manifest_lines 属性から始め、.bazelrc と BUILD.bazel の例を使って問題を再現します。bazel-out/stable-status.txt と bazel-out/volatile-status.txt を通じて workspace status がどのように公開されるかを調べ、その後、カスタム値を 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bazelbuild/rules_java のほかの issue
-
P4
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
bazelbuild/rules_java#360 · コメント 4 件 · リアクション 2 件 ·
-
P4
難易度 5/5 1週間以上 初心者へのやさしさ 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 件 ·
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 件 ·
-
Builders
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100