Skip to content

Commit 5995cdd

Browse files
committed
Improving nested reporting
1 parent cb5930d commit 5995cdd

6 files changed

Lines changed: 120 additions & 16 deletions

File tree

tools/apput/src/Reporters/ApplicationPackageReporter.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public ApplicationPackageReporter (ApplicationPackage package, MarkdownDocument
1616
this.package = package;
1717
}
1818

19-
protected override void DoReport ()
19+
protected override void DoReport (ReportForm form)
2020
{
2121
AddAspectDesc (package.PackageFormat);
2222

@@ -56,12 +56,8 @@ protected override void DoReport ()
5656
// Markdown renderer has a bug where it won't render the first item of the sub-list
5757
// properly if the item line ends with a formatting character (or whitespace)
5858
AddText (": ", addIndent: false);
59-
ReportDoc.BeginList ()
60-
.AddLabeledListItem ("Alignment", $"{lib.Alignment}")
61-
.AddLabeledListItem ("Debug info", $"{YesNo (lib.HasDebugInfo)}")
62-
.AddLabeledListItem ("Size", $"{lib.Size}", appendLine: false)
63-
.EndList ()
64-
.EndListItem ();
59+
var libReporter = new SharedLibraryReporter (lib, ReportDoc);
60+
libReporter.Report (ReportForm.SimpleList);
6561
}
6662
ReportDoc.AddNewline ();
6763
ReportDoc.EndList ();

tools/apput/src/Reporters/BaseReporter.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,22 @@ protected BaseReporter (MarkdownDocument doc)
4848
ReportDoc = doc;
4949
}
5050

51-
public void Report ()
51+
public void Report (ReportForm form)
5252
{
53-
WriteLine (BannerColor, $"# {AspectName} ({ShortDescription})");
54-
DoReport ();
55-
WriteLine ();
53+
bool standalone = form == ReportForm.Standalone;
54+
55+
if (standalone) {
56+
WriteLine (BannerColor, $"# {AspectName} ({ShortDescription})");
57+
}
58+
59+
DoReport (form);
60+
61+
if (standalone) {
62+
WriteLine ();
63+
}
5664
}
5765

58-
protected abstract void DoReport ();
66+
protected abstract void DoReport (ReportForm form);
5967

6068
protected MarkdownDocument AddSection (string text, uint level = 1) => ReportDoc.AddHeading (level, text).AddNewline ();
6169

@@ -96,6 +104,12 @@ protected void WriteNativeArch (NativeArchitecture arch)
96104
WriteItem (NativeArchitectureLabel, arch.ToString ());
97105
}
98106

107+
protected MarkdownDocument AddNativeArchListItem (NativeArchitecture arch)
108+
{
109+
ReportDoc.AddLabeledListItem (NativeArchitectureLabel, arch.ToString ());
110+
return ReportDoc;
111+
}
112+
99113
protected void WriteNativeArch (AndroidTargetArch arch)
100114
{
101115
WriteItem (NativeArchitectureLabel, arch.ToString ());

tools/apput/src/Reporters/IReporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ namespace ApplicationUtility;
22

33
interface IReporter
44
{
5-
void Report ();
5+
void Report (ReportForm form = ReportForm.Standalone);
66
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace ApplicationUtility;
2+
3+
/// <summary>
4+
/// Form in which the object report should be generated.
5+
/// </summary>
6+
enum ReportForm
7+
{
8+
/// <summary>
9+
/// Standalone format means the reporter can generate the document in
10+
/// an shape or form it wants as it's not part of a larger (outer)
11+
/// report.
12+
/// </summary>
13+
Standalone,
14+
15+
/// <summary>
16+
/// Report should be rendered as a simple list, one bit of information
17+
/// per list item. It is meant to be part of a larger (outer)
18+
/// report.
19+
/// </summary>
20+
SimpleList,
21+
}

tools/apput/src/Reporters/SharedLibraryReporter.cs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Text;
23

34
namespace ApplicationUtility;
@@ -17,7 +18,24 @@ public SharedLibraryReporter (SharedLibrary library, MarkdownDocument doc)
1718
this.library = library;
1819
}
1920

20-
protected override void DoReport ()
21+
protected override void DoReport (ReportForm form)
22+
{
23+
switch (form) {
24+
case ReportForm.Standalone:
25+
DoStandaloneReport ();
26+
break;
27+
28+
case ReportForm.SimpleList:
29+
DoListReport ();
30+
break;
31+
32+
default:
33+
throw new NotSupportedException ($"Unsupported report form '{form}'");
34+
}
35+
}
36+
37+
// TODO: migrate to Markdown
38+
void DoStandaloneReport ()
2139
{
2240
WriteAspectDesc (LibraryKind);
2341

@@ -37,6 +55,61 @@ protected override void DoReport ()
3755
}
3856
}
3957

58+
void DoListReport ()
59+
{
60+
ReportDoc.BeginList ();
61+
AddNativeArchListItem (library.TargetArchitecture);
62+
if (library.HasSoname) {
63+
ReportDoc.AddLabeledListItem ("Soname", ValueOrNone (library.Soname));
64+
}
65+
AddBuildId ();
66+
AddSize ();
67+
AddAlignment ();
68+
AddDebugInfo ();
69+
AddAndroidIdent (appendLine: false);
70+
71+
ReportDoc.EndList ().EndListItem ();
72+
}
73+
74+
void AddSoname ()
75+
{
76+
if (!library.HasSoname) {
77+
return;
78+
}
79+
80+
ReportDoc.AddLabeledListItem ("Soname", ValueOrNone (library.Soname));
81+
}
82+
83+
void AddBuildId (bool appendLine = true)
84+
{
85+
ReportDoc.AddLabeledListItem ("Build ID", ValueOrNone (library.BuildID), appendLine: appendLine);
86+
}
87+
88+
void AddAlignment (bool appendLine = true)
89+
{
90+
ReportDoc.AddLabeledListItem ("Alignment", $"{library.Alignment}", appendLine: appendLine);
91+
}
92+
93+
void AddDebugInfo (bool appendLine = true)
94+
{
95+
ReportDoc.AddLabeledListItem ("Debug info", $"{YesNo (library.HasDebugInfo)}", appendLine: appendLine);
96+
}
97+
98+
void AddSize (bool appendLine = true)
99+
{
100+
ReportDoc.AddLabeledListItem ("Size", $"{library.Size}", appendLine: appendLine);
101+
}
102+
103+
void AddAndroidIdent (bool appendLine = true)
104+
{
105+
if (!library.HasAndroidIdent) {
106+
return;
107+
}
108+
109+
// TODO: fix output, currently produces gibberish
110+
ReportDoc.AddLabeledListItem ("Android ident", "FIXME" /* ValueOrNone (library.AndroidIdent) */);
111+
}
112+
40113
protected void WriteDebugInfoDesc ()
41114
{
42115
WriteItem ("Has debug info", YesNo (library.HasDebugInfo));

tools/apput/src/Reporters/XamarinAppSharedLibraryReporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public XamarinAppSharedLibraryReporter (XamarinAppSharedLibrary library, Markdow
1414
this.library = library;
1515
}
1616

17-
protected override void DoReport ()
17+
protected override void DoReport (ReportForm form)
1818
{
19-
base.DoReport ();
19+
base.DoReport (form);
2020
WriteSubsectionBanner ("Xamarin.Android app library info");
2121
WriteItem ("Format tag", $"0x{library.FormatTag:x}");
2222
}

0 commit comments

Comments
 (0)