我想通过 HTTP 在 Bazel 中获取一些数据。 有一个http_file 方法看起来像我想要的。 我从中获取的远程服务器使用身份验证,因此我将其编写为 当我尝试构建时,我得到 警告:从https://example.com/data.0.1.2下载失败:class com.google ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在使用Bazel构建我的项目。 我想使用单头测试框架Catch v2 。 我决定使用http_file规则使Bazel下载catch标头。 我的WORKSPACE
文件如下所示:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
name = "catch",
downloaded_file_path = "catch.hpp",
sha256 = "cc6cc272cf84d8e10fb28f66f52584dedbb80d1234aae69e6a1027af4f31ae6f",
urls = ["https://github.com/catchorg/Catch2/releases/download/v2.4.2/catch.hpp"],
)
根据文档,测试取决于生成的软件包,如下所示:
cc_test(
name = "my_test",
srcs = ["@catch//file", "my_test.cc"]
)
测试文件my_test.cc
不能再简单了:
#include "catch.hpp"
但是,出现以下错误:
$ bazel test --config=opt -s //...
WARNING: [...]/BUILD:25:10: in srcs attribute of cc_test rule //test:my_test: please do not import '@catch//file:catch.hpp' directly. You should either move the file to this package or depend on an appropriate rule there
SUBCOMMAND: # //test:my_test [action 'Compiling test/my_test.cc']
(cd [...] && \
exec env - [...] \
/usr/bin/gcc
-U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF [...].d '-frandom-seed=[...].o' -fPIC
-iquote .
-iquote bazel-out/k8-fastbuild/genfiles
-iquote bazel-out/k8-fastbuild/bin
-iquote external/bazel_tools
-iquote bazel-out/k8-fastbuild/genfiles/external/bazel_tools
-iquote bazel-out/k8-fastbuild/bin/external/bazel_tools
-fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c test/my_test.cc
-o [...].o)
ERROR: [...]/BUILD:23:1: C++ compilation of rule '//test:my_test' failed (Exit 1)
test/my_test.cc:1:28: fatal error: catch.hpp: No such file or directory
compilation terminated.
[...]
FAILED: Build did NOT complete successfully
创建cc_library
包装器或包含catch/catch.hpp
,catch / file / catch.hpp会产生相同的错误。
默认情况下, http_file
下载的文件可以包含为:
#include "external/<name>/file/<file_name>"
在这种情况下:
#include "external/catch/file/catch.hpp"
但是,此包含路径很难看,应该用cc_library
包装。 此外,为每个测试编译完整的catch头文件将使构建变慢。 根据catch文档 ,catch标头的实现部分应单独编译。 像这样:
测试/ BUILD:
cc_library(
name = "catch",
hdrs = ["@catch//file"],
srcs = ["catch.cpp"],
visibility = ["//visibility:public"],
strip_include_prefix = "/external/catch/file",
include_prefix = "catch",
linkstatic = True, # otherwise main() will could end up in a .so
)
cc_test(
name = "my_test",
deps = ["//test:catch"],
srcs = ["my_test.cc"],
)
测试/ catch.cpp:
#define CATCH_CONFIG_MAIN
#include "catch/catch.hpp"
测试/ my_test.cc:
#include "catch/catch.hpp"
TEST_CASE("my_test", "[main]") { /* ... */ }
如果只更改catch.cpp
将不会重新编译my_test.cc
,从而节省了宝贵的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.