Skip to content

Commit

Permalink
Merge pull request #1045 from atsushieno/api-level-27-enumification
Browse files Browse the repository at this point in the history
API-27 Enumification for `Mono.Android.dll`.
  • Loading branch information
jonpryor authored Dec 3, 2017
2 parents 32db18c + 914f95f commit 9a73c4c
Show file tree
Hide file tree
Showing 12 changed files with 3,036 additions and 3,090 deletions.
48 changes: 7 additions & 41 deletions build-tools/enumification-helpers/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
topdir = ../..

API_LEVEL = 26
API_LEVEL_NAME = 26
API_LEVEL = 27
API_LEVEL_NAME = 27

CSCOMPILE = csc -debug:portable

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

CONST_MAPPER_SOURCES = \
generate-const-mapping.cs \
Expand All @@ -15,20 +14,11 @@ CONST_MAPPER_SOURCES = \

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

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

generate-const-list.exe: generate-const-list.cs
$(CSCOMPILE) generate-const-list.cs

const-list-$(API_LEVEL).xml: generate-const-list.exe
mono --debug generate-const-list.exe $(DOCS_DIR)/reference/ -v > const-list-$(API_LEVEL).xml || rm const-list-$(API_LEVEL).xml

generate-intermediary-enum-candidates.exe : generate-intermediary-enum-candidates.cs
$(CSCOMPILE) generate-intermediary-enum-candidates.cs

#it is obsolete
intermediary-enum-candidates.xml: generate-intermediary-enum-candidates.exe
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
const-list-$(API_LEVEL).xml: generate-const-list-2.exe ../../src/Mono.Android/Profiles/*.xml.in
mono --debug generate-const-list-2.exe ../../src/Mono.Android/Profiles > const-list-$(API_LEVEL).xml || rm const-list-$(API_LEVEL).xml

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

# method mappings
generate-intermediary-doc-enum-mapping.exe: generate-intermediary-doc-enum-mapping.cs
$(CSCOMPILE) generate-intermediary-doc-enum-mapping.cs

generate-enumlist-to-query.exe : generate-enumlist-to-query.cs
$(CSCOMPILE) generate-enumlist-to-query.cs

generate-intermediary-method-mapping.exe: generate-intermediary-method-mapping.cs
$(CSCOMPILE) generate-intermediary-method-mapping.cs

intermediary-enum-list.txt: generate-enumlist-to-query.exe
mono --debug generate-enumlist-to-query.exe const-list-$(API_LEVEL).xml > intermediary-enum-list.txt || rm intermediary-enum-list.txt

intermediary-doc-enum-mapping.tsv: generate-intermediary-doc-enum-mapping.exe intermediary-enum-list.txt
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

intermediary-method-mapping.txt: generate-intermediary-method-mapping.exe
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

intermediary-field-candidates.txt: intermediary-method-mapping.txt
grep "#[a-z]" intermediary-method-mapping.txt | grep -v '(' > intermediary-field-candidates.txt

remaining-int-methods-filtered.txt: remaining-int-methods.txt reduction_rules.txt
vi remaining-int-methods.txt -s reduction_rules.txt
grep "int[\[ ]" remaining-int-methods.txt > remaining-int-methods-filtered.txt
Expand All @@ -78,8 +46,6 @@ remaining-int-methods.txt: $(topdir)/src/Mono.Android/obj/$(CONFIGURATION)/andro

clean::
-rm -rf tmp.xml const-list-$(API_LEVEL).xml \
generate-const-list.exe generate-const-list.exe.mdb \
generate-intermediary-enum-candidates.exe generate-intermediary-enum-candidates.exe.mdb \
generate-const-list-2.exe generate-const-list-2.exe.mdb \
generate-const-mapping.exe generate-const-mapping.exe.mdb \
map.ext.csv intermediate-enum-candidates.xml remaining-int-consts.txt \
generate-intermediary-doc-enum-mapping.exe generate-intermediary-doc-enum-mapping.exe.mdb
11 changes: 4 additions & 7 deletions build-tools/enumification-helpers/enum-conversion-mappings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@
<map package='android.view.accessibility' class='AccessibilityNodeInfo' fields='' prefix='MOVEMENT_GRANULARITY_' enum-name="MovementGranularity" api-level='16' />
<map package='android.view.accessibility' class='AccessibilityNodeInfo.CollectionInfo' fields='' prefix='SELECTION_MODE_' enum-name="SelectionMode" api-level='21' />
<map package='android.view.accessibility' class='AccessibilityNodeInfo.RangeInfo' fields='' prefix='RANGE_TYPE_' enum-name="RangeType" />
<map package='android.view.accessibility' class='AccessibilityRequestPreparer' prefix='REQUEST_TYPE_' enum-name="AccessibilityRequestTypes" api-level="27" />
<map package='android.view.accessibility' class='AccessibilityWindowInfo' fields='' prefix='TYPE_' enum-name="AccessibilityWindowType" api-level="21" />
<map package='android.view.accessibility' class='CaptioningManager.CaptionStyle' fields='' prefix='EDGE_TYPE_' enum-name="CaptionStyles" />
<map package='android.view' class='Gravity' fields='*' prefix='' enum-name="GravityFlags" is-transient="false" />
Expand Down Expand Up @@ -645,11 +646,7 @@
<map package="android.accessibilityservice" class="AccessibilityService" fields="" prefix="GESTURE_" enum-name="AccessibilityGesture" api-level="16" />
<map package="android.accessibilityservice" class="AccessibilityService" fields="" prefix="GLOBAL_ACTION_" enum-name="GlobalAction" api-level="16" />
<map package='android.app' class='Notification' fields='' prefix='PRIORITY_' enum-name="NotificationPriority" api-level="16" />
<!--
This had to be explicitly removed from auto-generation. see map.csv for the reason.
-->
<!--
map package="android.content.pm" class="PackageInfo" fields="" prefix="REQUESTED_PERMISSION_" enum-name="RequestedPermission" api-level="16" / -->
<map package="android.content.pm" class="PackageInfo" fields="" prefix="REQUESTED_PERMISSION_" enum-name="RequestedPermission" api-level="16" />
<map package='android.media' class='MediaCodecInfo$CodecCapabilities' fields='' prefix='COLOR_' enum-name="MediaCodecCapabilities" api-level="16" />
<!-- for those constants category, see http://tools.oesf.biz/android-4.1.1_r1.0/xref/frameworks/base/media/java/android/media/MediaCodecInfo.java -->
<map package='android.media' class='MediaCodecInfo$CodecProfileLevel' fields='.*Level.*' enum-name="MediaCodecProfileLevel" api-level="16" />
Expand Down Expand Up @@ -803,7 +800,7 @@
<field java='ACTION_DROP' managed='Drop' />
</map>
<map package='android.view' class='DragEvent' prefix='ACTION_DRAG_' enum-name='DragAction' is-transient='false' />
<map package='android.view' class='HapticFeedbackConstants' fields='CLOCK_TICK CONTEXT_CLICK KEYBOARD_TAP LONG_PRESS VIRTUAL_KEY' enum-name='FeedbackConstants' is-transient='true' />
<map package='android.view' class='HapticFeedbackConstants' fields='CLOCK_TICK CONTEXT_CLICK KEYBOARD_PRESS KEYBOARD_RELEASE KEYBOARD_TAP LONG_PRESS VIRTUAL_KEY TEXT_HANDLE_MOVE VIRTUAL_KEY_RELEASE' enum-name='FeedbackConstants' is-transient='true' />
<map package='android.view' class='HapticFeedbackConstants' prefix='FLAG_' enum-name='FeedbackFlags' is-transient='true' />
<map package='android.view' class='KeyCharacterMap' fields='ALPHA BUILT_IN_KEYBOARD FULL NUMERIC PREDICTIVE SPECIAL_FUNCTION VIRTUAL_KEYBOARD' enum-name='KeyboardType' is-transient='false' />
<map package='android.view' class='KeyCharacterMap' prefix='MODIFIER_BEHAVIOR_' enum-name='KeyModifierBehavior' is-transient='false' />
Expand Down Expand Up @@ -844,6 +841,7 @@
<map package='android.webkit' class='WebView' prefix='RENDERER_PRIORITY_' enum-name='RendererPriority' is-transient='false' />
<map package='android.webkit' class='WebView.HitTestResult' fields='*' enum-name='HitTestResult' is-transient='false' />
<map package='android.webkit' class='WebViewClient' prefix='ERROR_' enum-name='ClientError' is-transient='false' />
<map package='android.webkit' class='WebViewClient' prefix='SAFE_BROWSING_THREAT_' enum-name='SafeBrowsingThreat' is-transient='false' />
<map package='android.widget' class='AbsListView' prefix='CHOICE_MODE_' enum-name='ChoiceMode' is-transient='false' />
<map package='android.widget' class='AbsListView' prefix='TRANSCRIPT_MODE_' enum-name='TranscriptMode' is-transient='false' />
<map package='android.widget' class='AdapterView' prefix='ITEM_VIEW_TYPE_' enum-name='ItemViewType' is-transient='false' />
Expand Down Expand Up @@ -940,7 +938,6 @@
-->
<map package='android.provider' class='Browser' prefix='HISTORY_PROJECTION_' enum-name='HistoryProjection' is-transient='false' />
<map package='android.provider' class='Browser' prefix='SEARCHES_PROJECTION_' enum-name='SearchesProjection' is-transient='false' />
<map package='android.provider' class='Browser' prefix='SEARCHES_PROJECTION_' enum-name='HistoryProjection' is-transient='false' />
<map package='android.provider' class='ContactsContract.ProviderStatus' prefix='STATUS_' enum-name='ContactsProviderStatus' is-transient='false' />

<!-- New in API Level 24 -->
Expand Down
94 changes: 94 additions & 0 deletions build-tools/enumification-helpers/generate-const-list-2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;


public class Driver
{
class Constant {
public string Package, ParentType, Level, FieldType, Name, Value;
public bool IsTypeInterface;
}

static string GetApiLevel (string file)
{
Console.Error.WriteLine ($"[{file}]");
return file.Substring (0, file.Length - ".xml.in".Length).Substring ("api-".Length);
}

public static void Main (string [] args)
{
var docs = args.SelectMany (a => Directory.GetFiles (a, "api-*.xml.in"))
.Select (file => XDocument.Load (file, LoadOptions.SetBaseUri));
Dictionary<string,string> levels = docs.Select (doc => new { Doc = doc.BaseUri, File = Path.GetFileName (doc.BaseUri) })
.Select (p => new { Doc = p.Doc, Level = GetApiLevel (p.File) })
.ToDictionary (p => p.Doc, p => p.Level);
var results = docs.Select (doc => doc.Root.Elements ("package"))
.SelectMany (p => p.Elements ())
.SelectMany (t => t.Elements ("field"))
.Where (f => f.Attribute ("type")?.Value == "int")
.Where (f => f.Attribute ("final")?.Value == "true" && f.Attribute ("value") != null)
.ToArray ();
var consts = results.Select (f => new Constant {
Package = f.Parent.Parent.Attribute ("name").Value,
ParentType = f.Parent.Attribute ("name").Value,
IsTypeInterface = f.Parent.Name.LocalName == "interface",
Name = f.Attribute ("name").Value,
FieldType = f.Attribute ("type").Value,
Value = f.Attribute ("value").Value,
Level = levels [f.Document.BaseUri]
})
.OrderBy (c => c.Package)
.ThenBy (c => c.ParentType)
.ThenBy (c => c.Name)
.ThenBy (c => c.Level)
.ToArray ();

for (int i = 1; i < consts.Length; i++) {
int x = 1;
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) {
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);
consts [i - x].Value = consts [i].Value;
x++;
}
}

var fields = new List<string> ();
string package = null, type = null;
var writer = XmlWriter.Create (Console.Out, new XmlWriterSettings { Indent = true });
writer.WriteStartElement ("enums");
foreach (var c in consts) {
if (c.Package != package) {
if (package != null) {
writer.WriteEndElement (); // type
type = null;
writer.WriteEndElement (); // package
}
package = c.Package;
writer.WriteStartElement ("package");
writer.WriteAttributeString ("name", package);
}
if (c.ParentType != type) {
if (type != null)
writer.WriteEndElement ();
type = c.ParentType;
writer.WriteStartElement (c.IsTypeInterface ? "interface" : "class");
writer.WriteAttributeString ("name", c.ParentType);
fields.Clear ();
}
if (fields.Contains (c.Name))
continue;
fields.Add (c.Name);
writer.WriteStartElement ("const");
writer.WriteAttributeString ("type", c.FieldType);
writer.WriteAttributeString ("name", c.Name);
writer.WriteAttributeString ("api-level", c.Level);
writer.WriteString (c.Value);
writer.WriteEndElement ();
}
writer.Close ();
}
}
161 changes: 0 additions & 161 deletions build-tools/enumification-helpers/generate-const-list.cs

This file was deleted.

Loading

0 comments on commit 9a73c4c

Please sign in to comment.