- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试根据运行 bazel 的操作系统指定构建条件,因此在我的 .bzl 脚本中我有一个规则,该规则从外部源创建所有模拟链接并编写一个构建文件(使用 ctx.file) ,我在其中声明了所有导入和库,并且在其中我想添加选择功能。但是,当我构建时收到此错误消息:
ERROR: no such package '@maya_repo//': Traceback (most recent call last):
File "/var/tmp/doNotRemove/mdilena_plugins/MayaMathNodes/src/maya.bzl", line 149
ctx.file("BUILD", _BUILD_STRUC.format(maya_...))
File "/var/tmp/doNotRemove/mdilena_plugins/MayaMathNodes/src/maya.bzl", line 149, in ctx.file
_BUILD_STRUC.format(maya_dir = maya_dir)
Invalid character '[' inside replacement field
下面是我的代码示例以及我要实现的目标:
_BUILD_STRUC = \
"""
# Windows imports
cc_import(
name = "Foundation-win",
interface_library = "{maya_dir}/lib/Foundation.lib",
shared_library = "{maya_dir}/bin/Foundation.dll",
)
cc_import(
name = "OpenMaya-win",
interface_library = "{maya_dir}/lib/OpenMaya.lib",
shared_library = "{maya_dir}/bin/OpenMaya.dll",
)
# Linux imports
cc_import(
name = "Foundation-lnx",
shared_library = "{maya_dir}/bin/Foundation.so",
)
cc_import(
name = "OpenMaya-lnx",
shared_library = "{maya_dir}/bin/OpenMaya.so",
)
cc_library(
name = "Foundation",
deps = select({
"@bazel_tools//src/conditions:windows": [":Foundation-win"],
"//conditions:default": [":Foundation-lnx"],
}),
includes = ["{maya_dir}/include"],
visibility = ["//visibility:public"],
)
cc_library(
name = "OpenMaya",
deps = select({
"@bazel_tools//src/conditions:windows": [":OpenMaya-win"],
"//conditions:default": [":OpenMaya-lnx"],
}),
includes = ["{maya_dir}/include"],
visibility = ["//visibility:public"],
)
"""
def _impl(ctx):
maya_src = ctx.os.environ["MAYA_LOCATION"]
maya_ver = ctx.os.environ["MAYA_VERSION"]
maya_dir = "maya{}".format(maya_ver)
ctx.symlink(maya_src, maya_dir)
ctx.file("BUILD", _BUILD_STRUC.format(maya_dir=maya_dir))
link_maya = repository_rule(
implementation = _impl,
local = True,
environ = ["MAYA_LOCATION"],
)
有人知道为什么会这样吗?我看了select和 configurable attributes文档,似乎这就是使用它的方式;我想知道是我做错了什么还是某处有错误。
感谢您的帮助!
EDIT:
looks like Bazel really doesn't like using select inside a ctx.file, I'll leave the question open in case someone will be able to shed some light on it. In the meantime I solved it by making all the
cc_imports
and includes public from the linked repo, while leaving all thecc_libraries
withselect
to my plugin's BUILD file; from there I'm able to use the condition and everything builds.
最佳答案
看起来错误来自这一行,特别是对 string.format
的调用.
ctx.file("BUILD", _BUILD_STRUC.format(maya_dir=maya_dir))
string.format
在模板字符串中搜索大括号,例如 {}
或 {key}
,并用位置参数或关键字参数替换它们。
您看到此错误是因为 string.format
将模板中 select
的 dict 参数误认为是要替换的内容,因为它以花括号开头。通过加倍转义模板字符串中的大括号应该可以解决问题:
_BUILD_STRUC = \
"""
...
cc_library(
name = "Foundation",
deps = select({{
"@bazel_tools//src/conditions:windows": [":Foundation-win"],
"//conditions:default": [":Foundation-lnx"],
}}),
includes = ["{maya_dir}/include"],
visibility = ["//visibility:public"],
)
...
仅供引用,您可能会找到 repository_ctx.template
更容易使用。它的语义略有不同:它按字面替换字符串,而不寻找像 {
这样的特殊字符,因此不需要转义。
关于Bazel 选择在 ctx.file 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52257038/
当我调用 Bazel 命令并出现分析错误时,它只显示其中之一。例如: ERROR: /Users/oliver/src/github.com/monzo/wearedev/service.transa
我们正在生成许多 Go 源文件作为我们构建的一部分。以前我们使用了 genrule ( example here ) 导致生成的文件存储在 bazel-genfiles/ . 我们最近切换到使用自定义
有没有办法在 Bazel 中指定可选依赖项? 我想制定一个规则来在某种程度上反射(reflect) Kitware 的 ExternalData , 但我想看看我是否可以启用开发人员在树中编辑文件的工
我想知道特定于平台的默认 Bazel 构建标志是否可能。 例如,我们想要使用 --workspace_status_command,但这必须是 Linux 上的 shell 脚本,并且必须指向 Win
具体来说,我想从 Mac 主机对 Windows 工作人员运行测试。 评论 running bazel remote executor test on separate machines表明这是 Ba
我想知道特定于平台的默认 Bazel 构建标志是否可能。 例如,我们想要使用 --workspace_status_command,但这必须是 Linux 上的 shell 脚本,并且必须指向 Win
有没有办法指示 bazel 列出它找到的所有目标而不构建或测试它们? 最佳答案 bazel query 可用于发现 bazel 工作区内的目标(无需构建/测试它们) 例如; 查找给定包中的所有标签:
(来自https://groups.google.com/d/msg/bazel-discuss/XrtKLhH1bgI/B9xZn_aVAAAJ) 在我们使用 Bazel 构建的项目中,我使用了远程
在 bazel 构建期间,有一堆文本飞过,暂时显示然后从屏幕上删除。这发生在整个构建过程中。我尝试了几种重定向技术,将 stderr 重定向到标准输出但无济于事。我还尝试了 bazel 的详细标志。
我是 Bazel 的新手,并在 CentOS 7 上安装了 Bazel。我使用版本为“0.14.0- (@non-git)”的“yum install bazel”安装了它 启动 bazel 时,它总
我有几段 C++ 代码(模板、宏等),它们在使用某些方式时无法编译。手动编写一段代码来完成不应该编译的事情并验证它是否编译是很容易的,但这不是自动化的。看起来 Bazel 应该能够编译一段代码并自动验
鉴于使用 bazel 构建的相当大的存储库和多种语言的大量第三方依赖项(包括重型 docker 容器),我遇到以下问题: 运行 Bazel 查询会触发下载许多这些依赖项,从而导致查询性能下降。因此,问
假设我有一个 Bazel 宏,它使用生成器规则在给定输入文件的情况下生成输出文件: def my_generator( name, input_file,
在我的代码库中,在多个目标(cc_binary、cc_library 等)中包含相同的源文件通常是错误的。我想检测这个。 我可以 bazel query labels(srcs, //target:n
您好,我想读取 .bzl 文件中本地文件的内容。 print(onefile.basename) #content = ctx.read #content=ctx.file.o
我确信这已记录在某处,但无法在任何地方找到答案。 如果我有: ```bazel_rule( name = "foo", srcs = ["foo.cpp"], attr_bar
我正在开始使用 Bazel,如果有一种简单的方法可以集成 buildifier,我就在运行每次运行 bazel build 时? 最佳答案 您可以将此实现为测试规则,其中 ctx.file_actio
bazel test命令对标记为 size = small 的测试使用默认超时 75 秒在我的设置中(版本 0.12.0)(而 documentation 提到这是 60 秒) 有没有办法在 baze
$ python gencpp.py 此命令生成一个 cpp 文件 foo.cpp在工作目录中。 我想在 bazel 中运行此命令建之前可以包含foo.cpp在 cc_binary的 srcs属性。
一遍又一遍地阅读 Bazel 文档,以至于没有什么新鲜的地方,但我似乎无法掌握如何为 native 以外的变体设置配置和变体,例如--cpu 和--compilation_mode。 为了解释我对配置
我是一名优秀的程序员,十分优秀!