Skip to content

Commit c2f4a85

Browse files
committed
installer task, built-in module, runner arguments enum, dce FULL for runner and alias
1 parent 688c0aa commit c2f4a85

12 files changed

+137
-105
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- Resolve tasks according to module dependencies
44
- Drop Haxe 3.2.X support, switch CI to Haxe 3.4.X
5+
- Installer code moved to built-in task and will be run in make context
6+
- Built-in Module allows to run default tasks without modules context
57

68
# v0.1.7
79

build.hxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-cp tool
22
-cp src
3-
#-debug
3+
-dce full
44
--each
55

66
-main hxmake.tool.RunScript

run.n

-30.7 KB
Binary file not shown.

src/hxmake/core/BuiltInModule.hx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package hxmake.core;
2+
3+
import hxmake.tasks.InstallTask;
4+
import hxmake.tasks.ListModules;
5+
import hxmake.tasks.ListTask;
6+
7+
/**
8+
Built in module is module for default tasks,
9+
it's required to run default tasks in any folder,
10+
even where make modules are not defined
11+
**/
12+
@:root
13+
class BuiltInModule extends Module {
14+
function new() {
15+
// TODO: better naming
16+
name = "__internal";
17+
task("tasks", new ListTask());
18+
task("modules", new ListModules());
19+
task("_", new InstallTask());
20+
}
21+
}

src/hxmake/core/MakeArgument.hx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package hxmake.core;
2+
3+
@:enum abstract MakeArgument(String) to String from String {
4+
// Enables `debug` and `trace` log levels
5+
var VERBOSE = "--verbose";
6+
7+
// Mute logger output
8+
var SILENT = "--silent";
9+
10+
// Enables compile-time logging from `CompileTime.log`
11+
var MAKE_COMPILER_LOG = "--make-compiler-log";
12+
13+
// Run make in haxe compiler-mode `--interp` (EXPEREMENTAL)
14+
var MAKE_COMPILER_MODE = "--make-compiler-mode";
15+
16+
// Show Haxe compiler time statistics, adds `--times -D macro-times`
17+
var MAKE_COMPILER_TIME = "--make-compiler-time";
18+
19+
// Rebuild `hxmake` binary and re-install alias-script
20+
var TASK_REBUILD = "_";
21+
}

src/hxmake/core/ModuleGraph.hx

-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,5 @@ class ModuleGraph {
3333
if (module.name != "hxmake" && module.config.devDependencies.get("hxmake") == null) {
3434
module.config.devDependencies.set("hxmake", "haxelib;global");
3535
}
36-
37-
if (module.isMain) {
38-
module.task("tasks", new hxmake.tasks.ListTask());
39-
module.task("modules", new hxmake.tasks.ListModules());
40-
}
4136
}
4237
}

src/hxmake/macr/CompileTime.hx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CompileTime {
1616
}
1717

1818
public static function log(message:String) {
19-
#if hxmake_macrolog
19+
#if hxmake_compiler_log
2020
Sys.println('[MACRO] $message');
2121
#end
2222
}

src/hxmake/macr/InitMacro.hx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class InitMacro {
1212
public static function generateMainClass(initialMakeDir:String, isCompiler:Bool, args:Array<String>) {
1313
PluginInclude.scan(initialMakeDir);
1414
CompileTime.addMakePath(initialMakeDir);
15-
15+
Context.getType("hxmake.core.BuiltInModule");
1616
var pos = Context.currentPos();
1717
var fields:Array<Field> = Context.getBuildFields();
1818
var mainFun:Function = {

tool/hxmake/tool/Installer.hx src/hxmake/tasks/InstallTask.hx

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,76 @@
1-
package hxmake.tool;
1+
package hxmake.tasks;
22

33
import haxe.io.Path;
44
import hxmake.cli.CL;
5-
import hxmake.cli.MakeLog;
5+
import hxmake.cli.logging.Logger;
66
import hxmake.utils.Haxe;
77
import hxmake.utils.Haxelib;
88
import sys.FileSystem;
99
import sys.io.File;
1010

11-
using StringTools;
12-
1311
@:final
14-
class Installer {
12+
class InstallTask extends Task {
13+
14+
public function new() {
15+
name = "_";
16+
description = "Rebuild and install `hxmake` binary";
17+
}
1518

16-
public static function run(library:String, ?alias:String):Bool {
19+
override public function run() {
20+
if (!install(project.logger, "hxmake")) {
21+
project.logger.error("hxmake installation FAILED");
22+
throw "stop execution";
23+
}
24+
}
1725

26+
static function install(logger:Logger, library:String, ?alias:String):Bool {
1827
if (alias == null) {
1928
alias = library;
2029
}
2130

2231
var libPath = Haxelib.libPath(library);
2332
if (libPath == null) {
24-
MakeLog.error('"$library" is not installed');
33+
logger.error('"$library" is not installed');
2534
return false;
2635
}
2736

2837
if (!FileSystem.exists(libPath)) {
29-
MakeLog.error('"$library" not found at $libPath');
38+
logger.error('"$library" not found at $libPath');
3039
return false;
3140
}
3241

33-
MakeLog.trace('Use "$library" from "$libPath"');
42+
logger.trace('Use "$library" from "$libPath"');
3443

3544
return CL.workingDir.with(libPath, function() {
3645

3746
// COMPILATION
3847
if (!Haxe.exec(["build.hxml"])) {
39-
MakeLog.error("HxMake library build failed");
48+
logger.error("HxMake library build failed");
4049
return false;
4150
}
4251

4352
if (CL.platform.isWindows && FileSystem.exists('$alias.exe')) {
44-
MakeLog.info('Alias should be installed already');
45-
MakeLog.info('If you need to reinstall alias script use:');
46-
MakeLog.info('> haxelib run $library _');
53+
logger.info('Alias should be installed already');
54+
logger.info('If you need to reinstall alias script use:');
55+
logger.info('> haxelib run $library _');
4756
return true;
4857
}
4958

5059
if (CL.command('nekotools', ['boot', '$library.n']) != 0) {
51-
MakeLog.error('Failed to create alias-script executable');
60+
logger.error('Failed to create alias-script executable');
5261
return false;
5362
}
5463

5564
// INSTALL
56-
MakeLog.info('We`re going to install ${alias.toUpperCase()} command');
57-
MakeLog.info('Please enter password if required...');
65+
logger.info('We`re going to install ${alias.toUpperCase()} command');
66+
logger.warning('Please enter password if required...');
5867
try {
5968
if (CL.platform.isWindows) {
6069
var haxePath = Haxe.path();
6170
var pn = '$alias.exe';
6271
var src = Path.join([libPath, pn]);
6372
var dst = Path.join([haxePath, pn]);
64-
MakeLog.trace('Copy hxmake.exe to $haxePath');
73+
logger.trace('Copy hxmake.exe to $haxePath');
6574
File.copy(src, dst);
6675

6776
// TODO: windows replace .exe issue
@@ -77,8 +86,8 @@ class Installer {
7786
}
7887
}
7988
catch (e:Dynamic) {
80-
MakeLog.error(e);
81-
MakeLog.error("Error while installing system command-line");
89+
logger.error(e);
90+
logger.error("Error while installing system command-line");
8291
return false;
8392
}
8493

tool/hxmake/tool/AliasScript.hx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import haxe.macro.Compiler;
55
import hxmake.cli.CL;
66
import hxmake.cli.MakeLog;
77
import hxmake.core.Arguments;
8+
import hxmake.core.MakeArgument;
89
import hxmake.utils.Haxelib;
910

1011
class AliasScript {
1112
public static function main() {
1213
var args = new Arguments(Sys.args());
13-
var logger = MakeLog.logger;
14-
logger.setupFilter(
15-
args.hasProperty("--silent"),
16-
args.hasProperty("--verbose")
14+
MakeLog.logger.setupFilter(
15+
args.hasProperty(MakeArgument.SILENT),
16+
args.hasProperty(MakeArgument.VERBOSE)
1717
);
1818
var library = Compiler.getDefine("library");
1919
var toolPath = Haxelib.libPath(library, true);

tool/hxmake/tool/MakeRunner.hx

-65
This file was deleted.

tool/hxmake/tool/RunScript.hx

+58-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
package hxmake.tool;
22

3+
import haxe.io.Path;
34
import haxe.Timer;
5+
import hxmake.cli.CL;
46
import hxmake.cli.MakeLog;
57
import hxmake.core.Arguments;
8+
import hxmake.core.MakeArgument;
9+
import hxmake.utils.Haxe;
10+
import hxmake.utils.Haxelib;
11+
import hxmake.utils.HaxeTarget;
12+
import hxmake.utils.Hxml;
613

714
class RunScript {
815

16+
static inline var INIT_MACRO_METHOD:String = "hxmake.macr.InitMacro.generateMainClass";
17+
918
public static function main() {
1019
var args = new Arguments(popRunCwd(Sys.args()));
1120
var logger = MakeLog.logger;
1221

1322
logger.setupFilter(
14-
args.hasProperty("--silent"),
15-
args.hasProperty("--verbose")
16-
);
17-
18-
var success = measure(
19-
function() { return args.hasTask("_") ? Installer.run("hxmake") : MakeRunner.make(Sys.getCwd(), args.args); },
20-
args.hasProperty("--times") ? function(totalTime:Float) { logger.info('Total time: $totalTime sec.'); } : null
23+
args.hasProperty(MakeArgument.SILENT),
24+
args.hasProperty(MakeArgument.VERBOSE)
2125
);
2226

23-
if (!success) {
24-
logger.error("hxmake FAILED");
27+
if (!make(Sys.getCwd(), args)) {
28+
logger.error("Make compilation FAILED");
2529
Sys.exit(-1);
2630
}
2731
}
@@ -45,4 +49,49 @@ class RunScript {
4549
}
4650
return result;
4751
}
52+
53+
// TODO: path exists (cwd, make, lib)
54+
static function make(path:String, arguments:Arguments):Bool {
55+
56+
Sys.setCwd(path);
57+
58+
var makePath = Path.join([path, "make"]);
59+
var libPath = Haxelib.classPath("hxmake", true);
60+
var isCompiler = arguments.hasProperty(MakeArgument.MAKE_COMPILER_MODE);
61+
62+
var hxml = new Hxml();
63+
hxml.main = "HxMakeMain";
64+
hxml.libraries = [];
65+
hxml.classPath.push(libPath);
66+
hxml.defines.push("hxmake");
67+
if (arguments.hasProperty(MakeArgument.MAKE_COMPILER_LOG)) {
68+
hxml.defines.push("hxmake_compiler_log");
69+
}
70+
71+
if (isCompiler) {
72+
// TODO: EVAL instead of --interp
73+
hxml.target = HaxeTarget.Interp;
74+
}
75+
else {
76+
// TODO: try Node.js instead of Neko?
77+
hxml.target = HaxeTarget.Neko;
78+
hxml.output = "make.n";
79+
}
80+
81+
hxml.macros.push('$INIT_MACRO_METHOD("$makePath",$isCompiler,[${toLiteralsArrayString(arguments.args)}])');
82+
83+
hxml.showMacroTimes =
84+
hxml.showTimes = arguments.hasProperty(MakeArgument.MAKE_COMPILER_TIME);
85+
86+
var result = Haxe.compile(hxml);
87+
if (!result || isCompiler) {
88+
return result;
89+
}
90+
91+
return CL.command("neko", ["make.n"]) == 0;
92+
}
93+
94+
static function toLiteralsArrayString(values:Array<String>):String {
95+
return values != null ? values.map(function(v:String) return '"$v"').join(",") : "";
96+
}
4897
}

0 commit comments

Comments
 (0)