Bazel:http_archive()中url的相对本地路径
Bazel: relative local path as url in http_archive()
我正试图在我的Bazel项目中包含一个外部库。它是一个商业的闭源代码软件库,在tar文件(Linux(中由一堆.h
和.a
文件组成。没有公共下载链接,您必须在某个地方手动下载存档。
因此,我在vendor/
中将库档案检查到Git中(这里不讨论(,并使用
http_archive(
name = "library_name",
build_file = "//third_party:library_name.BUILD",
sha256 = "12165fbcbac............",
urls = ["file:///home/myuser/git/repo/vendor/libraryname.tar.gz"],
)
我不想在urls=
中使用绝对路径,这样我的同事就可以轻松地签出并构建库。如何使用http_archive()
的相对路径?
我看过这个答案,但它似乎不是完全相同的问题,而且这个例子是不完整的。
一个非常简单的自定义存储库规则可以为您做到这一点。repositoryctx.extract负责所有繁重的工作。我刚才写了一个简单的例子:
def _test_archive_impl(repository_ctx):
repository_ctx.extract(repository_ctx.attr.src)
repository_ctx.file("BUILD.bazel", repository_ctx.read(repository_ctx.attr.build_file))
test_archive = repository_rule(
attrs = {
"src": attr.label(mandatory = True, allow_single_file = True),
"build_file": attr.label(mandatory = True, allow_single_file = True),
},
implementation = _test_archive_impl,
)
对于您的基本用例,您可能不需要对此进行任何更改(除了一个更好的名称(。添加通过stripPrefix的功能将非常简单。根据您的用例,像其他规则一样使用build_file_contents
而不是build_file
可能也很有用。
作为参考,这里是我用于测试的WORKSPACE
(上面的规则定义在test.bzl
中(:
load("//:test.bzl", "test_archive")
test_archive(
name = "test_repository",
src = "//:test.tar.gz",
build_file = "//:test.BUILD",
)
作为所有这些的替代方案,您可以从归档中签入文件,然后使用new_local_pository。在某些方面更容易合作,在其他方面更难合作。
相关文章:
- 如何使用url确定网站协议
- 下载URL中的所有文件
- 如何计算具有指定类型的表达式的相对精度和绝对精度
- 使用libcurl提交批量url的正确BING Api POST url是什么
- 如何使用cppcheck处理半相对包含路径
- 为什么字符串比较的 == 运算符相对于任一字符串长度线性时间(似乎)?
- 将所有 URL 组织在类中的一个位置
- 使用哈希图进行相对排序
- 有没有办法保证析构函数的相对顺序?
- 从 C++ 中的 URL 获取结果
- Windows 和 Linux 之间的相对路径分辨率差异?
- 在加载 MSHTML 文档之前从 MSHTML 文档中删除无效的 URL
- 连接到 URL Sqlite 数据库C++
- 为什么从具有较大阵列的 SIMD 内部函数中获得的相对加速比标量更大?
- MOVNTI 存储是否相对于由同一线程创建的其他 MOVNTI 存储重新排序?
- 如何获取 CMake 单元测试的相对路径?
- 如何在QTextEdit中添加URL或IMAGE-URL
- std::atomic 和 std::mutex 的相对性能
- c++ 网络浏览器块 url
- Bazel:http_archive()中url的相对本地路径