简体   繁体   English

Bazel 的`repository_rule` 如何调整`label_flag`(或者更普遍的`config_setting`)?

[英]How can a Bazel `repository_rule` adjust a `label_flag` (or a `config_setting` more generally)?

I can create a label_flag in Bazel to allow command line flags to in turn be matched with a config_setting in a Bazel BUILD file.我可以在 Bazel 中创建一个label_flag以允许命令行标志依次与 Bazel BUILD文件中的config_setting匹配。

However, I'd like to not hard-code the default value of the label_flag , and instead compute a good default based on the system when evaluating a repository_rule (or some other part of the WORKSPACE file).但是,我不想对label_flag的默认值进行硬编码,而是在评估repository_rule (或WORKSPACE文件的其他部分)时根据系统计算一个好的默认值。

The best (but awful) way I've come up with to do this is to have the default value loaded from a .bzl file that is generated using the template function on the repository_ctx .我想出的最好(但很糟糕)的方法是从使用repository_ctx上的template函数生成的.bzl文件加载默认值。

I feel like generating a new file by doing textual substitutions probably isn't the right way to do this, but I can't find anything else.我觉得通过进行文本替换来生成新文件可能不是正确的方法,但我找不到其他任何东西。 Ideas?想法? help?帮助?

Generating a bzl file using the repository rule that inspects the host system is the only way to achieve what you need right now.使用检查主机系统的存储库规则生成 bzl 文件是实现您现在需要的唯一方法。 So you're holding it "right" :)所以你持有它“正确”:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM