1
- package hxmake .tool ;
1
+ package hxmake .tasks ;
2
2
3
3
import haxe .io .Path ;
4
4
import hxmake .cli .CL ;
5
- import hxmake .cli .MakeLog ;
5
+ import hxmake .cli .logging . Logger ;
6
6
import hxmake .utils .Haxe ;
7
7
import hxmake .utils .Haxelib ;
8
8
import sys .FileSystem ;
9
9
import sys .io .File ;
10
10
11
- using StringTools ;
12
-
13
11
@:final
14
- class Installer {
12
+ class InstallTask extends Task {
13
+
14
+ public function new () {
15
+ name = " _" ;
16
+ description = " Rebuild and install `hxmake` binary" ;
17
+ }
15
18
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
+ }
17
25
26
+ static function install (logger : Logger , library : String , ? alias : String ): Bool {
18
27
if (alias == null ) {
19
28
alias = library ;
20
29
}
21
30
22
31
var libPath = Haxelib .libPath (library );
23
32
if (libPath == null ) {
24
- MakeLog .error (' " $library " is not installed' );
33
+ logger .error (' " $library " is not installed' );
25
34
return false ;
26
35
}
27
36
28
37
if (! FileSystem .exists (libPath )) {
29
- MakeLog .error (' " $library " not found at $libPath ' );
38
+ logger .error (' " $library " not found at $libPath ' );
30
39
return false ;
31
40
}
32
41
33
- MakeLog .trace (' Use " $library " from " $libPath "' );
42
+ logger .trace (' Use " $library " from " $libPath "' );
34
43
35
44
return CL .workingDir .with (libPath , function () {
36
45
37
46
// COMPILATION
38
47
if (! Haxe .exec ([" build.hxml" ])) {
39
- MakeLog .error (" HxMake library build failed" );
48
+ logger .error (" HxMake library build failed" );
40
49
return false ;
41
50
}
42
51
43
52
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 _' );
47
56
return true ;
48
57
}
49
58
50
59
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' );
52
61
return false ;
53
62
}
54
63
55
64
// 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...' );
58
67
try {
59
68
if (CL .platform .isWindows ) {
60
69
var haxePath = Haxe .path ();
61
70
var pn = ' $alias .exe' ;
62
71
var src = Path .join ([libPath , pn ]);
63
72
var dst = Path .join ([haxePath , pn ]);
64
- MakeLog .trace (' Copy hxmake.exe to $haxePath ' );
73
+ logger .trace (' Copy hxmake.exe to $haxePath ' );
65
74
File .copy (src , dst );
66
75
67
76
// TODO: windows replace .exe issue
@@ -77,8 +86,8 @@ class Installer {
77
86
}
78
87
}
79
88
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" );
82
91
return false ;
83
92
}
84
93
0 commit comments