[英]How to add input files to bazel run in TeamCity
I'm super new to bazel so lots of understanding could be wrong.我对bazel非常陌生,所以很多理解可能是错误的。
I have a local directory with the following structure:我有一个具有以下结构的本地目录:
/my/certain/path
|- my_test.go
|- my_utils.go
|- BUILD.bazel
|- mydir
|- input1
|- input2
I'm using bazel run
in TeamCity to run a go test with my_test.go
(some sensitive info is replaced with xxx
or ...
):我在 TeamCity 中使用
bazel run
运行 go 测试,其中my_test.go
(一些敏感信息被替换为xxx
或...
):
bazel run \
//my/certain/path:my_test \
--config=crosslinux --config=test \
--test_timeout=1800
And in the /my/certain/path/BUILD.bazel
I have在
/my/certain/path/BUILD.bazel
我有
go_library(
name = "path",
srcs = ["my_utils.go"],
importpath = "/my/certain/path",
visibility = ["//visibility:public"],
deps = [
"@com_github_docker_docker//api/types",
...
"@org_golang_x_net//context",
],
)
go_test(
name = "my_test",
size = "enormous",
srcs = ["my_test.go"],
embed = [":xxx"],
deps = [
"//pkg/util/contextutil",
"//pkg/util/log",
"@com_github_docker_docker//client",
"@org_golang_x_net//context",
],
)
The my_test.go
actually will use files in mydir
as input when running. my_test.go
实际上会在运行时使用mydir
中的文件作为输入。
But when running on teamcity, I notice mydir
was not mounted in the temporary directory where this bazel test happens, which made my_test.go
fail.但是在 teamcity 上运行时,我注意到
mydir
没有安装在发生此 bazel 测试的临时目录中,这导致my_test.go
失败。
I tried to solve it by adding these lines to print out the current directory and all files in my_test.go
:我试图通过添加这些行来打印出当前目录和
my_test.go
中的所有文件来解决它:
fmt.Println("==== listing all files in go====")
err := filepath.Walk(".",
func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
fmt.Println(path, info.Size())
return nil
})
if err != nil {
t.Fatal(err)
}
fmt.Println("==== end listing all files in go====")
ctx := context.Background()
pwd, err := os.Getwd()
if err != nil {
t.Fatal(fmt.Errorf("cannot get pwd: %v", err))
}
fmt.Println("-----pwd:", pwd)
And it shows that the它表明,
==== listing all files in go====
17:26:17 . 4096
17:26:17 my_test_ 4096
17:26:17 my_test_/my_test 152
17:26:17 ==== end listing all files in go====
pwd: /home/agent/.cache/bazel/_bazel_agent/xxxxx/execroot/myname/bazel-out/k8-fastbuild/bin/my/path/my_test_/my_test.runfiles/my/certain/path
So my goal is to mount mydir
to this working dir ( /home/agent/.cache/bazel/_bazel_agent/xxxxx/execroot/myname/bazel-out/k8-fastbuild/bin/my/path/my_test_/my_test.runfiles/my/certain/path
).所以我的目标是将
mydir
挂载到这个工作目录( /home/agent/.cache/bazel/_bazel_agent/xxxxx/execroot/myname/bazel-out/k8-fastbuild/bin/my/path/my_test_/ /home/agent/.cache/bazel/_bazel_agent/xxxxx/execroot/myname/bazel-out/k8-fastbuild/bin/my/path/my_test_/my_test.runfiles/my/certain/path
)。
I'm not sure if this is a TeamCity specific question or there's a way in bazel to specify it.我不确定这是 TeamCity 的特定问题,还是 bazel 有办法指定它。
I solved it by adding the data
entry in the BUILD.bazel
:我通过在
BUILD.bazel
中添加data
条目来解决它:
go_test(
name = "my_test",
size = "enormous",
srcs = ["my_test.go"],
embed = [":xxx"],
data = glob([
"mydir/**",
]),
deps = [
"//pkg/util/contextutil",
"//pkg/util/log",
"@com_github_docker_docker//client",
"@org_golang_x_net//context",
],
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.