@@ -5,25 +5,23 @@ use std::{
5
5
path:: { Path , PathBuf } ,
6
6
} ;
7
7
8
- use anyhow:: Result ;
9
8
use flate2:: { write:: GzEncoder , Compression } ;
10
- use xshell:: { cmd, cp , mkdir_p , pushd , pushenv , read_file , rm_rf , write_file } ;
9
+ use xshell:: { cmd, Shell } ;
11
10
12
11
use crate :: { date_iso, flags, project_root} ;
13
12
14
13
impl flags:: Dist {
15
- pub ( crate ) fn run ( self ) -> Result < ( ) > {
16
- let stable =
17
- std:: env:: var ( "GITHUB_REF" ) . unwrap_or_default ( ) . as_str ( ) == "refs/heads/release" ;
14
+ pub ( crate ) fn run ( self , sh : & Shell ) -> anyhow:: Result < ( ) > {
15
+ let stable = sh. var ( "GITHUB_REF" ) . unwrap_or_default ( ) . as_str ( ) == "refs/heads/release" ;
18
16
19
17
let project_root = project_root ( ) ;
20
18
let target = Target :: get ( & project_root) ;
21
19
let dist = project_root. join ( "dist" ) ;
22
- rm_rf ( & dist) ?;
23
- mkdir_p ( & dist) ?;
20
+ sh . remove_path ( & dist) ?;
21
+ sh . create_dir ( & dist) ?;
24
22
25
23
let release_channel = if stable { "stable" } else { "nightly" } ;
26
- dist_server ( release_channel, & target) ?;
24
+ dist_server ( sh , release_channel, & target) ?;
27
25
28
26
if let Some ( patch_version) = self . client_patch_version {
29
27
let version = if stable {
@@ -32,58 +30,63 @@ impl flags::Dist {
32
30
// A hack to make VS Code prefer nightly over stable.
33
31
format ! ( "0.3.{}" , patch_version)
34
32
} ;
35
- let release_tag = if stable { date_iso ( ) ? } else { "nightly" . to_string ( ) } ;
36
- dist_client ( & version, & release_tag, & target) ?;
33
+ let release_tag = if stable { date_iso ( sh ) ? } else { "nightly" . to_string ( ) } ;
34
+ dist_client ( sh , & version, & release_tag, & target) ?;
37
35
}
38
36
Ok ( ( ) )
39
37
}
40
38
}
41
39
42
- fn dist_client ( version : & str , release_tag : & str , target : & Target ) -> Result < ( ) > {
40
+ fn dist_client (
41
+ sh : & Shell ,
42
+ version : & str ,
43
+ release_tag : & str ,
44
+ target : & Target ,
45
+ ) -> anyhow:: Result < ( ) > {
43
46
let bundle_path = Path :: new ( "editors" ) . join ( "code" ) . join ( "server" ) ;
44
- mkdir_p ( & bundle_path) ?;
45
- cp ( & target. server_path , & bundle_path) ?;
47
+ sh . create_dir ( & bundle_path) ?;
48
+ sh . copy_file ( & target. server_path , & bundle_path) ?;
46
49
if let Some ( symbols_path) = & target. symbols_path {
47
- cp ( symbols_path, & bundle_path) ?;
50
+ sh . copy_file ( symbols_path, & bundle_path) ?;
48
51
}
49
52
50
- let _d = pushd ( "./editors/code" ) ? ;
53
+ let _d = sh . push_dir ( "./editors/code" ) ;
51
54
52
- let mut patch = Patch :: new ( "./package.json" ) ?;
55
+ let mut patch = Patch :: new ( sh , "./package.json" ) ?;
53
56
patch
54
57
. replace ( r#""version": "0.4.0-dev""# , & format ! ( r#""version": "{}""# , version) )
55
58
. replace ( r#""releaseTag": null"# , & format ! ( r#""releaseTag": "{}""# , release_tag) )
56
59
. replace ( r#""$generated-start": {},"# , "" )
57
60
. replace ( ",\n \" $generated-end\" : {}" , "" )
58
61
. replace ( r#""enabledApiProposals": [],"# , r#""# ) ;
59
- patch. commit ( ) ?;
62
+ patch. commit ( sh ) ?;
60
63
61
64
Ok ( ( ) )
62
65
}
63
66
64
- fn dist_server ( release_channel : & str , target : & Target ) -> Result < ( ) > {
65
- let _e = pushenv ( "RUST_ANALYZER_CHANNEL" , release_channel) ;
66
- let _e = pushenv ( "CARGO_PROFILE_RELEASE_LTO" , "thin" ) ;
67
+ fn dist_server ( sh : & Shell , release_channel : & str , target : & Target ) -> anyhow :: Result < ( ) > {
68
+ let _e = sh . push_env ( "RUST_ANALYZER_CHANNEL" , release_channel) ;
69
+ let _e = sh . push_env ( "CARGO_PROFILE_RELEASE_LTO" , "thin" ) ;
67
70
68
71
// Uncomment to enable debug info for releases. Note that:
69
72
// * debug info is split on windows and macs, so it does nothing for those platforms,
70
73
// * on Linux, this blows up the binary size from 8MB to 43MB, which is unreasonable.
71
- // let _e = pushenv ("CARGO_PROFILE_RELEASE_DEBUG", "1");
74
+ // let _e = sh.push_env ("CARGO_PROFILE_RELEASE_DEBUG", "1");
72
75
73
76
if target. name . contains ( "-linux-" ) {
74
77
env:: set_var ( "CC" , "clang" ) ;
75
78
}
76
79
77
80
let target_name = & target. name ;
78
- cmd ! ( "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} --release" ) . run ( ) ?;
81
+ cmd ! ( sh , "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} --release" ) . run ( ) ?;
79
82
80
83
let dst = Path :: new ( "dist" ) . join ( & target. artifact_name ) ;
81
84
gzip ( & target. server_path , & dst. with_extension ( "gz" ) ) ?;
82
85
83
86
Ok ( ( ) )
84
87
}
85
88
86
- fn gzip ( src_path : & Path , dest_path : & Path ) -> Result < ( ) > {
89
+ fn gzip ( src_path : & Path , dest_path : & Path ) -> anyhow :: Result < ( ) > {
87
90
let mut encoder = GzEncoder :: new ( File :: create ( dest_path) ?, Compression :: best ( ) ) ;
88
91
let mut input = io:: BufReader :: new ( File :: open ( src_path) ?) ;
89
92
io:: copy ( & mut input, & mut encoder) ?;
@@ -133,9 +136,9 @@ struct Patch {
133
136
}
134
137
135
138
impl Patch {
136
- fn new ( path : impl Into < PathBuf > ) -> Result < Patch > {
139
+ fn new ( sh : & Shell , path : impl Into < PathBuf > ) -> anyhow :: Result < Patch > {
137
140
let path = path. into ( ) ;
138
- let contents = read_file ( & path) ?;
141
+ let contents = sh . read_file ( & path) ?;
139
142
Ok ( Patch { path, original_contents : contents. clone ( ) , contents } )
140
143
}
141
144
@@ -145,8 +148,8 @@ impl Patch {
145
148
self
146
149
}
147
150
148
- fn commit ( & self ) -> Result < ( ) > {
149
- write_file ( & self . path , & self . contents ) ?;
151
+ fn commit ( & self , sh : & Shell ) -> anyhow :: Result < ( ) > {
152
+ sh . write_file ( & self . path , & self . contents ) ?;
150
153
Ok ( ( ) )
151
154
}
152
155
}
0 commit comments