Skip to content

Commit fc07188

Browse files
committed
Added some excessive logging to fixup applier
1 parent 76f67b4 commit fc07188

File tree

4 files changed

+56
-38
lines changed

4 files changed

+56
-38
lines changed

run.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/bash
2-
exec mono --debug tools/BindingGenerator/bin/Debug/generator2.exe -w --fixup=metadata --fixup=enummetadata -l=debug --dump-fixedup --dump-hierarchy api.xml
2+
rm -f run.log
3+
exec mono --debug tools/BindingGenerator/bin/Debug/generator2.exe -w --fixup=metadata --fixup=enummetadata -l=verbose --dump-fixedup --dump-hierarchy api.xml | tee -a run.log

src/Java.Interop.Bindings/LogLevel.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ namespace Java.Interop.Bindings
2929
{
3030
public enum LogLevel
3131
{
32-
Fatal = 0,
33-
Error = 1,
34-
Warning = 2,
35-
Info = 3,
36-
Debug = 4,
37-
Verbose = 5,
32+
Fatal = 0,
33+
Error = 1,
34+
Warning = 2,
35+
Info = 3,
36+
Debug = 4,
37+
Verbose = 5,
38+
Excessive = 6
3839
}
3940
}

src/Java.Interop.Bindings/Logger.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ public static void Warning (string message)
4848
{
4949
if (Level < LogLevel.Warning)
5050
return;
51-
51+
5252
Write ($"Warning: {message}");
5353
}
5454

5555
public static void Info (string message)
5656
{
5757
if (Level < LogLevel.Info)
5858
return;
59-
59+
6060
Write ($"Info: {message}");
6161
}
6262

6363
public static void Debug (string message)
6464
{
6565
if (Level < LogLevel.Debug)
6666
return;
67-
67+
6868
Write ($"Debug: {message}");
6969
}
7070

@@ -76,6 +76,14 @@ public static void Verbose (string message)
7676
Write ($"Verbose: {message}");
7777
}
7878

79+
public static void Excessive (string message)
80+
{
81+
if (Level < LogLevel.Excessive)
82+
return;
83+
84+
Write ($"Excessive: {message}");
85+
}
86+
7987
static void Write (string text)
8088
{
8189
Console.WriteLine (text);

src/Java.Interop.Bindings/Syntax/ApiFixupApplier.cs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public ApiFixupApplier (XDocument theDoc, XDocument theFixups, string fixupsFile
4646

4747
public void Apply ()
4848
{
49+
Logger.Debug ($"Applying fixups from: {fixupsPath}");
4950
foreach (XElement fixup in fixups.XPathSelectElements ("/metadata/*"))
5051
Apply (doc, fixup);
5152
}
@@ -56,34 +57,34 @@ protected virtual void Apply (XDocument doc, XElement fixup)
5657
switch (fixup.Name.LocalName) {
5758
case "remove-node":
5859
DoOp ((XElement node) => node.Remove (),
59-
// BG8A00
60-
() => Report.Warning (0, Report.WarningApiFixup + 0, null, fixup, $"<remove-node path=\"{path}\"/> matched no nodes."),
61-
// BG4A01
62-
(Exception e) => Report.Error (Report.ErrorApiFixup + 1, e, fixup, $"Invalid XPath specification: {path}")
63-
);
60+
// BG8A00
61+
() => Report.Warning (0, Report.WarningApiFixup + 0, null, fixup, $"<remove-node path=\"{path}\"/> matched no nodes."),
62+
// BG4A01
63+
(Exception e) => Report.Error (Report.ErrorApiFixup + 1, e, fixup, $"Invalid XPath specification: {path}")
64+
);
6465
break;
6566

6667
case "add-node":
6768
DoOp ((XElement node) => node.Add (fixup.Nodes ()),
68-
// BG8A01
69-
() => Report.Warning (0, Report.WarningApiFixup + 1, null, fixup, $"<add-node path=\"{path}\"/> matched no nodes."),
70-
// BG4A02
71-
(Exception e) => Report.Error (Report.ErrorApiFixup + 2, e, fixup, $"Invalid XPath specification: {path}")
72-
);
69+
// BG8A01
70+
() => Report.Warning (0, Report.WarningApiFixup + 1, null, fixup, $"<add-node path=\"{path}\"/> matched no nodes."),
71+
// BG4A02
72+
(Exception e) => Report.Error (Report.ErrorApiFixup + 2, e, fixup, $"Invalid XPath specification: {path}")
73+
);
7374
break;
7475

7576
case "change-node":
7677
DoOp ((XElement node) => {
77-
var newChild = new XElement (fixup.Value);
78-
newChild.Add (node.Attributes ());
79-
newChild.Add (node.Nodes ());
80-
node.ReplaceWith (newChild);
81-
},
78+
var newChild = new XElement (fixup.Value);
79+
newChild.Add (node.Attributes ());
80+
newChild.Add (node.Nodes ());
81+
node.ReplaceWith (newChild);
82+
},
8283
// BG8A03
8384
() => Report.Warning (0, Report.WarningApiFixup + 3, null, fixup, $"<change-node-type path=\"{path}\"/> matched no nodes."),
8485
// BG4A03
8586
(Exception e) => Report.Error (Report.ErrorApiFixup + 3, e, fixup, $"Invalid XPath specification: {path}")
86-
);
87+
);
8788
break;
8889

8990
case "attr":
@@ -93,11 +94,11 @@ protected virtual void Apply (XDocument doc, XElement fixup)
9394
Report.Error (Report.ErrorApiFixup + 7, null, fixup, $"Target attribute name is not specified for path: {path}");
9495

9596
DoOp ((XElement node) => node.SetAttributeValue (attr_name, fixup.Value),
96-
// BG8A04
97-
() => Report.Warning (0, Report.WarningApiFixup + 4, null, fixup, $"<attr path=\"{path}\"/> matched no nodes."),
98-
// BG4A04
99-
(Exception e) => Report.Error (Report.ErrorApiFixup + 4, e, fixup, $"Invalid XPath specification: {path}")
100-
);
97+
// BG8A04
98+
() => Report.Warning (0, Report.WarningApiFixup + 4, null, fixup, $"<attr path=\"{path}\"/> matched no nodes."),
99+
// BG4A04
100+
(Exception e) => Report.Error (Report.ErrorApiFixup + 4, e, fixup, $"Invalid XPath specification: {path}")
101+
);
101102
break;
102103

103104
case "move-node":
@@ -123,11 +124,11 @@ protected virtual void Apply (XDocument doc, XElement fixup)
123124

124125
case "remove-attr":
125126
DoOp ((XElement node) => node.RemoveAttributes (),
126-
// BG8A06
127-
() => Report.Warning (0, Report.WarningApiFixup + 6, null, fixup, $"<remove-attr path=\"{path}\"/> matched no nodes."),
128-
// BG4A06
129-
(Exception e) => Report.Error (Report.ErrorApiFixup + 6, e, fixup, $"Invalid XPath specification: {path}")
130-
);
127+
// BG8A06
128+
() => Report.Warning (0, Report.WarningApiFixup + 6, null, fixup, $"<remove-attr path=\"{path}\"/> matched no nodes."),
129+
// BG4A06
130+
(Exception e) => Report.Error (Report.ErrorApiFixup + 6, e, fixup, $"Invalid XPath specification: {path}")
131+
);
131132
break;
132133

133134
default:
@@ -137,12 +138,19 @@ protected virtual void Apply (XDocument doc, XElement fixup)
137138

138139
void DoOp (Action <XElement> operation, Action warning = null, Action<Exception> exception = null)
139140
{
141+
// Serialization is expensive
142+
if (Logger.Level >= LogLevel.Excessive)
143+
Logger.Excessive ($" Fixup source: {fixup.ToString ()}");
144+
140145
try {
141-
IEnumerable<XElement> nodes = doc.XPathSelectElements(path);
146+
IEnumerable<XElement> nodes = doc.XPathSelectElements (path);
142147
if (nodes.Any ()) {
143148
foreach (XElement node in nodes) {
144149
if (node == null) // Unlikely, but won't hurt
145-
operation (node);
150+
continue;
151+
if (Logger.Level >= LogLevel.Excessive)
152+
Logger.Excessive ($" Applying to: {node.ToString ()}");
153+
operation (node);
146154
}
147155
} else
148156
warning?.Invoke ();

0 commit comments

Comments
 (0)