llvm.org GIT mirror llvm / 5b5c5e7
[llvm-cov] Do not print out the filename of the object file When we load coverage data from multiple objects, we don't have a way to attribute a source object to a function record. Printing out the object filename next to the source filename is already not very useful: soon, it'll actually become misleading. Stop printing out the filename now. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285043 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 3 years ago
15 changed file(s) with 25 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
0 // Metadata section
1 // CHECK: {"version":"1.1.0","type":"llvm.coverage.json.export","data":[
1 // CHECK: {"version":"{{[0-9]\.[0-9]\.[0-9]}}","type":"llvm.coverage.json.export","data":[
22
33 // Open Export
4 // CHECK-SAME: {"object":"{{[^"]+}}","files":[
4 // CHECK-SAME: {"files":[
55
66 // File Object
77 // CHECK-SAME: {"filename":"{{[^"]+}}binary-formats.c",
0 // Metadata section
1 // CHECK: {"version":"1.1.0","type":"llvm.coverage.json.export","data":[
1 // CHECK: {"version":"{{[0-9]\.[0-9]\.[0-9]}}","type":"llvm.coverage.json.export","data":[
22
33 // Open Export
4 // CHECK-SAME: {"object":"{{[^"]+}}","files":[
4 // CHECK-SAME: {"files":[
55
66 // File Object
77 // CHECK-SAME: {"filename":"{{[^"]+}}showHighlightedRanges.cpp",
0 // Metadata section
1 // CHECK: {"version":"1.1.0","type":"llvm.coverage.json.export","data":[
1 // CHECK: {"version":"{{[0-9]\.[0-9]\.[0-9]}}","type":"llvm.coverage.json.export","data":[
22
33 // Open Export
4 // CHECK-SAME: {"object":"{{[^"]+}}","files":[
4 // CHECK-SAME: {"files":[
55
66 // File Object
77 // CHECK-SAME: {"filename":"{{[^"]+}}showLineExecutionCounts.cpp",
0 // Metadata section
1 // CHECK: {"version":"1.1.0","type":"llvm.coverage.json.export","data":[
1 // CHECK: {"version":"{{[0-9]\.[0-9]\.[0-9]}}","type":"llvm.coverage.json.export","data":[
22
33 // Open Export
4 // CHECK-SAME: {"object":"{{[^"]+}}","files":[
4 // CHECK-SAME: {"files":[
55
66 // File Object
77 // CHECK-SAME: {"filename":"{{[^"]+}}showRegionMarkers.cpp",
0 // Metadata section
1 // CHECK: {"version":"1.1.0","type":"llvm.coverage.json.export","data":[
1 // CHECK: {"version":"{{[0-9]\.[0-9]\.[0-9]}}","type":"llvm.coverage.json.export","data":[
22
33 // Open Export
4 // CHECK-SAME: {"object":"{{[^"]+}}","files":[
4 // CHECK-SAME: {"files":[
55
66 // File Object
77 // CHECK-SAME: {"filename":"{{[^"]+}}showExpansions.cpp",
0 TEXT-TITLE: Test Suite
11 TEXT-NOT: Coverage Report
22 TEXT-NOT: Created:
3 TEXT-FILE-NOT: (Binary: showProjectSummary.covmapping)
43 TEXT-FUNCTION: main:
54 TEXT-FOOTER: Generated by llvm-cov
65
76 HTML-TITLE:

Test Suite

87 HTML:

Coverage Report

98 HTML:

Created:{{.*}}

10 HTML-FILE:
{{.*}}showProjectSummary.cpp (Binary: showProjectSummary.covmapping)
9 HTML-FILE:
{{.*}}showProjectSummary.cpp
1110 HTML-FUNCTION:
main
1211 HTML-HEADER:
Line
1312 HTML-HEADER:
Count
0 // Metadata section
1 // CHECK: {"version":"1.1.0","type":"llvm.coverage.json.export","data":[
1 // CHECK: {"version":"{{[0-9]\.[0-9]\.[0-9]}}","type":"llvm.coverage.json.export","data":[
22
33 // Open Export
4 // CHECK-SAME: {"object":"{{[^"]+}}","files":[
4 // CHECK-SAME: {"files":[
55
66 // File Object
77 // CHECK-SAME: {"filename":"{{[^"]+}}universal-binary.c",
1414
1515 // TEXT-INDEX: \tmp\native_separators.c
1616 // HTML-INDEX: >tmp\native_separators.c
17 // HTML:
\tmp\native_separators.c (Binary: native_separators.covmapping)
17 // HTML:
\tmp\native_separators.c
1818
1919 int main() {}
3838 using namespace llvm;
3939 using namespace coverage;
4040
41 void exportCoverageDataToJson(StringRef ObjectFilename,
42 const coverage::CoverageMapping &CoverageMapping,
41 void exportCoverageDataToJson(const coverage::CoverageMapping &CoverageMapping,
4342 raw_ostream &OS);
4443
4544 namespace {
569568 CompareFilenamesOnly = FilenameEquivalence;
570569
571570 ViewOpts.Format = Format;
572 SmallString<128> ObjectFilePath(this->ObjectFilename);
573 if (std::error_code EC = sys::fs::make_absolute(ObjectFilePath)) {
574 error(EC.message(), this->ObjectFilename);
575 return 1;
576 }
577 sys::path::native(ObjectFilePath);
578 ViewOpts.ObjectFilename = ObjectFilePath.c_str();
579571 switch (ViewOpts.Format) {
580572 case CoverageViewOptions::OutputFormat::Text:
581573 ViewOpts.Colors = UseColor == cl::BOU_UNSET
842834 return 1;
843835 }
844836
845 exportCoverageDataToJson(ObjectFilename, *Coverage.get(), outs());
837 exportCoverageDataToJson(*Coverage.get(), outs());
846838
847839 return 0;
848840 }
4747 #include
4848
4949 /// \brief The semantic version combined as a string.
50 #define LLVM_COVERAGE_EXPORT_JSON_STR "1.1.0"
50 #define LLVM_COVERAGE_EXPORT_JSON_STR "2.0.0"
5151
5252 /// \brief Unique type identifier for JSON coverage export.
5353 #define LLVM_COVERAGE_EXPORT_JSON_TYPE_STR "llvm.coverage.json.export"
5656 using namespace coverage;
5757
5858 class CoverageExporterJson {
59 /// \brief A Name of the object file coverage is for.
60 StringRef ObjectFilename;
61
6259 /// \brief Output stream to print JSON to.
6360 raw_ostream &OS;
6461
7067
7168 /// \brief Tracks state of the JSON output.
7269 std::stack State;
73
74 /// \brief Get the object filename.
75 StringRef getObjectFilename() const { return ObjectFilename; }
7670
7771 /// \brief Emit a serialized scalar.
7872 void emitSerialized(const int64_t Value) { OS << Value; }
169163
170164 // Start Export.
171165 emitDictStart();
172 emitDictElement("object", getObjectFilename());
173166
174167 emitDictKey("files");
175168
409402 }
410403
411404 public:
412 CoverageExporterJson(StringRef ObjectFilename,
413 const CoverageMapping &CoverageMapping, raw_ostream &OS)
414 : ObjectFilename(ObjectFilename), OS(OS), Coverage(CoverageMapping) {
405 CoverageExporterJson(const CoverageMapping &CoverageMapping, raw_ostream &OS)
406 : OS(OS), Coverage(CoverageMapping) {
415407 State.push(JsonState::None);
416408 }
417409
420412 };
421413
422414 /// \brief Export the given CoverageMapping to a JSON Format.
423 void exportCoverageDataToJson(StringRef ObjectFilename,
424 const CoverageMapping &CoverageMapping,
415 void exportCoverageDataToJson(const CoverageMapping &CoverageMapping,
425416 raw_ostream &OS) {
426 auto Exporter = CoverageExporterJson(ObjectFilename, CoverageMapping, OS);
417 auto Exporter = CoverageExporterJson(CoverageMapping, OS);
427418
428419 Exporter.print();
429420 }
3535 std::vector DemanglerOpts;
3636 uint32_t TabSize;
3737 std::string ProjectTitle;
38 std::string ObjectFilename;
3938 std::string CreatedTimeStr;
4039
4140 /// \brief Change the output's stream color if the colors are enabled.
148148 return SourceText.str();
149149 }
150150
151 std::string SourceCoverageView::getVerboseSourceName() const {
152 return getSourceName() + " (Binary: " +
153 sys::path::filename(getOptions().ObjectFilename).str() + ")";
154 }
155
156151 void SourceCoverageView::addExpansion(
157152 const coverage::CounterMappingRegion &Region,
158153 std::unique_ptr View) {
276276 /// \brief Return the source name formatted for the host OS.
277277 std::string getSourceName() const;
278278
279 /// \brief Return a verbose description of the source name and the binary it
280 /// corresponds to.
281 std::string getVerboseSourceName() const;
282
283279 const CoverageViewOptions &getOptions() const { return Options; }
284280
285281 /// \brief Add an expansion subview to this view.
405405 }
406406
407407 void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile) {
408 OS << BeginSourceNameDiv;
409 std::string ViewInfo = escape(
410 WholeFile ? getVerboseSourceName() : getSourceName(), getOptions());
411 OS << tag("pre", ViewInfo);
412 OS << EndSourceNameDiv;
408 OS << BeginSourceNameDiv << tag("pre", escape(getSourceName(), getOptions()))
409 << EndSourceNameDiv;
413410 }
414411
415412 void SourceCoverageViewHTML::renderLinePrefix(raw_ostream &OS, unsigned) {
6969 void SourceCoverageViewText::renderViewFooter(raw_ostream &) {}
7070
7171 void SourceCoverageViewText::renderSourceName(raw_ostream &OS, bool WholeFile) {
72 std::string ViewInfo = WholeFile ? getVerboseSourceName() : getSourceName();
73 getOptions().colored_ostream(OS, raw_ostream::CYAN) << ViewInfo << ":\n";
72 getOptions().colored_ostream(OS, raw_ostream::CYAN) << getSourceName()
73 << ":\n";
7474 }
7575
7676 void SourceCoverageViewText::renderLinePrefix(raw_ostream &OS,