Skip to content

Commit e7ae7cf

Browse files
committed
--macrolog option (shows messages from make compile time)
1 parent 2db245c commit e7ae7cf

File tree

10 files changed

+73
-61
lines changed

10 files changed

+73
-61
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- `Task.empty(name, desc)` creates empty task
55
- Prints property-map on start
66
- Flash Player trust location PER USER for macOS and Windows
7+
- `--macrolog` enabled traces from compile-time
78

89
# v0.1.6
910

run.n

-22 Bytes
Binary file not shown.

src/hxmake/Project.hx

+8-4
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ class Project {
4040
var _moduleGraph:ModuleGraph;
4141

4242
function new(buildArguments:Array<String>, isCompiler:Bool) {
43-
MakeLog.initialize(buildArguments);
43+
args = isCompiler ? buildArguments : buildArguments.concat(Sys.args());
44+
properties = parsePropertyMap(args);
45+
46+
MakeLog.initialize(hasProperty("--silent"), hasProperty("--verbose"));
4447

4548
if (isCompiler) {
4649
MakeLog.trace("[MakeProject] Compiler mode");
4750
}
4851

49-
args = isCompiler ? buildArguments : buildArguments.concat(Sys.args());
50-
properties = parsePropertyMap(args);
51-
5252
_moduleGraph = @:privateAccess new ModuleGraph();
5353
_taskGraph = @:privateAccess new TaskGraph(args, _moduleGraph.modules);
5454
}
@@ -67,6 +67,10 @@ class Project {
6767
return properties.exists(name) ? properties.get(name) : null;
6868
}
6969

70+
public function hasProperty(name:String):Bool {
71+
return property(name) != null;
72+
}
73+
7074
function run() {
7175
var startTime = Timer.stamp();
7276

src/hxmake/cli/MakeLog.hx

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import hxmake.cli.logging.LogLevel;
88
@:final
99
class MakeLog {
1010

11-
public static var logger(default, null):Logger = new Logger();
11+
public static var logger(default, null):Logger;
1212

1313
public inline static function trace(message:Dynamic, ?position:PosInfos) {
1414
logger.trace(message, position);
@@ -30,13 +30,11 @@ class MakeLog {
3030
logger.error(message, position);
3131
}
3232

33-
public static function initialize(args:Array<String>) {
34-
if(args.indexOf("--silent") >= 0) {
35-
logger.setFilter(LogLevel.FILTER_SILENT);
36-
}
37-
else if(args.indexOf("--verbose") >= 0) {
38-
logger.setFilter(LogLevel.FILTER_VERBOSE);
39-
}
33+
public static function initialize(silent:Bool, verbose:Bool) {
34+
var filter = LogLevel.FILTER_STD;
35+
if(verbose) filter = LogLevel.FILTER_VERBOSE;
36+
if(silent) filter = LogLevel.FILTER_SILENT;
37+
logger = new Logger(filter);
4038
Log.trace = onHaxeTrace;
4139
}
4240

src/hxmake/cli/logging/Logger.hx

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ import haxe.PosInfos;
44

55
class Logger {
66

7-
public static var current(default, null):Logger = new Logger();
8-
97
var _filter:Int;
108
var _colors:Array<AnsiColor> = [];
119
var _levels:Array<String> = [];
1210
var _positions:Array<Bool> = [];
1311

14-
public function new() {
12+
public function new(filter:Int) {
1513
setLevelFormat(LogLevel.TRACE, "[T] ", AnsiColor.GREY, true);
1614
setLevelFormat(LogLevel.DEBUG, "[D] ", AnsiColor.WHITE, true);
1715
setLevelFormat(LogLevel.INFO, "", AnsiColor.CYAN, false);
1816
setLevelFormat(LogLevel.WARNING, "[WARNING] ", AnsiColor.YELLOW, false);
1917
setLevelFormat(LogLevel.ERROR, "[ERROR] ", AnsiColor.RED, false);
20-
setFilter(LogLevel.FILTER_STD);
18+
setFilter(filter);
2119
}
2220

2321
inline public function trace(message:Dynamic, ?position:PosInfos) {
@@ -43,11 +41,11 @@ class Logger {
4341
public function print(data:Dynamic, level:LogLevel, ?position:PosInfos) {
4442
var text = Std.string(data);
4543

46-
if((_filter & (1 << level)) == 0) {
44+
if ((_filter & (1 << level)) == 0) {
4745
return;
4846
}
4947

50-
if(_positions[level]) {
48+
if (_positions[level]) {
5149
text = position.fileName + ":" + position.lineNumber + " " + text;
5250
}
5351

src/hxmake/macr/CompileTime.hx

+6
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ class CompileTime {
1414
Compiler.addClassPath(makePath);
1515
Compiler.include("", true, null, [makePath]);
1616
}
17+
18+
public static function log(message:String) {
19+
#if hxmake_macrolog
20+
Sys.println('[MACRO] $message');
21+
#end
22+
}
1723
}

src/hxmake/macr/ModuleMacro.hx

+28-27
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package hxmake.macr;
22

3-
import hxmake.cli.MakeLog;
4-
import haxe.macro.Expr.Access;
5-
import sys.FileSystem;
63
import haxe.io.Path;
7-
import haxe.macro.Type;
84
import haxe.macro.Context;
5+
import haxe.macro.Expr.Access;
96
import haxe.macro.Expr;
7+
import haxe.macro.Type;
8+
import sys.FileSystem;
109

1110
using StringTools;
1211

@@ -20,42 +19,44 @@ class ModuleMacro {
2019
var modulePath = getModulePath(Context.getLocalModule());
2120
var childrenExprs:Array<Expr> = [];
2221

23-
MakeLog.trace(modulePath);
22+
CompileTime.log(modulePath);
2423
var changedModulePath:Array<String> = MacroHelper.extractMetaStrings(cls.meta, ":module_path");
25-
if(changedModulePath.length > 0) {
24+
if (changedModulePath.length > 0) {
2625
var parentPath = modulePath;
2726
modulePath = FileSystem.absolutePath(Path.join([modulePath, changedModulePath[0]]));
28-
MakeLog.trace("CHANGED TO: " + modulePath);
27+
CompileTime.log("CHANGED TO: " + modulePath);
2928
//childrenExprs.push(macro hxmake.core.CompiledProjectData.createModuleConnection($v{modulePath}, $v{childModulePath}));
3029
}
3130

3231
var guessModuleName = modulePath.split("/").pop();
3332

3433
var includes:Array<String> = MacroHelper.extractMetaStrings(cls.meta, ":include");
35-
for(include in includes) {
34+
for (include in includes) {
3635
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);
3939
continue;
4040
}
4141

4242
var cp = Path.join([childModulePath, "make"]);
43-
if(FileSystem.exists(cp)) {
43+
if (FileSystem.exists(cp)) {
4444
PluginInclude.scan(cp);
4545
CompileTime.addMakePath(cp);
4646
}
4747
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);
4950
}
5051

5152
childrenExprs.push(macro hxmake.core.CompiledProjectData.createModuleConnection($v{modulePath}, $v{childModulePath}));
5253
}
5354

5455
processMakeLibraries(":lib", cls.meta);
5556

56-
if(!cls.meta.has(":root")) {
57+
if (!cls.meta.has(":root")) {
5758
var parentMakeDir = FileSystem.absolutePath(Path.join([modulePath, "..", "make"]));
58-
if(FileSystem.exists(parentMakeDir) && FileSystem.isDirectory(parentMakeDir)) {
59+
if (FileSystem.exists(parentMakeDir) && FileSystem.isDirectory(parentMakeDir)) {
5960
PluginInclude.scan(parentMakeDir);
6061
CompileTime.addMakePath(parentMakeDir);
6162
}
@@ -67,13 +68,13 @@ class ModuleMacro {
6768
};
6869

6970
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}
7778
}, pos));
7879

7980
transformConstructor(fields);
@@ -83,11 +84,11 @@ class ModuleMacro {
8384

8485
static function processMakeLibraries(libraryMeta:String, metaAccess:MetaAccess) {
8586
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) {
8889
var libName = exprGetStringConst(meta.params[0]);
8990
var libPath = exprGetStringConst(meta.params[1]);
90-
if(libName == null) {
91+
if (libName == null) {
9192
throw '@$libraryMeta first argument need to be String literal';
9293
}
9394
PluginInclude.include(libName, libPath);
@@ -99,7 +100,7 @@ class ModuleMacro {
99100
}
100101

101102
static function exprGetStringConst(expr:Expr):Null<String> {
102-
if(expr == null) {
103+
if (expr == null) {
103104
return null;
104105
}
105106
return switch(expr.expr) {
@@ -113,8 +114,8 @@ class ModuleMacro {
113114
}
114115

115116
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") {
118119
field.name = "__initialize";
119120
field.access = [Access.AOverride];
120121
// TODO: add more validation at Compile-time

tool/hxmake/tool/AliasScript.hx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package hxmake.tool;
22

3-
import hxmake.cli.MakeLog;
43
import haxe.io.Path;
54
import haxe.macro.Compiler;
65
import hxmake.cli.CL;
6+
import hxmake.cli.MakeLog;
77
import hxmake.utils.Haxelib;
88

99
class AliasScript {
1010
public static function main() {
11-
MakeLog.initialize(Sys.args());
11+
var args = Sys.args();
12+
MakeLog.initialize(args.indexOf("--silent") >= 0, args.indexOf("--verbose") >= 0);
1213
var library = Compiler.getDefine("library");
1314
var toolPath = Haxelib.libPath(library, true);
1415
Sys.exit(CL.command("neko", [Path.join([toolPath, "run.n"])].concat(Sys.args())));

tool/hxmake/tool/MakeRunner.hx

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package hxmake.tool;
22

3+
import haxe.io.Path;
34
import hxmake.cli.CL;
4-
import hxmake.utils.HaxeTarget;
5-
import hxmake.utils.Hxml;
65
import hxmake.utils.Haxe;
76
import hxmake.utils.Haxelib;
8-
import haxe.io.Path;
7+
import hxmake.utils.HaxeTarget;
8+
import hxmake.utils.Hxml;
99

1010
@:final
1111
class MakeRunner {
@@ -26,8 +26,11 @@ class MakeRunner {
2626
hxml.libraries = [];
2727
hxml.classPath.push(libPath);
2828
hxml.defines.push("hxmake");
29+
if (builtInArguments.indexOf("--macrolog") >= 0) {
30+
hxml.defines.push("hxmake_macrolog");
31+
}
2932

30-
if(isCompiler) {
33+
if (isCompiler) {
3134
hxml.target = HaxeTarget.Interp;
3235
}
3336
else {
@@ -46,7 +49,7 @@ class MakeRunner {
4649
hxml.showTimes = builtInArguments.indexOf("--times") >= 0;
4750

4851
var result = Haxe.compile(hxml);
49-
if(!result || isCompiler) {
52+
if (!result || isCompiler) {
5053
return result;
5154
}
5255

@@ -55,8 +58,8 @@ class MakeRunner {
5558

5659
static function toLiteralsArrayString(values:Array<String>):String {
5760
var args = [];
58-
if(values != null) {
59-
for(v in values) {
61+
if (values != null) {
62+
for (v in values) {
6063
args.push('"$v"');
6164
}
6265
}

tool/hxmake/tool/RunScript.hx

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
package hxmake.tool;
22

3-
import hxmake.cli.MakeLog;
43
import haxe.Timer;
4+
import hxmake.cli.MakeLog;
55

66
class RunScript {
77

88
public static function main() {
99
var args = popRunCwd(Sys.args());
1010
var success = false;
1111

12-
MakeLog.initialize(args);
12+
MakeLog.initialize(args.indexOf("--silent") >= 0, args.indexOf("--verbose") >= 0);
1313

1414
measure(function() {
1515
success = run(args);
1616
}, args.indexOf("--times") < 0);
1717

18-
if(!success) {
18+
if (!success) {
1919
MakeLog.error("hxmake FAILED");
2020
Sys.exit(-1);
2121
}
2222
}
2323

2424
static function run(args:Array<String>):Bool {
25-
if(args.indexOf("_") >= 0) {
25+
if (args.indexOf("_") >= 0) {
2626
return Installer.run("hxmake");
2727
}
2828
return MakeRunner.make(Sys.getCwd(), args);
2929
}
3030

31-
static function measure(func:Void->Void, bypass:Bool = false) {
32-
if(bypass) {
31+
static function measure(func:Void -> Void, bypass:Bool = false) {
32+
if (bypass) {
3333
func();
3434
return;
3535
}
@@ -43,7 +43,7 @@ class RunScript {
4343
static function popRunCwd(args:Array<String>):Array<String> {
4444
var result = args.copy();
4545
var env = Sys.getEnv("HAXELIB_RUN");
46-
if(env != null && env.length > 0 && Std.parseInt(env) != 0) {
46+
if (env != null && env.length > 0 && Std.parseInt(env) != 0) {
4747
Sys.setCwd(result.pop());
4848
}
4949
return result;

0 commit comments

Comments
 (0)