1
1
// build.rs
2
2
3
- use std:: process:: Command ;
4
3
use std:: env;
5
4
use std:: path:: Path ;
6
5
#[ macro_use]
7
6
extern crate error_chain;
8
7
9
8
#[ cfg( windows) ]
10
9
mod execs {
11
- pub const NPM : & ' static str = "npm.cmd" ;
12
- pub const STYLUS : & ' static str = "stylus.cmd" ;
10
+ use std:: process:: Command ;
11
+
12
+ pub fn cmd ( program : & str ) -> Command {
13
+ let mut cmd = Command :: new ( "cmd" ) ;
14
+ cmd. args ( & [ "/c" , program] ) ;
15
+ cmd
16
+ }
13
17
}
14
18
#[ cfg( not( windows) ) ]
15
19
mod execs {
16
- pub const NPM : & ' static str = "npm" ;
17
- pub const STYLUS : & ' static str = "stylus" ;
20
+ use std:: process:: Command ;
21
+
22
+ pub fn cmd ( program : & str ) -> Command {
23
+ Command :: new ( program)
24
+ }
18
25
}
19
26
20
27
@@ -25,15 +32,15 @@ error_chain!{
25
32
}
26
33
27
34
fn program_exists ( program : & str ) -> Result < ( ) > {
28
- Command :: new ( program)
35
+ execs :: cmd ( program)
29
36
. arg ( "-v" )
30
37
. output ( )
31
38
. chain_err ( || format ! ( "Please install '{}'!" , program) ) ?;
32
39
Ok ( ( ) )
33
40
}
34
41
35
42
fn npm_package_exists ( package : & str ) -> Result < ( ) > {
36
- let status = Command :: new ( execs:: NPM )
43
+ let status = execs:: cmd ( "npm" )
37
44
. args ( & [ "list" , "-g" ] )
38
45
. arg ( package)
39
46
. output ( ) ;
@@ -67,7 +74,7 @@ fn run() -> Result<()> {
67
74
68
75
if let Ok ( _) = env:: var ( "CARGO_FEATURE_REGENERATE_CSS" ) {
69
76
// Check dependencies
70
- Program ( execs :: NPM ) . exists ( ) ?;
77
+ Program ( "npm" ) . exists ( ) ?;
71
78
Program ( "node" ) . exists ( ) . or ( Program ( "nodejs" ) . exists ( ) ) ?;
72
79
Package ( "nib" ) . exists ( ) ?;
73
80
Package ( "stylus" ) . exists ( ) ?;
@@ -78,7 +85,7 @@ fn run() -> Result<()> {
78
85
let theme_dir = Path :: new ( & manifest_dir) . join ( "src/theme/" ) ;
79
86
let stylus_dir = theme_dir. join ( "stylus/book.styl" ) ;
80
87
81
- if !Command :: new ( execs:: STYLUS )
88
+ if !execs:: cmd ( "stylus" )
82
89
. arg ( stylus_dir)
83
90
. arg ( "--out" )
84
91
. arg ( theme_dir)
0 commit comments