Skip to content

Commit

Permalink
Propagate mode aspect on "_coverdata" edges (#1632)
Browse files Browse the repository at this point in the history
* Propagate mode aspect on "_coverdata" edges

This ensures the coverdata library is built in the same mode as the
binary that depends on it.

Fixes #1630

* set pure = "on" on test to make CI happy
  • Loading branch information
jayconrod authored and Jay Conrod committed Aug 25, 2018
1 parent 0688191 commit 753760c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions go/private/rules/aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ go_archive_aspect = aspect(
"compiler",
"compilers",
"_stdlib",
"_coverdata",
],
attrs = {
"pure": attr.string(values = [
Expand Down
3 changes: 3 additions & 0 deletions go/private/rules/rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ load(
)

_ASPECT_ATTRS = ["pure", "static", "msan", "race"]

# Keep in sync with attr_aspects in go_archive_aspect. Any implicit dependency
# that is built in the target configuration should go there.
_BOOTSTRAP_ATTRS = ["_builders", "_coverdata", "_stdlib"]

def go_rule(implementation, attrs = {}, toolchains = [], bootstrap = False, bootstrap_attrs = _BOOTSTRAP_ATTRS, **kwargs):
Expand Down
26 changes: 23 additions & 3 deletions tests/core/coverage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//tests:bazel_tests.bzl", "bazel_test")

bazel_test(
name = "coverage_test_test",
args = ["--instrumentation_filter=-coverage:b"],
check = """
if ! grep -q '^coverage: 50.0% of statements' "bazel-testlogs/$RULES_GO_OUTPUT/coverage_test/test.log"; then
echo "error: no coverage output found in test log file" >&2
Expand Down Expand Up @@ -48,7 +49,6 @@ for i in "${excluded_files[@]}"; do
done
""",
command = "coverage",
args = ["--instrumentation_filter=-coverage:b"],
targets = [":coverage_test"],
)

Expand All @@ -62,19 +62,39 @@ go_test(
go_library(
name = "a",
srcs = ["a.go"],
deps = [":b"],
importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/a",
deps = [":b"],
)

go_library(
name = "b",
srcs = ["b.go"],
deps = [":c"],
importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/b",
deps = [":c"],
)

go_library(
name = "c",
srcs = ["c.go"],
importpath = "github.com/bazelbuild/rules_go/tests/core/coverage/c",
)

bazel_test(
name = "cross_cover_test_test",
args = [
"--collect_code_coverage",
"--instrumentation_filter=-coverage:b",
],
command = "build",
targets = [":cross_cover_test"],
)

go_test(
name = "cross_cover_test",
srcs = ["coverage_test.go"],
embed = [":a"],
goarch = "386",
goos = "linux",
pure = "on",
tags = ["manual"],
)
6 changes: 6 additions & 0 deletions tests/core/coverage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ Checks that ``bazel coverage`` on a ``go_test`` produces reasonable output.
Libraries referenced by the test that pass ``--instrumentation_filter`` should
have coverage data. Library excluded with ``--instrumentatiuon_filter`` should
not have coverage data.

coverdata_aspect_test_test
--------------------------

Checks that the ``coverdata`` library is compiled in the same mode as the
test that depends on it.

0 comments on commit 753760c

Please sign in to comment.