Skip to content

Commit 4f65d25

Browse files
committed
test task refactoring
1 parent 39c3bff commit 4f65d25

15 files changed

+652
-324
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ install:
1010

1111
script:
1212
- haxelib run hxmake _
13+
- hxmake _
1314
- hxmake haxe

appveyor.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ build: off
1515
test_script:
1616
- haxelib dev hxmake .
1717
- haxelib run hxmake _
18+
- hxmake _
1819
- hxmake haxe

run.n

2.66 KB
Binary file not shown.

src/hxmake/Task.hx

+29-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ class Task {
77
public var description:String = "";
88
public var enabled:Bool = true;
99
public var module(default, null):Module;
10-
public var chain(default, null):Array<Task> = [];
10+
11+
public var chainBefore(default, null):Array<Task> = [];
12+
public var chainAfter(default, null):Array<Task> = [];
13+
1114
public var parent(default, null):Task;
1215

1316
var __after:Map<String, String> = new Map();
@@ -17,14 +20,20 @@ class Task {
1720

1821
function _configure() {
1922
configure();
20-
for(chained in chain) {
23+
for(chained in chainBefore) {
24+
chained._configure();
25+
}
26+
for(chained in chainAfter) {
2127
chained._configure();
2228
}
2329
}
2430

2531
function _run() {
32+
for(chained in chainBefore) {
33+
chained._run();
34+
}
2635
run();
27-
for(chained in chain) {
36+
for(chained in chainAfter) {
2837
chained._run();
2938
}
3039
}
@@ -54,9 +63,25 @@ class Task {
5463
public function run() {}
5564

5665
public function then<T:Task>(task:T):T {
57-
chain.push(task);
66+
chainAfter.push(task);
5867
task.parent = this;
5968
task.module = module;
6069
return task;
6170
}
71+
72+
public function prepend<T:Task>(task:T):T {
73+
chainBefore.push(task);
74+
task.parent = this;
75+
task.module = module;
76+
return task;
77+
}
78+
79+
function fail(description:String = "") {
80+
if(parent != null) {
81+
throw 'Sub-task $name of task ${parent.name} failed: \n$description';
82+
}
83+
else {
84+
throw 'Task $name failed: \n$description';
85+
}
86+
}
6287
}

src/hxmake/cli/WorkingDirectory.hx

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ class WorkingDirectory {
1010
_stack = [Sys.getCwd()];
1111
}
1212

13+
public function with<T>(path:String, func:Void->T):T {
14+
push(path);
15+
var result = func();
16+
pop();
17+
return result;
18+
}
19+
1320
public function push(path:String):String {
1421
var prev = current;
1522
if (path == null) {

src/hxmake/test/CiTools.hx

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

33
// todo final
4-
import hxmake.utils.Haxelib;
54
import hxmake.cli.Platform;
65
import hxmake.cli.CL;
76

7+
@:final
88
class CiTools {
99

1010
public static function installPackage(pckge:String, ?additionalArgs:Array<String>):Bool {

src/hxmake/test/HaxeTask.hx

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package hxmake.test;
2+
3+
import hxmake.cli.CL;
4+
import hxmake.utils.Haxe;
5+
import hxmake.utils.Hxml;
6+
7+
class HaxeTask extends Task {
8+
9+
// Meta information for keeping wide target key: mac, win, node, etc...
10+
public var targetName:String;
11+
12+
public var hxml(default, null):Hxml = new Hxml();
13+
14+
public function new() {}
15+
16+
override public function run() {
17+
if(!Haxe.compile(hxml)) {
18+
fail("Compilation failed");
19+
}
20+
}
21+
22+
public function createSetupTask():SetupTask {
23+
var pct = new SetupTask();
24+
switch(hxml.target) {
25+
case Cpp:
26+
if(CL.platform.isLinux) {
27+
pct.packages = pct.packages.concat(['gcc-multilib', 'g++-multilib']);
28+
}
29+
pct.libraries.push("hxcpp");
30+
case Cs:
31+
if(Sys.command("mono", ["--version"]) != 0) {
32+
if(CL.platform.isLinux) {
33+
pct.packages = pct.packages.concat(['mono-devel', 'mono-mcs']);
34+
}
35+
else if(CL.platform.isMac) {
36+
pct.packages.push('mono');
37+
}
38+
}
39+
pct.libraries.push("hxcs");
40+
case Java:
41+
pct.libraries.push("hxjava");
42+
default:
43+
}
44+
return pct;
45+
}
46+
}

0 commit comments

Comments
 (0)