Skip to content

Commit cce7951

Browse files
committed
[api-xml-adjuster] give chance to set logging verbosity in ApiXmlAdjuster.
ApiXmlAdjuster had been ignoring logging verbosity, but now it is time to respect that at least from generator. (mono xbuild does not appropriately implement some MSBuild logging API so it will not be usable very soon until we switch to Microsoft/msbuild...)
1 parent 7985cb9 commit cce7951

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

src/Xamarin.Android.Tools.ApiXmlAdjuster/JavaApiDefectFinderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void FindParametersDefects (this JavaMethodBase methodBase)
2222
int dummy;
2323
foreach (var p in methodBase.Parameters) {
2424
if (p.Name.StartsWith ("p", StringComparison.Ordinal) && int.TryParse (p.Name.Substring (1), out dummy)) {
25-
Console.Error.WriteLine ("Warning: {0} in {1} has 'unnamed' parameters", methodBase.Parent, methodBase);
25+
Log.LogWarning ("Warning: {0} in {1} has 'unnamed' parameters", methodBase.Parent, methodBase);
2626
break; // reporting once is enough.
2727
}
2828
}

src/Xamarin.Android.Tools.ApiXmlAdjuster/JavaApiGenericInheritanceMapperExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void PrepareGenericInheritanceMapping (this JavaClass cls)
3030
cls.GenericInheritanceMapping = empty;
3131
else if (cls.ResolvedExtends.ReferencedType.TypeParameters == null) {
3232
// FIXME: I guess this should not happen. But this still happens.
33-
Console.WriteLine ("Warning: '{0}' is referenced as base type of '{1}' and expected to have generic type parameters, but it does not.", cls.ExtendsGeneric, cls.FullName);
33+
Log.LogWarning ("Warning: '{0}' is referenced as base type of '{1}' and expected to have generic type parameters, but it does not.", cls.ExtendsGeneric, cls.FullName);
3434
cls.GenericInheritanceMapping = empty;
3535
} else {
3636
if (cls.ResolvedExtends.ReferencedType.TypeParameters.TypeParameters.Count != cls.ResolvedExtends.TypeParameters.Count)
@@ -44,8 +44,6 @@ static void PrepareGenericInheritanceMapping (this JavaClass cls)
4444
dic.Add (new JavaTypeReference (kvp.Key, null), kvp.Value);
4545
if (dic.Any ()) {
4646
cls.GenericInheritanceMapping = dic;
47-
//Console.WriteLine ("in {0}.{1}: {2}", cls.Parent.Name, cls.Name,
48-
// string.Join (", ", dic.Select (p => string.Format ("base {0} becomes {1}", p.Key.ReferencedTypeParameter.Name, p.Value.ToString ()))));
4947
}
5048
else
5149
cls.GenericInheritanceMapping = empty;

src/Xamarin.Android.Tools.ApiXmlAdjuster/JavaApiTypeResolverExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public static void Resolve (this JavaApi api)
5454
while (true) {
5555
bool errors = false;
5656
foreach (var t in api.Packages.SelectMany (p => p.Types).OfType<JavaClass> ().ToArray ())
57-
try { t.Resolve (); } catch (JavaTypeResolutionException ex) { Console.Error.WriteLine (string.Format ("Error while processing type '{0}': {1}", t, ex.Message)); errors = true; t.Parent.Types.Remove (t); }
57+
try { t.Resolve (); } catch (JavaTypeResolutionException ex) { Log.LogError ("Error while processing type '{0}': {1}", t, ex.Message); errors = true; t.Parent.Types.Remove (t); }
5858
foreach (var t in api.Packages.SelectMany (p => p.Types).OfType<JavaInterface> ().ToArray ())
59-
try { t.Resolve (); } catch (JavaTypeResolutionException ex) { Console.Error.WriteLine (string.Format ("Error while processing type '{0}': {1}", t, ex.Message)); errors = true; t.Parent.Types.Remove (t); }
59+
try { t.Resolve (); } catch (JavaTypeResolutionException ex) { Log.LogError ("Error while processing type '{0}': {1}", t, ex.Message); errors = true; t.Parent.Types.Remove (t); }
6060
if (!errors)
6161
break;
6262
}
@@ -89,7 +89,7 @@ static void ResolveWithTryCatch (Action resolve, JavaMember m)
8989
try {
9090
resolve ();
9191
} catch (JavaTypeResolutionException ex) {
92-
Console.Error.WriteLine (string.Format ("Error while processing '{0}' in '{1}': {2}", m, m.Parent, ex.Message));
92+
Log.LogError ("Error while processing '{0}' in '{1}': {2}", m, m.Parent, ex.Message);
9393
m.Parent.Members.Remove (m);
9494
}
9595
}
@@ -128,7 +128,7 @@ static void Resolve (this JavaTypeParameters tp, JavaApi api, params JavaTypePar
128128
foreach (var t in tp.TypeParameters)
129129
if (t.GenericConstraints != null)
130130
foreach (var g in t.GenericConstraints.GenericConstraints)
131-
try { g.ResolvedType = api.Parse (g.Type, additionalTypeParameters); } catch (JavaTypeResolutionException ex) { Console.Error.WriteLine (string.Format ("Warning: failed to resolve generic constraint: '{0}': {1}", g.Type, ex.Message)); }
131+
try { g.ResolvedType = api.Parse (g.Type, additionalTypeParameters); } catch (JavaTypeResolutionException ex) { Log.LogWarning ("Warning: failed to resolve generic constraint: '{0}': {1}", g.Type, ex.Message); }
132132
}
133133
}
134134
}

src/Xamarin.Android.Tools.ApiXmlAdjuster/JavaTypeResolutionUtil.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ static bool IsConformantType (this JavaTypeParameter typeParameter, JavaTypeRefe
8585
if (typeParameter.GenericConstraints == null)
8686
return true;
8787
// FIXME: implement correct generic constraint conformance check.
88-
Console.Error.WriteLine ("WARNING: generic constraint conformance check is not implemented, so the type might be actually compatible. Type parameter: {0}{1}, examined type: {2}",
89-
typeParameter.Name, typeParameter.Parent.ParentMethod?.Name ?? typeParameter.Parent.ParentType?.Name, examinedType.ToString ());
88+
Log.LogDebug ("NOTICE: generic constraint conformance check is not implemented, so the type might be actually compatible. Type parameter: {0}{1}, examined type: {2}",
89+
typeParameter.Name, typeParameter.Parent.ParentMethod?.Name ?? typeParameter.Parent.ParentType?.Name, examinedType);
9090
return false;
9191
}
9292
}

src/Xamarin.Android.Tools.ApiXmlAdjuster/Xamarin.Android.Tools.ApiXmlAdjuster.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<Compile Include="JavaApiDefectFinderExtensions.cs" />
5050
<Compile Include="JavaTypeResolutionUtil.cs" />
5151
<Compile Include="JavaApiFixVisibilityExtensions.cs" />
52+
<Compile Include="Log.cs" />
5253
</ItemGroup>
5354
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
5455
</Project>

tools/generator/ApiXmlAdjuster.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@ namespace Xamarin.Android.Tools.ApiXmlAdjuster
55
{
66
public class Adjuster
77
{
8-
public void Process (string inputXmlFile, GenBase [] gens, string outputXmlFile)
8+
public void Process (string inputXmlFile, GenBase [] gens, string outputXmlFile, int reportVerbosity)
99
{
10+
switch (reportVerbosity) {
11+
case 0:
12+
break;
13+
case 1:
14+
Log.Verbosity = Log.LoggingLevel.Error;
15+
break;
16+
case 2:
17+
Log.Verbosity = Log.LoggingLevel.Warning;
18+
break;
19+
default:
20+
Log.Verbosity = Log.LoggingLevel.Debug;
21+
break;
22+
}
1023
var api = new JavaApi ();
1124
api.LoadReferences (gens);
1225
api.Load (inputXmlFile);

tools/generator/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve
282282
}
283283
if (apiSourceAttr == "class-parse") {
284284
apiXmlFile = api_xml_adjuster_output ?? Path.Combine (Path.GetDirectoryName (filename), Path.GetFileName (filename) + ".adjusted");
285-
new Adjuster ().Process (filename, SymbolTable.AllRegisteredSymbols ().OfType<GenBase> ().ToArray (), apiXmlFile);
285+
new Adjuster ().Process (filename, SymbolTable.AllRegisteredSymbols ().OfType<GenBase> ().ToArray (), apiXmlFile, Report.Verbosity ?? 0);
286286
}
287287
if (only_xml_adjuster)
288288
return;

0 commit comments

Comments
 (0)