1
1
package hxmake .macr ;
2
2
3
- import hxmake .cli .MakeLog ;
4
- import haxe .macro .Expr .Access ;
5
- import sys .FileSystem ;
6
3
import haxe .io .Path ;
7
- import haxe .macro .Type ;
8
4
import haxe .macro .Context ;
5
+ import haxe .macro .Expr .Access ;
9
6
import haxe .macro .Expr ;
7
+ import haxe .macro .Type ;
8
+ import sys .FileSystem ;
10
9
11
10
using StringTools ;
12
11
@@ -20,42 +19,44 @@ class ModuleMacro {
20
19
var modulePath = getModulePath (Context .getLocalModule ());
21
20
var childrenExprs : Array <Expr > = [];
22
21
23
- MakeLog . trace (modulePath );
22
+ CompileTime . log (modulePath );
24
23
var changedModulePath : Array <String > = MacroHelper .extractMetaStrings (cls .meta , " :module_path" );
25
- if (changedModulePath .length > 0 ) {
24
+ if (changedModulePath .length > 0 ) {
26
25
var parentPath = modulePath ;
27
26
modulePath = FileSystem .absolutePath (Path .join ([modulePath , changedModulePath [0 ]]));
28
- MakeLog . trace (" CHANGED TO: " + modulePath );
27
+ CompileTime . log (" CHANGED TO: " + modulePath );
29
28
// childrenExprs.push(macro hxmake.core.CompiledProjectData.createModuleConnection($v{modulePath}, $v{childModulePath}));
30
29
}
31
30
32
31
var guessModuleName = modulePath .split (" /" ).pop ();
33
32
34
33
var includes : Array <String > = MacroHelper .extractMetaStrings (cls .meta , " :include" );
35
- for (include in includes ) {
34
+ for (include in includes ) {
36
35
var childModulePath = FileSystem .absolutePath (Path .join ([modulePath , include ]));
37
- if (! FileSystem .exists (childModulePath )) {
38
- MakeLog .warning (' Path is not found for include " $include "' );
36
+ if (! FileSystem .exists (childModulePath )) {
37
+ // TODO: pos of meta
38
+ Context .warning (' Path is not found for include " $include "' , pos );
39
39
continue ;
40
40
}
41
41
42
42
var cp = Path .join ([childModulePath , " make" ]);
43
- if (FileSystem .exists (cp )) {
43
+ if (FileSystem .exists (cp )) {
44
44
PluginInclude .scan (cp );
45
45
CompileTime .addMakePath (cp );
46
46
}
47
47
else {
48
- MakeLog .warning (' Make directory is not found for module " $include "' );
48
+ // TODO: pos of meta
49
+ Context .warning (' Make directory is not found for module " $include "' , pos );
49
50
}
50
51
51
52
childrenExprs .push (macro hxmake.core. CompiledProjectData .createModuleConnection ($v {modulePath }, $v {childModulePath }));
52
53
}
53
54
54
55
processMakeLibraries (" :lib" , cls .meta );
55
56
56
- if (! cls .meta .has (" :root" )) {
57
+ if (! cls .meta .has (" :root" )) {
57
58
var parentMakeDir = FileSystem .absolutePath (Path .join ([modulePath , " .." , " make" ]));
58
- if (FileSystem .exists (parentMakeDir ) && FileSystem .isDirectory (parentMakeDir )) {
59
+ if (FileSystem .exists (parentMakeDir ) && FileSystem .isDirectory (parentMakeDir )) {
59
60
PluginInclude .scan (parentMakeDir );
60
61
CompileTime .addMakePath (parentMakeDir );
61
62
}
@@ -67,13 +68,13 @@ class ModuleMacro {
67
68
};
68
69
69
70
fields .push (MacroHelper .makeInitField (macro {
70
- var module = @:privateAccess new $tp ();
71
- if (module .name == null ) {
72
- module .name = $v {guessModuleName };
73
- }
74
- module .path = $v {modulePath };
75
- hxmake.core. CompiledProjectData .registerModule (module );
76
- $b {childrenExprs }
71
+ var module = @:privateAccess new $tp ();
72
+ if (module .name == null ) {
73
+ module .name = $v {guessModuleName };
74
+ }
75
+ module .path = $v {modulePath };
76
+ hxmake.core. CompiledProjectData .registerModule (module );
77
+ $b {childrenExprs }
77
78
}, pos ));
78
79
79
80
transformConstructor (fields );
@@ -83,11 +84,11 @@ class ModuleMacro {
83
84
84
85
static function processMakeLibraries (libraryMeta : String , metaAccess : MetaAccess ) {
85
86
var metaList : Array <MetadataEntry > = metaAccess .extract (libraryMeta );
86
- for (meta in metaList ) {
87
- if (meta .params .length > 0 ) {
87
+ for (meta in metaList ) {
88
+ if (meta .params .length > 0 ) {
88
89
var libName = exprGetStringConst (meta .params [0 ]);
89
90
var libPath = exprGetStringConst (meta .params [1 ]);
90
- if (libName == null ) {
91
+ if (libName == null ) {
91
92
throw ' @ $libraryMeta first argument need to be String literal' ;
92
93
}
93
94
PluginInclude .include (libName , libPath );
@@ -99,7 +100,7 @@ class ModuleMacro {
99
100
}
100
101
101
102
static function exprGetStringConst (expr : Expr ): Null <String > {
102
- if (expr == null ) {
103
+ if (expr == null ) {
103
104
return null ;
104
105
}
105
106
return switch (expr .expr ) {
@@ -113,8 +114,8 @@ class ModuleMacro {
113
114
}
114
115
115
116
static function transformConstructor (fields : Array <Field >) {
116
- for (field in fields ) {
117
- if (field .name == " new" ) {
117
+ for (field in fields ) {
118
+ if (field .name == " new" ) {
118
119
field .name = " __initialize" ;
119
120
field .access = [Access . AOverride ];
120
121
// TODO: add more validation at Compile-time
0 commit comments