Commit ee04f6a4 authored by Alberto Mardegan's avatar Alberto Mardegan

Build: add coverage report

parent 2a19b59f
......@@ -50,6 +50,7 @@ DynamicLibrary {
]
}
Depends { name: "buildconfig" }
Depends { name: "cpp" }
Depends { name: "Qt.gui" }
Depends { name: "Qt.qml" }
......
......@@ -35,6 +35,7 @@ DynamicLibrary {
]
}
Depends { name: "buildconfig" }
Depends { name: "cpp" }
Depends { name: "Qt.quick" }
......
......@@ -23,5 +23,8 @@ Project {
"tests/tests.qbs",
]
AutotestRunner { name: "check" }
AutotestRunner {
name: "check"
Depends { productTypes: ["coverage-clean"] }
}
}
import qbs
Product {
name: "coverage-clean"
builtByDefault: false
files: ["**"]
type: ["coverage-clean"]
Rule {
multiplex: true
outputFileTags: "coverage-clean"
requiresInputs: false
prepare: {
var cleanCmd = new Command("find", [
project.sourceDirectory,
"-type", "f",
"(",
"-name", "*.gcda",
"-o",
"-name", "coverage.info",
")",
"-delete",
]);
cleanCmd.description = "Clearing coverage data";
cleanCmd.highlight = "coverage";
cleanCmd.silent = false;
return [cleanCmd];
}
}
}
import qbs
Product {
name: "coverage"
property string outputDirectory: "coverage-html"
property stringList extractPatterns: []
builtByDefault: false
files: ["**"]
type: ["coverage.html"]
Depends { productTypes: ["autotest-result"] }
Rule {
multiplex: true
explicitlyDependsOnFromDependencies: ["autotest-result"]
outputFileTags: "coverage.html"
requiresInputs: false
prepare: {
var commands = []
var captureCmd = new Command("lcov", [
"--directory", project.sourceDirectory,
"--capture",
"--output-file", "coverage.info",
"--no-checksum",
"--compat-libtool",
]);
captureCmd.description = "Collecting coverage data";
captureCmd.highlight = "coverage";
captureCmd.silent = false;
commands.push(captureCmd);
var extractArgs = []
for (var i = 0; i < product.extractPatterns.length; i++) {
extractArgs.push("--extract");
extractArgs.push("coverage.info");
extractArgs.push(product.extractPatterns[i]);
}
if (product.extractPatterns.length > 0) {
extractArgs.push("-o");
extractArgs.push("coverage.info");
var extractCmd = new Command("lcov", extractArgs);
extractCmd.description = "Extracting coverage data";
extractCmd.highlight = "coverage";
extractCmd.silent = false;
commands.push(extractCmd);
}
var filterCmd = new Command("lcov", [
"--remove", "coverage.info", 'moc_*.cpp',
"--remove", "coverage.info", 'qrc_*.cpp',
"--remove", "coverage.info", '*/tests/*',
"-o", "coverage.info",
]);
filterCmd.description = "Filtering coverage data";
filterCmd.highlight = "coverage";
filterCmd.silent = false;
commands.push(filterCmd);
var genhtmlCmd = new Command("genhtml", [
"--prefix", project.sourceDirectory,
"--output-directory", product.outputDirectory,
"--title", "Code coverage",
"--legend",
"--show-details",
"coverage.info",
]);
genhtmlCmd.description = "Generate HTML coverage report";
genhtmlCmd.highlight = "coverage";
genhtmlCmd.silent = false;
commands.push(genhtmlCmd);
return commands;
}
}
}
import qbs
Module {
cpp.cxxFlags: project.enableCoverage ? ["--coverage"] : undefined
cpp.dynamicLibraries: project.enableCoverage ? ["gcov"] : undefined
Depends { name: "cpp" }
}
......@@ -80,6 +80,7 @@ QtGuiApplication {
]
}
Depends { name: "buildconfig" }
Depends { name: "cpp" }
Depends { name: "Qt.quick" }
Depends { name: "Mappero" }
......
......@@ -6,4 +6,13 @@ Project {
references: [
"path/path.qbs",
]
CoverageClean {
condition: project.enableCoverage
}
CoverageReport {
condition: project.enableCoverage
extractPatterns: [ '*/src/*.cpp', '*/lib/*.cpp' ]
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment