Skip to content

Commit a301764

Browse files
committed
Remove DroidDoc dependencies from enumification helpers.
api-*.xml.in can be generated dynamically (up to [*1]) but enumification helper tools still depended on DroidDoc, meaning that we cannot remove package download dependencies. This fixes the situation by eliminating the dependencies. Especially it is easier to just parse api-*.xml.in to extract int consts from Java API. ... thought so? It turnd out to not be that easy. Unlike DroidDoc, api-*.xml.in does not contain "api-since" information, so we need to parse ALL the API XML. And they cannot be **precise** because we only have a subset of the API definitions. For example, "since API Level 1" now becomes "since API Level 10" because we don't have api-1.xml.in (not even api-4.xml.in). So they will become non-precise. (A slightly better possibility to "fix" this is to parse `android-sdk-whatever/platform-tools/api/api-versions.xml`, but it won't contain "already vanished" constants so it will be incomplete either. I didn't bother to do "better" so far. We don't need that for enumification.) Therefore, there is a lot of changes in `map.csv` to reflect those "insignificant" changes to remap "API since" column (e.g. from "1" to "10"). Regeneration from api-LEVEL.xml.in instead of DroidDoc has some other side effects; some consts are back to the list so that we don't have to manually copy existing mapped consts that could not be generated from the latest DroidDocs (due to disappearance) anymore. Instead we have to remove manually-mapped constants (either from the sources or `map.csv`). Therefore, a handful of heading lines in `map.csv` were removed, and some definitions in `enum-conversion-mappings.xml` are back. [*1] #1038
1 parent 4e0dacb commit a301764

File tree

7 files changed

+2966
-3069
lines changed

7 files changed

+2966
-3069
lines changed
Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
topdir = ../..
22

3-
API_LEVEL = 26
4-
API_LEVEL_NAME = 26
3+
API_LEVEL = 27
4+
API_LEVEL_NAME = 27
55

66
CSCOMPILE = csc -debug:portable
77

88
CONFIGURATION = Debug
9-
DOCS_DIR=~/android-toolchain/docs/docs-api-$(API_LEVEL_NAME)
109

1110
CONST_MAPPER_SOURCES = \
1211
generate-const-mapping.cs \
@@ -15,20 +14,11 @@ CONST_MAPPER_SOURCES = \
1514

1615
all:: map.ext.csv remaining-int-consts.txt remaining-int-methods-filtered.txt
1716

18-
#enum mappings
17+
generate-const-list-2.exe: generate-const-list-2.cs
18+
$(CSCOMPILE) generate-const-list-2.cs
1919

20-
generate-const-list.exe: generate-const-list.cs
21-
$(CSCOMPILE) generate-const-list.cs
22-
23-
const-list-$(API_LEVEL).xml: generate-const-list.exe
24-
mono --debug generate-const-list.exe $(DOCS_DIR)/reference/ -v > const-list-$(API_LEVEL).xml || rm const-list-$(API_LEVEL).xml
25-
26-
generate-intermediary-enum-candidates.exe : generate-intermediary-enum-candidates.cs
27-
$(CSCOMPILE) generate-intermediary-enum-candidates.cs
28-
29-
#it is obsolete
30-
intermediary-enum-candidates.xml: generate-intermediary-enum-candidates.exe
31-
mono --debug generate-intermediary-enum-candidates.exe $(topdir)/src/Mono.Android/api-$(API_LEVEL).xml.in > intermediary-enum-candidates.xml || rm intermediary-enum-candidates.xml
20+
const-list-$(API_LEVEL).xml: generate-const-list-2.exe ../../src/Mono.Android/Profiles/*.xml.in
21+
mono --debug generate-const-list-2.exe ../../src/Mono.Android/Profiles > const-list-$(API_LEVEL).xml || rm const-list-$(API_LEVEL).xml
3222

3323
generate-const-mapping.exe: $(CONST_MAPPER_SOURCES)
3424
$(CSCOMPILE) $(CONST_MAPPER_SOURCES)
@@ -47,28 +37,6 @@ remaining-int-consts.txt: ../../src/Mono.Android/obj/$(CONFIGURATION)/android-$(
4737
| sed -e 's/android-[0-9]*/android-XXX/' \
4838
> remaining-int-consts.txt
4939

50-
# method mappings
51-
generate-intermediary-doc-enum-mapping.exe: generate-intermediary-doc-enum-mapping.cs
52-
$(CSCOMPILE) generate-intermediary-doc-enum-mapping.cs
53-
54-
generate-enumlist-to-query.exe : generate-enumlist-to-query.cs
55-
$(CSCOMPILE) generate-enumlist-to-query.cs
56-
57-
generate-intermediary-method-mapping.exe: generate-intermediary-method-mapping.cs
58-
$(CSCOMPILE) generate-intermediary-method-mapping.cs
59-
60-
intermediary-enum-list.txt: generate-enumlist-to-query.exe
61-
mono --debug generate-enumlist-to-query.exe const-list-$(API_LEVEL).xml > intermediary-enum-list.txt || rm intermediary-enum-list.txt
62-
63-
intermediary-doc-enum-mapping.tsv: generate-intermediary-doc-enum-mapping.exe intermediary-enum-list.txt
64-
mono --debug generate-intermediary-doc-enum-mapping.exe $(DOCS_DIR)/reference intermediary-enum-list.txt > intermediary-doc-enum-mapping.tsv || rm intermediary-doc-enum-mapping.tsv
65-
66-
intermediary-method-mapping.txt: generate-intermediary-method-mapping.exe
67-
mono --debug generate-intermediary-method-mapping.exe intermediary-doc-enum-mapping.tsv const-list-$(API_LEVEL).xml $(DOCS_DIR)/reference > intermediary-method-mapping.txt || rm intermediary-method-mapping.txt
68-
69-
intermediary-field-candidates.txt: intermediary-method-mapping.txt
70-
grep "#[a-z]" intermediary-method-mapping.txt | grep -v '(' > intermediary-field-candidates.txt
71-
7240
remaining-int-methods-filtered.txt: remaining-int-methods.txt reduction_rules.txt
7341
vi remaining-int-methods.txt -s reduction_rules.txt
7442
grep "int[\[ ]" remaining-int-methods.txt > remaining-int-methods-filtered.txt
@@ -78,8 +46,6 @@ remaining-int-methods.txt: $(topdir)/src/Mono.Android/obj/$(CONFIGURATION)/andro
7846

7947
clean::
8048
-rm -rf tmp.xml const-list-$(API_LEVEL).xml \
81-
generate-const-list.exe generate-const-list.exe.mdb \
82-
generate-intermediary-enum-candidates.exe generate-intermediary-enum-candidates.exe.mdb \
49+
generate-const-list-2.exe generate-const-list-2.exe.mdb \
8350
generate-const-mapping.exe generate-const-mapping.exe.mdb \
8451
map.ext.csv intermediate-enum-candidates.xml remaining-int-consts.txt \
85-
generate-intermediary-doc-enum-mapping.exe generate-intermediary-doc-enum-mapping.exe.mdb

build-tools/enumification-helpers/enum-conversion-mappings.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,7 @@
645645
<map package="android.accessibilityservice" class="AccessibilityService" fields="" prefix="GESTURE_" enum-name="AccessibilityGesture" api-level="16" />
646646
<map package="android.accessibilityservice" class="AccessibilityService" fields="" prefix="GLOBAL_ACTION_" enum-name="GlobalAction" api-level="16" />
647647
<map package='android.app' class='Notification' fields='' prefix='PRIORITY_' enum-name="NotificationPriority" api-level="16" />
648-
<!--
649-
This had to be explicitly removed from auto-generation. see map.csv for the reason.
650-
-->
651-
<!--
652-
map package="android.content.pm" class="PackageInfo" fields="" prefix="REQUESTED_PERMISSION_" enum-name="RequestedPermission" api-level="16" / -->
648+
<map package="android.content.pm" class="PackageInfo" fields="" prefix="REQUESTED_PERMISSION_" enum-name="RequestedPermission" api-level="16" />
653649
<map package='android.media' class='MediaCodecInfo$CodecCapabilities' fields='' prefix='COLOR_' enum-name="MediaCodecCapabilities" api-level="16" />
654650
<!-- for those constants category, see http://tools.oesf.biz/android-4.1.1_r1.0/xref/frameworks/base/media/java/android/media/MediaCodecInfo.java -->
655651
<map package='android.media' class='MediaCodecInfo$CodecProfileLevel' fields='.*Level.*' enum-name="MediaCodecProfileLevel" api-level="16" />
@@ -940,7 +936,6 @@
940936
-->
941937
<map package='android.provider' class='Browser' prefix='HISTORY_PROJECTION_' enum-name='HistoryProjection' is-transient='false' />
942938
<map package='android.provider' class='Browser' prefix='SEARCHES_PROJECTION_' enum-name='SearchesProjection' is-transient='false' />
943-
<map package='android.provider' class='Browser' prefix='SEARCHES_PROJECTION_' enum-name='HistoryProjection' is-transient='false' />
944939
<map package='android.provider' class='ContactsContract.ProviderStatus' prefix='STATUS_' enum-name='ContactsProviderStatus' is-transient='false' />
945940

946941
<!-- New in API Level 24 -->
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Xml;
6+
using System.Xml.Linq;
7+
8+
9+
public class Driver
10+
{
11+
class Constant {
12+
public string Package, ParentType, Level, FieldType, Name, Value;
13+
public bool IsTypeInterface;
14+
}
15+
16+
static string GetApiLevel (string file)
17+
{
18+
Console.Error.WriteLine ($"[{file}]");
19+
return file.Substring (0, file.Length - ".xml.in".Length).Substring ("api-".Length);
20+
}
21+
22+
public static void Main (string [] args)
23+
{
24+
var docs = args.SelectMany (a => Directory.GetFiles (a, "api-*.xml.in"))
25+
.Select (file => XDocument.Load (file, LoadOptions.SetBaseUri));
26+
Dictionary<string,string> levels = docs.Select (doc => new { Doc = doc.BaseUri, File = Path.GetFileName (doc.BaseUri) })
27+
.Select (p => new { Doc = p.Doc, Level = GetApiLevel (p.File) })
28+
.ToDictionary (p => p.Doc, p => p.Level);
29+
var results = docs.Select (doc => doc.Root.Elements ("package"))
30+
.SelectMany (p => p.Elements ())
31+
.SelectMany (t => t.Elements ("field"))
32+
.Where (f => f.Attribute ("type")?.Value == "int")
33+
.Where (f => f.Attribute ("final")?.Value == "true" && f.Attribute ("value") != null)
34+
.ToArray ();
35+
var consts = results.Select (f => new Constant {
36+
Package = f.Parent.Parent.Attribute ("name").Value,
37+
ParentType = f.Parent.Attribute ("name").Value,
38+
IsTypeInterface = f.Parent.Name.LocalName == "interface",
39+
Name = f.Attribute ("name").Value,
40+
FieldType = f.Attribute ("type").Value,
41+
Value = f.Attribute ("value").Value,
42+
Level = levels [f.Document.BaseUri]
43+
})
44+
.OrderBy (c => c.Package)
45+
.ThenBy (c => c.ParentType)
46+
.ThenBy (c => c.Name)
47+
.ThenBy (c => c.Level)
48+
.ToArray ();
49+
50+
for (int i = 1; i < consts.Length; i++) {
51+
int x = 1;
52+
while (consts [i - x].Name == consts [i].Name && consts [i - x].ParentType == consts [i].ParentType && consts [i - x].Package == consts [i].Package && consts [i - x].Value != consts [i].Value) {
53+
Console.Error.WriteLine ("Overwrite field value: {0}.{1}.{2}: {3} (at {4}) -> {5} (at {6})", consts [i - x].Package, consts [i - x].ParentType, consts [i - x].Name, consts [i - x].Value, consts [i - x].Level, consts [i].Value, consts [i].Level);
54+
consts [i - x].Value = consts [i].Value;
55+
x++;
56+
}
57+
}
58+
59+
var fields = new List<string> ();
60+
string package = null, type = null;
61+
var writer = XmlWriter.Create (Console.Out, new XmlWriterSettings { Indent = true });
62+
writer.WriteStartElement ("enums");
63+
foreach (var c in consts) {
64+
if (c.Package != package) {
65+
if (package != null) {
66+
writer.WriteEndElement (); // type
67+
type = null;
68+
writer.WriteEndElement (); // package
69+
}
70+
package = c.Package;
71+
writer.WriteStartElement ("package");
72+
writer.WriteAttributeString ("name", package);
73+
}
74+
if (c.ParentType != type) {
75+
if (type != null)
76+
writer.WriteEndElement ();
77+
type = c.ParentType;
78+
writer.WriteStartElement (c.IsTypeInterface ? "interface" : "class");
79+
writer.WriteAttributeString ("name", c.ParentType);
80+
fields.Clear ();
81+
}
82+
if (fields.Contains (c.Name))
83+
continue;
84+
fields.Add (c.Name);
85+
writer.WriteStartElement ("const");
86+
writer.WriteAttributeString ("type", c.FieldType);
87+
writer.WriteAttributeString ("name", c.Name);
88+
writer.WriteAttributeString ("api-level", c.Level);
89+
writer.WriteString (c.Value);
90+
writer.WriteEndElement ();
91+
}
92+
writer.Close ();
93+
}
94+
}

build-tools/enumification-helpers/generate-const-list.cs

Lines changed: 0 additions & 161 deletions
This file was deleted.

src/Mono.Android/Android.Content.PM/PackageInfo.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Mono.Android/Mono.Android.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@
147147
<Compile Include="Android.Content\CursorLoader.cs" />
148148
<Compile Include="Android.Content\GrantUriPermissionAttribute.cs" />
149149
<Compile Include="Android.Content\Intent.cs" />
150-
<Compile Include="Android.Content.PM\PackageInfo.cs" />
151150
<Compile Include="Android.Content.Res\IXmlResourceParser.cs" />
152151
<Compile Include="Android.Graphics\AndroidBitmapInfo.cs" />
153152
<Compile Include="Android.Graphics\Bitmap.cs" />

0 commit comments

Comments
 (0)