Skip to content

Commit 5d447b2

Browse files
committed
update
1 parent 43bd63c commit 5d447b2

22 files changed

+373
-193
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# v0.2.0
22

33
- Removed deprecated methods
4+
- Order for Task `then`/`prepend`/`doFirst`/`doLast` methods
5+
- Fix task queue builder recursive dependency search
6+
- `Task.func` utility for creation of simple task with closure
47

58
# v0.1.8
69

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ haxelib dev hxmake path/to/hxmake
9595
- Then do initial rebuild command
9696
```
9797
haxelib run hxmake _
98-
```
98+
```
99+
100+
### Task running details
101+
Task will be ran in current working directory of associated module.
102+
103+
Default Task / Sub-Tasks / Functions running order:
104+
1. Sub-Tasks added with `prepend` method.
105+
2. Functions registered with `doFirst` method.
106+
3. Task's `run` logic.
107+
4. Functions registered with `doLast` method.
108+
5. Sub-Tasks added with `then` method.

run.n

-4.29 KB
Binary file not shown.

src/hxmake/Module.hx

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class Module {
1717
public var children(get, never):Array<Module>;
1818

1919
public var name(default, null):String;
20+
21+
/**
22+
Absolute path to Module folder
23+
**/
2024
public var path(default, null):String;
2125
public var config(get, never):ModuleConfig;
2226

@@ -44,9 +48,10 @@ class Module {
4448
// Finalization phase
4549
}
4650

51+
@:access(hxmake.Task)
4752
public function task(name:String, ?task:Task, ?type:Class<Task>):Task {
4853
if (task != null) {
49-
@:privateAccess task.module = this;
54+
task._module = this;
5055
_tasks.set(name, task);
5156
return task;
5257
}

src/hxmake/Project.hx

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ class Project {
1313
public var arguments(default, null):Arguments;
1414

1515
@:access(hxmake.Module)
16-
function new(modules:Array<Module>, arguments:Arguments, workingDir:String, logger:Logger) {
16+
function new(modules:Array<Module>, arguments:Arguments, runPath:String, logger:Logger) {
1717
this.arguments = arguments;
1818
this.logger = logger;
19-
this.workingDir = Path.directory(workingDir);
2019
this.modules = modules;
2120
for (module in modules) {
2221
module.project = this;
2322
}
23+
24+
workingDir = Path.directory(runPath);
2425
}
2526

2627
/**
@@ -49,4 +50,8 @@ class Project {
4950
}
5051
return null;
5152
}
53+
54+
public function toString() {
55+
return "Project";
56+
}
5257
}

src/hxmake/Task.hx

+51-64
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,40 @@
11
package hxmake;
22

3-
using hxmake.utils.TaskTools;
4-
53
class Task {
6-
4+
75
public var name:String;
86
public var description:String = "";
97
public var enabled:Bool = true;
108

119
/**
12-
* `Module` associated with this Task
10+
* `Module` associated with this task node
1311
**/
14-
public var module(default, null):Module;
12+
public var module(get, never):Module;
1513

1614
/**
1715
* `Project` of associated module
1816
* `null` if task is not linked to any module
1917
**/
2018
public var project(get, never):Project;
2119

22-
public var chainBefore(default, null):Array<Task> = [];
23-
public var chainAfter(default, null):Array<Task> = [];
24-
2520
public var parent(default, null):Task;
2621

22+
/** Task attached directly to this task **/
23+
var _module:Module;
24+
25+
/** Children before run BEFORE parent **/
26+
var _childrenBefore:Array<Task> = [];
27+
28+
/** Children before run AFTER parent **/
29+
var _childrenAfter:Array<Task> = [];
30+
2731
var __after:Map<String, String> = new Map();
2832
var __before:Map<String, String> = new Map();
2933
var __finalized:Map<String, String> = new Map();
3034
var __depends:Map<String, String> = new Map();
3135

32-
var _doFirst:Array<Task -> Void> = [];
33-
var _doLast:Array<Task -> Void> = [];
34-
35-
function _configure() {
36-
this.logStep("Configuration BEGIN");
37-
configure();
38-
this.logStep("Sub-tasks configuration (BEFORE)");
39-
for (chained in chainBefore) {
40-
chained._configure();
41-
}
42-
this.logStep("Sub-tasks configuration (AFTER)");
43-
for (chained in chainAfter) {
44-
chained._configure();
45-
}
46-
this.logStep("Configuration END");
47-
}
48-
49-
function _run() {
50-
this.logStep("Run BEGIN");
51-
this.logStep("Run BEFORE tasks");
52-
53-
for (chained in chainBefore) {
54-
chained._run();
55-
}
56-
for (cb in _doFirst) {
57-
cb(this);
58-
}
59-
this.logStep("Running");
60-
run();
61-
62-
this.logStep("Run AFTER tasks");
63-
for (cb in _doLast) {
64-
cb(this);
65-
}
66-
for (chained in chainAfter) {
67-
chained._run();
68-
}
69-
this.logStep("Run END");
70-
}
36+
var _doFirst = new Array<Task -> Void>();
37+
var _doLast = new Array<Task -> Void>();
7138

7239
public function runAfter(task:String):Task {
7340
__after.set(task, task);
@@ -90,22 +57,30 @@ class Task {
9057
return this;
9158
}
9259

60+
public function toString() {
61+
return 'Task $name ($description)';
62+
}
63+
9364
public function configure() {}
9465

9566
public function run() {}
9667

97-
public function then<T:Task>(task:T):T {
98-
chainAfter.push(task);
99-
task.parent = this;
100-
task.module = module;
101-
return task;
68+
public function prepend(task:Task):Task {
69+
return attachChild(task, _childrenBefore, true);
10270
}
10371

104-
public function prepend<T:Task>(task:T):T {
105-
chainBefore.push(task);
106-
task.parent = this;
107-
task.module = module;
108-
return task;
72+
public function then(task:Task):Task {
73+
return attachChild(task, _childrenAfter, false);
74+
}
75+
76+
public function doFirst(func:Task -> Void):Task {
77+
_doFirst.insert(0, func);
78+
return this;
79+
}
80+
81+
public function doLast(func:Task -> Void):Task {
82+
_doLast.push(func);
83+
return this;
10984
}
11085

11186
function fail(description:String = "") {
@@ -117,18 +92,24 @@ class Task {
11792
}
11893
}
11994

120-
public function doFirst(func:Task -> Void):Task {
121-
_doFirst.push(func);
122-
return this;
123-
}
95+
function attachChild(task:Task, array:Array<Task>, prepend:Bool):Task {
96+
if (task.parent != null) project.logger.error("Task is a child already (TODO: info)");
97+
task.parent = this;
98+
99+
if (_childrenBefore.indexOf(task) >= 0 || _childrenAfter.indexOf(task) >= 0) project.logger.error("Task is registered as child already (TODO: info)");
100+
if (prepend) array.unshift(task);
101+
else array.push(task);
124102

125-
public function doLast(func:Task -> Void):Task {
126-
_doLast.push(func);
127103
return this;
128104
}
129105

130106
function get_project():Project {
131-
return module != null ? module.project : null;
107+
var m = this.module;
108+
return m != null ? m.project : null;
109+
}
110+
111+
function get_module():Module {
112+
return _module != null ? _module : (parent != null ? parent.module : null);
132113
}
133114

134115
public static function empty(name:String = null, description = ""):Task {
@@ -137,6 +118,12 @@ class Task {
137118
task.description = description;
138119
return task;
139120
}
121+
122+
public static function func(fn:Void -> Void, name:String = null, description = ""):Task {
123+
return empty(name, description).doLast(function(_) {
124+
fn();
125+
});
126+
}
140127
}
141128

142129

src/hxmake/cli/FileUtil.hx

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class FileUtil {
1111
* returns path to created directory `path/dir`
1212
**/
1313
public static function ensureDirectory(path:String, dir:String):String {
14-
if(!FileSystem.exists(path)) throw '$path not found';
15-
if(!FileSystem.isDirectory(path)) throw '$path is not directory';
14+
if (!FileSystem.exists(path)) throw '$path not found';
15+
if (!FileSystem.isDirectory(path)) throw '$path is not directory';
1616

1717
path = Path.join([path, dir]);
18-
if(!FileSystem.exists(path)) FileSystem.createDirectory(path);
18+
if (!FileSystem.exists(path)) FileSystem.createDirectory(path);
1919

2020
return path;
2121
}
@@ -83,6 +83,10 @@ class FileUtil {
8383
return StringTools.replace(path1, "\\", "/") == StringTools.replace(path2, "\\", "/");
8484
}
8585

86+
public static function normalizeAbsolute(path:String):String {
87+
return Path.normalize(FileSystem.absolutePath(path));
88+
}
89+
8690
public static function fileExists(path:String):Bool {
8791
return FileSystem.exists(path) && !FileSystem.isDirectory(path);
8892
}

src/hxmake/core/CompiledProjectData.hx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package hxmake.core;
22

3-
import hxmake.cli.FileUtil;
4-
53
/**
64
Storage for data, which collected during compilation, or manually provided for Project
75
**/
@@ -38,10 +36,10 @@ class CompiledProjectData {
3836
static function resolveHierarchy(modules:Array<Module>, connections:Iterable<ModuleConnectionData>) {
3937
for (connection in connections) {
4038
for (parent in modules) {
41-
if (FileUtil.pathEquals(parent.path, connection.parentPath)) {
39+
if (parent.path == connection.parentPath) {
4240
for (childPath in connection.childPath) {
4341
for (child in modules) {
44-
if (FileUtil.pathEquals(child.path, childPath)) {
42+
if (child.path == childPath) {
4543
appendChildModule(parent, child);
4644
}
4745
}

src/hxmake/core/TaskQueue.hx

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
package hxmake.core;
22

33
import hxmake.cli.CL;
4+
import hxmake.cli.MakeLog;
45
import hxmake.Task;
56

67
@:final
78
@:access(hxmake.Task)
89
class TaskQueue {
910

1011
var _queue:Array<TaskNode>;
12+
var _runner:TaskRunner;
1113

1214
public function new(queue:Array<TaskNode>) {
1315
_queue = queue;
16+
// TODO: as dependency
17+
_runner = new TaskRunner(MakeLog.logger);
1418
}
1519

1620
public function configure():Void {
1721
var wd = CL.workingDir;
1822
for (node in _queue) {
1923
wd.with(node.module.path, function() {
20-
node.task._configure();
24+
_runner.configure(node.task);
2125
});
2226
}
2327
}
2428

2529
public function run() {
2630
var wd = CL.workingDir;
2731
for (node in _queue) {
28-
if (node.task.enabled) {
29-
wd.with(node.module.path, function() {
30-
node.task._run();
31-
});
32-
}
32+
wd.with(node.module.path, function() {
33+
_runner.run(node.task);
34+
});
3335
}
3436
}
3537
}

0 commit comments

Comments
 (0)