Skip to content

Commit

Permalink
Rename LcovMerger to CoverageOutputGenerator.
Browse files Browse the repository at this point in the history
This renaming is essential because LcovMerger does so much more than merging lcov files (e.g.parses gcov files, filters source files, etc) and soon it will do some more (e.g. filter out sources based on the source file manifest). Keeping this name only introduces confusion when someone unfamiliar with the code tries to understand it.

RELNOTES: LcovMerger was renamed to CoverageOutputGenerator.

Please use
```
--coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main
```

instead of the previous

```
--coverage_report_generator=@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main
```

Closes bazelbuild#6137.

PiperOrigin-RevId: 212639898
  • Loading branch information
iirina authored and Copybara-Service committed Sep 12, 2018
1 parent 753ff08 commit 8f4786b
Show file tree
Hide file tree
Showing 32 changed files with 485 additions and 560 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment env)
attr("$lcov_merger", LABEL)
.value(
Label.parseAbsoluteUnchecked(
"@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main")))
"@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main")))
.add(
attr("$jacocorunner", LABEL)
.value(Label.parseAbsoluteUnchecked("@bazel_tools//tools/jdk:JacocoCoverage")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi
attr("$lcov_merger", LABEL)
.value(
Label.parseAbsoluteUnchecked(
"@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main")));
"@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main")));
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void setupMockClient(MockToolsConfig config) throws IOException {
"filegroup(name = 'coverage_report_generator', srcs = ['coverage_report_generator.sh'])");

config.create(
"/bazel_tools_workspace/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/BUILD",
"/bazel_tools_workspace/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/BUILD",
"filegroup(name='srcs', srcs = glob(['**']))",
"filegroup(name='Main', srcs = ['Main.java'])");

Expand Down
2 changes: 1 addition & 1 deletion src/test/shell/bazel/bazel_coverage_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public class TestCollatz {
}
EOF

bazel coverage --test_output=all //:test --coverage_report_generator=@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main --combined_report=lcov &>$TEST_log \
bazel coverage --test_output=all //:test --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main --combined_report=lcov &>$TEST_log \
|| echo "Coverage for //:test failed"

cat <<EOF > result.dat
Expand Down
6 changes: 3 additions & 3 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ filegroup(
"//tools/osx:srcs",
"//tools/osx/crosstool:srcs",
"//tools/test:srcs",
"//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:srcs",
"//tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger:srcs",
"//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:srcs",
"//tools/test/CoverageOutputGenerator/javatests/com/google/devtools/coverageoutputgenerator:srcs",
"//tools/python:srcs",
"//tools/runfiles:srcs",
"//tools/sh:srcs",
Expand Down Expand Up @@ -59,7 +59,7 @@ filegroup(
"//tools/python:embedded_tools",
"//tools/runfiles:embedded_tools",
"//tools/test:embedded_tools",
"//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:embedded_tools",
"//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:embedded_tools",
"//tools/osx/crosstool:srcs",
"//tools/osx:srcs",
"//tools/sh:embedded_tools",
Expand Down
4 changes: 2 additions & 2 deletions tools/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ filegroup(

filegroup(
name = "coverage_report_generator",
srcs = ["@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main"],
srcs = ["@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main"],
)

cc_binary(
Expand Down Expand Up @@ -88,7 +88,7 @@ test_suite(
name = "all_windows_tests",
tests = [
":windows_tests",
"//tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger:all_windows_tests",
"//tools/test/CoverageOutputGenerator/javatests/com/google/devtools/coverageoutputgenerator:all_windows_tests",
],
visibility = ["//tools:__pkg__"],
)
2 changes: 1 addition & 1 deletion tools/test/BUILD.tools
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ filegroup(

filegroup(
name = "coverage_report_generator",
srcs = ["@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main"],
srcs = ["@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main"],
)

filegroup(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package(
default_visibility = [
"//tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger:__pkg__",
"//tools/test/CoverageOutputGenerator/javatests/com/google/devtools/coverageoutputgenerator:__pkg__",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ java_import(
java_binary(
name = "Main",
create_executable = 1,
main_class = "com.google.devtools.lcovmerger.Main",
main_class = "com.google.devtools.coverageoutputgenerator.Main",
runtime_deps = [":all_lcov_merger_lib"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.lcovmerger;
package com.google.devtools.coverageoutputgenerator;

import com.google.auto.value.AutoValue;

/**
* Stores branch coverage information.
*/
/** Stores branch coverage information. */
@AutoValue
abstract class BranchCoverage {

Expand All @@ -35,8 +33,8 @@ static BranchCoverage createWithBlockAndBranch(
/**
* Merges two given instances of {@link BranchCoverage}.
*
* Calling {@code lineNumber()}, {@code blockNumber()} and {@code branchNumber()} must return the
* same values for {@code first} and {@code second}.
* <p>Calling {@code lineNumber()}, {@code blockNumber()} and {@code branchNumber()} must return
* the same values for {@code first} and {@code second}.
*/
static BranchCoverage merge(BranchCoverage first, BranchCoverage second) {
assert first.lineNumber() == second.lineNumber();
Expand All @@ -52,8 +50,10 @@ static BranchCoverage merge(BranchCoverage first, BranchCoverage second) {

abstract int lineNumber();
// The two numbers below should be -1 for non-gcc emitted coverage (e.g. Java).
abstract String blockNumber(); // internal gcc internal ID for the branch
abstract String blockNumber(); // internal gcc internal ID for the branch

abstract String branchNumber(); // internal gcc internal ID for the branch

abstract int nrOfExecutions();

boolean wasExecuted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.lcovmerger;
package com.google.devtools.coverageoutputgenerator;

/**
* Stores markers used by the lcov tracefile and gcov intermediate format file. See <a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.lcovmerger;
package com.google.devtools.coverageoutputgenerator;

import java.util.Collection;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.lcovmerger;
package com.google.devtools.coverageoutputgenerator;

import static com.google.devtools.lcovmerger.Constants.DELIMITER;
import static com.google.devtools.lcovmerger.Constants.GCOV_BRANCH_MARKER;
import static com.google.devtools.lcovmerger.Constants.GCOV_BRANCH_NOTEXEC;
import static com.google.devtools.lcovmerger.Constants.GCOV_BRANCH_NOTTAKEN;
import static com.google.devtools.lcovmerger.Constants.GCOV_BRANCH_TAKEN;
import static com.google.devtools.lcovmerger.Constants.GCOV_CWD_MARKER;
import static com.google.devtools.lcovmerger.Constants.GCOV_FILE_MARKER;
import static com.google.devtools.lcovmerger.Constants.GCOV_FUNCTION_MARKER;
import static com.google.devtools.lcovmerger.Constants.GCOV_LINE_MARKER;
import static com.google.devtools.lcovmerger.Constants.GCOV_VERSION_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.DELIMITER;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_BRANCH_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_BRANCH_NOTEXEC;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_BRANCH_NOTTAKEN;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_BRANCH_TAKEN;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_CWD_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_FILE_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_FUNCTION_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_LINE_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.GCOV_VERSION_MARKER;
import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.BufferedReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.lcovmerger;
package com.google.devtools.coverageoutputgenerator;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.lcovmerger;
package com.google.devtools.coverageoutputgenerator;

import static com.google.devtools.lcovmerger.Constants.BA_MARKER;
import static com.google.devtools.lcovmerger.Constants.BRDA_MARKER;
import static com.google.devtools.lcovmerger.Constants.BRF_MARKER;
import static com.google.devtools.lcovmerger.Constants.BRH_MARKER;
import static com.google.devtools.lcovmerger.Constants.DA_MARKER;
import static com.google.devtools.lcovmerger.Constants.DELIMITER;
import static com.google.devtools.lcovmerger.Constants.END_OF_RECORD_MARKER;
import static com.google.devtools.lcovmerger.Constants.FNDA_MARKER;
import static com.google.devtools.lcovmerger.Constants.FNF_MARKER;
import static com.google.devtools.lcovmerger.Constants.FNH_MARKER;
import static com.google.devtools.lcovmerger.Constants.FN_MARKER;
import static com.google.devtools.lcovmerger.Constants.LF_MARKER;
import static com.google.devtools.lcovmerger.Constants.LH_MARKER;
import static com.google.devtools.lcovmerger.Constants.SF_MARKER;
import static com.google.devtools.lcovmerger.Constants.TAKEN;
import static com.google.devtools.coverageoutputgenerator.Constants.BA_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.BRDA_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.BRF_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.BRH_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.DA_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.DELIMITER;
import static com.google.devtools.coverageoutputgenerator.Constants.END_OF_RECORD_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.FNDA_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.FNF_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.FNH_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.FN_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.LF_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.LH_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.SF_MARKER;
import static com.google.devtools.coverageoutputgenerator.Constants.TAKEN;
import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.BufferedReader;
Expand All @@ -41,8 +41,8 @@
import java.util.logging.Logger;

/**
* A parser for the lcov tracefile format used by geninfo. See
* <a href="http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php"> lcov documentation</a>
* A parser for the lcov tracefile format used by geninfo. See <a
* href="http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php">lcov documentation</a>
*/
class LcovParser {

Expand All @@ -59,9 +59,8 @@ public static List<SourceFileCoverage> parse(InputStream inputStream) throws IOE
}

/**
* Reads the tracefile line by line and creates a SourceFileCoverage object
* for each section of the file between a SF:<source file> line and an
* end_of_record line.
* Reads the tracefile line by line and creates a SourceFileCoverage object for each section of
* the file between a SF:<source file> line and an end_of_record line.
*
* @return a list of each source file path found in the tracefile
*/
Expand Down Expand Up @@ -206,8 +205,8 @@ private boolean parseFNFLine(String line) {
int nrFunctionsFound = Integer.parseInt(lineContent);
assert currentSourceFileCoverage.nrFunctionsFound() == nrFunctionsFound;
} catch (NumberFormatException e) {
logger.log(Level.WARNING,
"Tracefile contains invalid number of functions on FNF line " + line);
logger.log(
Level.WARNING, "Tracefile contains invalid number of functions on FNF line " + line);
return false;
}
return true;
Expand All @@ -224,8 +223,8 @@ private boolean parseFNHLine(String line) {
int nrFunctionsHit = Integer.parseInt(lineContent);
assert currentSourceFileCoverage.nrFunctionsHit() == nrFunctionsHit;
} catch (NumberFormatException e) {
logger.log(Level.WARNING,
"Tracefile contains invalid number of functions hit on FNH line " + line);
logger.log(
Level.WARNING, "Tracefile contains invalid number of functions hit on FNH line " + line);
return false;
}
return true;
Expand Down Expand Up @@ -308,8 +307,8 @@ private boolean parseBRFLine(String line) {
int nrBranchesFound = Integer.parseInt(lineContent);
assert currentSourceFileCoverage.nrBranchesFound() == nrBranchesFound;
} catch (NumberFormatException e) {
logger.log(Level.WARNING,
"Tracefile contains invalid number of branches in BRDA line " + line);
logger.log(
Level.WARNING, "Tracefile contains invalid number of branches in BRDA line " + line);
return false;
}
return true;
Expand All @@ -326,8 +325,8 @@ private boolean parseBRHLine(String line) {
int nrBranchesHit = Integer.parseInt(lineContent);
assert currentSourceFileCoverage.nrBranchesHit() == nrBranchesHit;
} catch (NumberFormatException e) {
logger.log(Level.WARNING,
"Tracefile contains invalid number of branches hit in BRH line " + line);
logger.log(
Level.WARNING, "Tracefile contains invalid number of branches hit in BRH line " + line);
return false;
}
return true;
Expand All @@ -354,10 +353,8 @@ private boolean parseDALine(String line) {
if (lineData.length == 3) {
checkSum = lineData[2];
}
LineCoverage lineCoverage =
LineCoverage.create(lineNumber, executionCount, checkSum);
currentSourceFileCoverage.addLine(
lineNumber, lineCoverage);
LineCoverage lineCoverage = LineCoverage.create(lineNumber, executionCount, checkSum);
currentSourceFileCoverage.addLine(lineNumber, lineCoverage);
} catch (NumberFormatException e) {
logger.log(Level.WARNING, "Tracefile contains an invalid number on DA line " + line);
return false;
Expand Down Expand Up @@ -399,4 +396,3 @@ private boolean parseLFLine(String line) {
return true;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.devtools.lcovmerger;
package com.google.devtools.coverageoutputgenerator;

import static java.nio.charset.StandardCharsets.UTF_8;

Expand All @@ -27,8 +27,8 @@
import java.util.logging.Logger;

/**
* Prints coverage data stored in a collection of {@link SourceFileCoverage} in a
* <a href="http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php"> lcov tracefile format</a>
* Prints coverage data stored in a collection of {@link SourceFileCoverage} in a <a
* href="http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php">lcov tracefile format</a>
*/
class LcovPrinter {
private static final Logger logger = Logger.getLogger(LcovPrinter.class.getName());
Expand Down Expand Up @@ -67,7 +67,7 @@ private boolean print(Coverage coverage) {
/**
* Prints the given source data in an lcov tracefile format.
*
* Assumes the file is opened and closed outside of this method.
* <p>Assumes the file is opened and closed outside of this method.
*/
@VisibleForTesting
void print(SourceFileCoverage sourceFile) throws IOException {
Expand Down Expand Up @@ -95,8 +95,7 @@ private void printSFLine(SourceFileCoverage sourceFile) throws IOException {

// FN:<line number of function start>,<function name>
private void printFNLines(SourceFileCoverage sourceFile) throws IOException {
for (Entry<String, Integer> entry :
sourceFile.getAllLineNumbers()) {
for (Entry<String, Integer> entry : sourceFile.getAllLineNumbers()) {
bufferedWriter.write(Constants.FN_MARKER);
bufferedWriter.write(Integer.toString(entry.getValue())); // line number of function start
bufferedWriter.write(Constants.DELIMITER);
Expand All @@ -107,8 +106,7 @@ private void printFNLines(SourceFileCoverage sourceFile) throws IOException {

// FNDA:<execution count>,<function name>
private void printFNDALines(SourceFileCoverage sourceFile) throws IOException {
for (Entry<String, Integer> entry :
sourceFile.getAllExecutionCount()) {
for (Entry<String, Integer> entry : sourceFile.getAllExecutionCount()) {
bufferedWriter.write(Constants.FNDA_MARKER);
bufferedWriter.write(Integer.toString(entry.getValue())); // execution count
bufferedWriter.write(Constants.DELIMITER);
Expand Down Expand Up @@ -193,8 +191,7 @@ private void printBRHLine(SourceFileCoverage sourceFile) throws IOException {

// DA:<line number>,<execution count>[,<checksum>]
private void printDALines(SourceFileCoverage sourceFile) throws IOException {
for (LineCoverage lineExecution :
sourceFile.getAllLineExecution()) {
for (LineCoverage lineExecution : sourceFile.getAllLineExecution()) {
bufferedWriter.write(Constants.DA_MARKER);
bufferedWriter.write(Integer.toString(lineExecution.lineNumber()));
bufferedWriter.write(Constants.DELIMITER);
Expand Down
Loading

0 comments on commit 8f4786b

Please sign in to comment.