Skip to content

Commit c0171a1

Browse files
avagingvisor-bot
authored andcommitted
runsc: allow to build runsc-race with code coverage instrumentation
PiperOrigin-RevId: 828670954
1 parent 6db7459 commit c0171a1

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

runsc/BUILD

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,28 @@ go_cov(
9393
"\"$(location //:go.mod)\" " +
9494
"\"$(location //:go.sum)\" " +
9595
"\"$(location main.go)\" " +
96-
"\"$(location //tools:go-allow-internal.patch)\" ",
96+
"\"$(location //tools:go-allow-internal.patch)\" " +
97+
"\"false\" ",
98+
)
99+
100+
go_cov(
101+
name = "runsc_race_coverage",
102+
srcs = [
103+
"main.go",
104+
"//:go.mod",
105+
"//:go.sum",
106+
"//:gopath",
107+
"//tools:build_cover.sh",
108+
"//tools:go-allow-internal.patch",
109+
],
110+
outs = ["runsc_race_cov"],
111+
cmd =
112+
"\"$(location //tools:build_cover.sh)\" " +
113+
"\"$(location //runsc:runsc_race_cov)\" " +
114+
"\"$(location //:gopath)\" " +
115+
"\"$(location //:go.mod)\" " +
116+
"\"$(location //:go.sum)\" " +
117+
"\"$(location main.go)\" " +
118+
"\"$(location //tools:go-allow-internal.patch)\" " +
119+
"\"true\" ",
97120
)

tools/build_cover.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ go_mod="$3"
2222
go_sum="$4"
2323
runsc_main_go="$5"
2424
golang_patch=$(realpath "$6")
25+
race="$7"
2526

2627
mkdir .gocache
2728
GOMODCACHE="$(pwd)/.gocache"
@@ -48,5 +49,15 @@ mkdir -p "$gvisor_gopath/src/gvisor.dev/gvisor/runsc"
4849
cp "$runsc_main_go" "$gvisor_gopath/src/gvisor.dev/gvisor/runsc/main.go"
4950
cd "$gvisor_gopath/src/gvisor.dev/gvisor/"
5051
export GOROOT="$goroot_dir"
52+
go_opts=""
53+
go_tags="kcov,opensource"
54+
if [[ "$race" = true ]]; then
55+
go_opts="-race"
56+
go_tags="$go_tags,lockdep"
57+
else
58+
# runsc has to be a self-contained binary to be able to run it in a minimal
59+
# mount namespace.
60+
export CGO_ENABLED=0
61+
fi
5162
gopkgs=$("$go_tool" list ./... | grep -v pkg/sentry/platform | grep -v pkg/ring0 | grep -v pkg/coverage | paste -sd,)
52-
"$go_tool" build --tags kcov,opensource -cover -coverpkg="$gopkg" -covermode=atomic -o "$dst" runsc/main.go
63+
"$go_tool" build --tags "$go_tags" $go_opts -cover -coverpkg="$gopkg" -covermode=atomic -o "$dst" runsc/main.go

0 commit comments

Comments
 (0)