Skip to content

Commit

Permalink
bazel/rules_r: bazel 0.18 compatibility for coverage
Browse files Browse the repository at this point in the history
Summary:
From bazel 0.18.0, an lcov_merger tool is needed for every test rule
that collects coverage.

See bazelbuild/bazel#6293 for more details.

Reviewers: ysaito

Reviewed By: ysaito

Differential Revision: https://phabricator.grailbio.com/D20750

fbshipit-source-id: f480a5e
  • Loading branch information
Siddhartha Bagaria authored and grailbot committed Oct 30, 2018
1 parent 5ac1c22 commit ef085b6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions R/internal/tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ r_unit_test = rule(
allow_single_file = True,
default = "@com_grail_rules_r//R/scripts:collect_coverage.R",
),
"_lcov_merger": attr.label(
allow_single_file = True,
default = "@com_grail_rules_r//R/scripts:lcov_merger.sh",
),
},
doc = ("Rule to keep all deps in the sandbox, and run the test " +
"scripts of the specified package. The package itself must " +
Expand Down
1 change: 1 addition & 0 deletions R/scripts/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports_files([
"check.sh.tpl",
"collect_coverage.R",
"instrument.R",
"lcov_merger.sh",
"library.sh.tpl",
"test.sh.tpl",
])
Expand Down
8 changes: 2 additions & 6 deletions R/scripts/collect_coverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
# Collect code coverage

# NOTE:
# bazel currently always tries to run lcov with gcov to generate lcov trace
# files, which is not applicable here. The only reason collect_coverage.sh from
# bazel succeeds is because it can not find gcov defined in the toolchain for
# the rule and skips the step. This is brittle and will break when bazel
# changes collect_coverage.sh or if we start specifying cc_deps as a dependency
# attribute in instrumented_files. More proper support for coverage in skylark
# This might break in the future if we start specifying cc_deps as a dependency
# attribute in instrumented_files. More proper support for coverage in starlark
# rules is in the roadmap --
# https://bazel.build/roadmaps/coverage.html#improve-adding-coverage-support-for-skylark-rules-p2

Expand Down
21 changes: 21 additions & 0 deletions R/scripts/lcov_merger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Since bazel 0.18.0, an lcov_merger tool is mandatory for tests that
# collect coverage. This tool is run after the tests to generate the
# COVERAGE_OUTPUT_FILE. Since we generate this file from within our
# test runner directly, the lcov_merger tool is a no-op for us.

exit 0

0 comments on commit ef085b6

Please sign in to comment.