Skip to content

Commit f22cf11

Browse files
committed
feature of v7.0.0 - see CHANGES.md
1 parent b484389 commit f22cf11

File tree

8 files changed

+71
-67
lines changed

8 files changed

+71
-67
lines changed

CHANGES.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
## Changelogs
22
we use [Semantic Versioning](http://semver.org/)
33

4+
#### 7.0.0
5+
+ Not use tink_syntaxhub to reduce compile time ~3 times
6+
(in our large project, compile time is reduced from 40s to 10s)
7+
8+
+ revert syntax as in version 5.x:
9+
10+
regex replace from:
11+
`@:tinyui\((['"][^)]+)`
12+
to:
13+
`@:build(TinyUI.build($1)`
14+
15+
+ rename & change `TinyUI.saveCodeTo` to `TinyUI.init` for better meaning.
16+
17+
+ use `-D tinyui-use-gen-code` flag instead of argument `useGeneratedCode` of `TinyUI.saveCodeTo` method
18+
see document of `TinyUI.init` for more detail.
19+
420
#### 6.0.1
521
+ better error logging
622

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,14 @@ haxelib install tinyui
244244
245245
4. (optional) save generated code
246246
```xml
247-
<haxeflag name="--macro" value="TinyUI.saveCodeTo('ui-codegen')"/>
247+
<haxeflag name="--macro" value="TinyUI.init('ui-codegen')"/>
248248
```
249249
250250
5. you can use the generated code (bypass the whole tinyui macro building)
251-
by passing `useGeneratedCode = true` to `TinyUI.saveCodeTo` method:
251+
by set `tinyui-use-gen-code` flag:
252252
```xml
253-
<haxeflag name="--macro" value="TinyUI.saveCodeTo('ui-codegen', null, true)"/>
253+
<!--uncomment to bypass TinyUI.build & using the generated code-->
254+
<haxeflag name="-D tinyui-use-gen-code"/>
254255
```
255256
256257
6. see [example](http://tinyui.sandinh.com)

example/example.hxproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,24 @@
1717
<!-- Other classes to be compiled into your SWF -->
1818
<classpaths>
1919
<class path="C:\HaxeToolkit\haxe\lib\tinyui\git\main\src" />
20-
<class path="C:\HaxeToolkit\haxe\lib\tink_syntaxhub\0,3,0\src" />
2120
<class path="C:\HaxeToolkit\haxe\lib\tink_macro\0,6,4\src" />
2221
<class path="C:\HaxeToolkit\haxe\lib\tink_core\1,0,0-rc,11\src" />
23-
<class path="C:\HaxeToolkit\haxe\lib\tink_priority\0,1,2\src" />
2422
<class path="C:\HaxeToolkit\haxe\lib\openfl-tooltip\git\src" />
25-
<class path="C:\HaxeToolkit\haxe\lib\openfl\3,0,8" />
26-
<class path="C:\HaxeToolkit\haxe\lib\lime\2,4,3" />
23+
<class path="C:\HaxeToolkit\haxe\lib\openfl\3,1,0" />
24+
<class path="C:\HaxeToolkit\haxe\lib\lime\2,4,4" />
2725
<class path="C:\HaxeToolkit\haxe\lib\actuate\1,8,6" />
2826
<class path="C:\HaxeToolkit\haxe\lib\advanced-layout\git" />
2927
<class path="src" />
30-
<class path="bin\flash\haxe" />
28+
<class path="bin\html5\haxe" />
3129
</classpaths>
3230
<!-- Build options -->
3331
<build>
34-
<option directives="tinyui=0.0.0&#xA;tink_syntaxhub=0.3.0&#xA;tink_macro=0.6.4&#xA;tink_core=1.0.0-rc.11&#xA;tink_priority=0.1.2&#xA;openfl-tooltip=0.0.0&#xA;openfl=3.0.8&#xA;lime=2.4.3&#xA;actuate=1.8.6&#xA;advanced-layout=0.4.1&#xA;openfl-next&#xA;tools=2.4.3&#xA;no-compilation&#xA;openfl-flash&#xA;web" />
32+
<option directives="tinyui=0.0.0&#xA;tink_macro=0.6.4&#xA;tink_core=1.0.0-rc.11&#xA;openfl-tooltip=0.0.0&#xA;openfl=3.1.0&#xA;lime=2.4.4&#xA;actuate=1.8.6&#xA;advanced-layout=0.4.1&#xA;openfl-next&#xA;tools=2.4.4&#xA;no-compilation&#xA;openfl-html5&#xA;canvas&#xA;lime-html5&#xA;html5&#xA;web&#xA;tinyui-use-gen-code&#xA;html5" />
3533
<option flashStrict="False" />
3634
<option noInlineOnDebug="False" />
3735
<option mainClass="ApplicationMain" />
3836
<option enabledebug="True" />
39-
<option additional="--macro tink.SyntaxHub.use()&#xA;--macro TinyUI.saveCodeTo('ui-codegen', ['ui-src'])&#xA;-swf-version 11.2&#xA;-debug " />
37+
<option additional="--remap flash:openfl&#xA;--macro TinyUI.init('ui-codegen', ['ui-src'], 'com.sandinh')&#xA;--macro allowPackage(&quot;flash&quot;)" />
4038
</build>
4139
<!-- haxelib libraries -->
4240
<haxelib>

example/example.iml

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@
5858
</SOURCES>
5959
</library>
6060
</orderEntry>
61-
<orderEntry type="module-library">
62-
<library name="haxelib|C:/HaxeToolkit/haxe/lib/openfl/3,0,8">
63-
<CLASSES>
64-
<root url="file://$MODULE_DIR$/../../../openfl/3,0,8" />
65-
</CLASSES>
66-
<JAVADOC />
67-
<SOURCES>
68-
<root url="file://$MODULE_DIR$/../../../openfl/3,0,8" />
69-
</SOURCES>
70-
</library>
71-
</orderEntry>
7261
<orderEntry type="module-library">
7362
<library name="haxelib|C:/HaxeToolkit/haxe/lib/tink_macro/0,6,4/src">
7463
<CLASSES>
@@ -92,24 +81,13 @@
9281
</library>
9382
</orderEntry>
9483
<orderEntry type="module-library">
95-
<library name="haxelib|C:/HaxeToolkit/haxe/lib/tink_syntaxhub/0,3,0/src">
96-
<CLASSES>
97-
<root url="file://$MODULE_DIR$/../../../tink_syntaxhub/0,3,0/src" />
98-
</CLASSES>
99-
<JAVADOC />
100-
<SOURCES>
101-
<root url="file://$MODULE_DIR$/../../../tink_syntaxhub/0,3,0/src" />
102-
</SOURCES>
103-
</library>
104-
</orderEntry>
105-
<orderEntry type="module-library">
106-
<library name="haxelib|C:/HaxeToolkit/haxe/lib/tink_priority/0,1,2/src">
84+
<library name="haxelib|C:/HaxeToolkit/haxe/lib/openfl/3,1,0">
10785
<CLASSES>
108-
<root url="file://$MODULE_DIR$/../../../tink_priority/0,1,2/src" />
86+
<root url="file://$MODULE_DIR$/../../../openfl/3,1,0" />
10987
</CLASSES>
11088
<JAVADOC />
11189
<SOURCES>
112-
<root url="file://$MODULE_DIR$/../../../tink_priority/0,1,2/src" />
90+
<root url="file://$MODULE_DIR$/../../../openfl/3,1,0" />
11391
</SOURCES>
11492
</library>
11593
</orderEntry>

example/project.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<!-- classpath, haxe libs -->
1616
<source path="src" />
1717
<haxelib name="tinyui" />
18-
<haxelib name="tink_syntaxhub" />
18+
<haxelib name="tink_macro" />
1919
<haxelib name="openfl-tooltip" />
2020
<haxelib name="openfl" />
2121
<haxelib name="actuate" />
@@ -27,7 +27,7 @@
2727
<!-- optimize output
2828
<haxeflag name="-dce full" /> -->
2929

30-
<!--switch the following configs for normal build or bypass TinyUI.build & using the generated code-->
31-
<haxeflag name="--macro" value="TinyUI.saveCodeTo('ui-codegen', ['ui-src'])"/>
32-
<!--<haxeflag name="&#45;&#45;macro" value="TinyUI.saveCodeTo('ui-codegen', ['ui-src'], true)"/>-->
30+
<!--uncomment to bypass TinyUI.build & using the generated code-->
31+
<!--<haxeflag name="-D tinyui-use-gen-code"/>-->
32+
<haxeflag name="--macro" value="TinyUI.init('ui-codegen', ['ui-src'], 'com.sandinh')"/>
3333
</project>

haxelib.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"license" : "MIT",
55
"tags" : ["cross", "openfl", "flash", "html5", "cpp", "ui", "macro", "layout"],
66
"description" : "A tiny UI macro for injecting ui items declared in a xml file into a haxe class.",
7-
"version" : "6.0.1",
7+
"version" : "7.0.0",
88
"releasenote" : "see CHANGES.md",
99
"classPath" : "main/src",
1010
"contributors" : ["SanDinh.com"],
1111
"dependencies" : {
1212
"openfl" : "",
13-
"tink_syntaxhub" : ""
13+
"tink_macro" : ""
1414
}
1515
}

main/src/TinyUI.hx

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#if macro
22
import tink.macro.ClassBuilder;
3-
import tink.SyntaxHub;
43
import haxe.macro.Compiler;
54
import haxe.macro.Type;
65
import haxe.macro.Printer;
@@ -28,47 +27,55 @@ class TinyUI {
2827
* @param genCodeDir - the directory to save generated code to.
2928
* @param uiSrcDirs - array of source dir contains only .hx view files
3029
* need to be built using @:build(TinyUI.build(<the-xml-file>)).
31-
* @param useGeneratedCode -
32-
* = false (default) for normal @build. uiSrcDirs will be add to class path (Compiler.addClassPath)
33-
* = true to bypass TinyUI.build function.
30+
* @param genTypePrefix TinyUI will gen haxe type from xml file only if type (include package name)
31+
* is prefixed with this argument.
32+
* You should use this feature in large projects to reduce the compile time.
33+
* In our project, set genTypePrefix="com.sandinh.ui" reduce compile time from 30s to 10s!
34+
*
35+
* config tinyui_use_gen_code -
36+
* unset (default) for normal @build. uiSrcDirs will be add to class path (Compiler.addClassPath)
37+
* set (by add: -D tinyui-use-gen-code) to bypass TinyUI.build function.
3438
* We will use the generated code when compiling: Compiler.addClassPath(genCodeDir)
3539
*
3640
* usage, ex with openfl: add to using openfl project.xml file:
3741
* ```xml
38-
* <!--switch the following configs for normal build or bypass TinyUI.build & using the generated code-->
39-
* <haxeflag name="--macro" value="TinyUI.saveCodeTo('ui-codegen', ['ui-src'])"/>
40-
* <!--<haxeflag name="&#45;&#45;macro" value="TinyUI.saveCodeTo('ui-codegen', ['ui-src'], true)"/>-->
42+
* <!--uncomment to bypass TinyUI.build & using the generated code-->
43+
* <haxeflag name="-D tinyui-use-gen-code"/>
44+
* <haxeflag name="--macro" value="TinyUI.init('ui-codegen', ['ui-src'], 'com.sandinh')"/>
4145
* ``` */
42-
public static function saveCodeTo(genCodeDir: String,
43-
uiSrcDirs: Array<String> = null,
44-
useGeneratedCode: Bool = false): Void {
45-
if (useGeneratedCode) {
46+
public static function init(genCodeDir: String,
47+
uiSrcDirs: Array<String> = null,
48+
genTypePrefix: String = ""): Void {
49+
#if tinyui_use_gen_code
4650
Compiler.addClassPath(genCodeDir);
47-
} else {
51+
#else
4852
TinyUI.genCodeDir = genCodeDir.endsWith("/")? genCodeDir : genCodeDir + "/";
4953
if (uiSrcDirs != null) {
5054
uiSrcDirs.iter(Compiler.addClassPath);
5155
}
5256

5357
genCodeDir.delDirRecursive();
5458

55-
TinyUIPlugin.init();
56-
SyntaxHub.classLevel.whenever(build);
57-
}
59+
TinyUIPlugin.init(genTypePrefix);
60+
#end
5861
}
5962

60-
/** Inject fields declared in `xmlFile` and generate `initUI()` function for the macro building class. */
61-
static function build(builder: ClassBuilder): Bool return
62-
try switch builder.target.meta.extract(":tinyui") {
63-
case []: false;
64-
case uiMetas:
65-
var xmlFile: String = uiMetas[0].params[0].getValue();
63+
static function build(xmlFile: String): Array<Field> {
64+
#if tinyui_use_gen_code
65+
return null;
66+
#else
67+
return try switch Context.getLocalType() {
68+
case TInst(_.get() => c, _):
69+
var builder = new ClassBuilder(c);
6670
new TinyUI(xmlFile, builder).doBuild();
67-
true;
71+
builder.export(builder.target.meta.has(':explain'));
72+
default: null;
6873
} catch(e: Dynamic) {
6974
println('ERROR! tinyui build failed: $e\n' + CallStack.toString(CallStack.exceptionStack()));
70-
false;
75+
null;
7176
}
77+
#end
78+
}
7279

7380
/** Position point to the xml file. we store this in a class var for convenient */
7481
var xmlPos: Position;
@@ -621,7 +628,7 @@ class TinyUI {
621628

622629
//2. Get content of building file. We will save this content and the generated fields to the saveFile
623630
inline function getContent(): String {
624-
//genCodeDir is delete in method `saveCodeTo`.
631+
//genCodeDir is delete in method `init`.
625632
//saveFile exist here when it contain multiple building class
626633
var file = FileSystem.exists(saveFile)?
627634
saveFile : builder.target.pos.getInfos().file;

main/src/_tinyui/TinyUIPlugin.hx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@ class TinyUIPlugin {
2121
* 2. return an alias to the impl class. */
2222
static inline var prebuildCodeDir = "bin/tinyui/";
2323
static inline var GenSuffix = "_ui_gen";
24+
static var genTypePrefix: String;
2425

2526
public static inline function isGenSuffix(s: String) return s.endsWith(GenSuffix);
2627
public static function removeGenSuffix(s: String) {
2728
return isGenSuffix(s)? s.substr(0, s.length - GenSuffix.length) : s;
2829
}
2930

3031
/* delete the prebuildCodeDir dir and register Context.onTypeNotFound */
31-
public static function init() {
32+
public static function init(genTypePrefix: String) {
3233
Compiler.addClassPath(prebuildCodeDir);
3334
prebuildCodeDir.delDirRecursive();
3435
Context.onTypeNotFound(onTypeNotFound);
36+
TinyUIPlugin.genTypePrefix = genTypePrefix;
3537
}
3638

3739
/** @param name the not-found-type, ex "foo.Bar" */
3840
static function onTypeNotFound(name: String): TypeDefinition {
41+
if (! name.startsWith(genTypePrefix)) return null;
42+
3943
var ctx = name.asTypePath();
4044
//Note: if we define the impl class named "foo.__impl.Bar" as in tink.syntaxhub.FrontendContext:
4145
//var actual = {name: ctx.name, pack: ctx.pack.concat(['__impl'])};
@@ -87,7 +91,7 @@ class TinyUIPlugin {
8791
code += "\n";
8892
xml.elementsNamed("using").iter(addImport);
8993

90-
code += '\n@:tinyui("$xmlFile")\n';
94+
code += '\n@:build(TinyUI.build("$xmlFile"))\n';
9195
code += "class " + ctx.name + " extends " + xml.nodeName + " {\n}\n";
9296

9397
File.saveContent(hxFile(), code);

0 commit comments

Comments
 (0)