-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
4e0dacb
commit a301764
Showing
7 changed files
with
2,966 additions
and
3,069 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
build-tools/enumification-helpers/generate-const-list-2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
161
build-tools/enumification-helpers/generate-const-list.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.