File tree Expand file tree Collapse file tree 3 files changed +21
-26
lines changed Expand file tree Collapse file tree 3 files changed +21
-26
lines changed Original file line number Diff line number Diff line change 1
1
use serde_json;
2
2
use cargo_metadata;
3
+ use std:: path:: PathBuf ;
3
4
4
- #[ derive( Debug , Deserialize , Hash ) ]
5
+ #[ derive( Debug , Hash ) ]
5
6
pub struct Config {
6
7
pub memcpy : bool ,
7
- pub sysroot_path : Option < String > ,
8
+ pub sysroot_path : PathBuf ,
8
9
}
9
10
10
- impl Default for Config {
11
- fn default ( ) -> Self {
12
- Config {
13
- memcpy : true ,
14
- sysroot_path : None ,
15
- }
16
- }
11
+ #[ derive( Debug , Deserialize , Default ) ]
12
+ struct ParseConfig {
13
+ pub memcpy : Option < bool > ,
14
+ pub sysroot_path : Option < String > ,
17
15
}
18
16
19
17
impl Config {
20
18
pub fn from_metadata ( metadata : & cargo_metadata:: Metadata ) -> Result < Config , serde_json:: Error > {
21
19
let package_metadata = metadata. packages . first ( ) . map ( |p| & p. metadata ) ;
22
20
let crate_metadata = package_metadata. as_ref ( ) . and_then ( |m| m. get ( "cargo-xbuild" ) ) ;
23
- match crate_metadata {
24
- Some ( json) => serde_json:: from_value ( json. clone ( ) ) ,
25
- None => Ok ( Config :: default ( ) )
26
- }
21
+ let config = match crate_metadata {
22
+ Some ( json) => serde_json:: from_value ( json. clone ( ) ) ?,
23
+ None => ParseConfig :: default ( ) ,
24
+ } ;
25
+
26
+ Ok ( Config {
27
+ memcpy : config. memcpy . unwrap_or ( true ) ,
28
+ sysroot_path : PathBuf :: from ( config. sysroot_path . unwrap_or ( "target/sysroot" . into ( ) ) ) ,
29
+ } )
27
30
}
28
31
}
Original file line number Diff line number Diff line change @@ -147,7 +147,6 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
147
147
let metadata =
148
148
cargo_metadata:: metadata ( args. manifest_path ( ) ) . expect ( "cargo metadata invocation failed" ) ;
149
149
let root = Path :: new ( & metadata. workspace_root ) ;
150
- let target_directory = Path :: new ( & metadata. target_directory ) ;
151
150
let crate_config = config:: Config :: from_metadata ( & metadata)
152
151
. map_err ( |_| "parsing package.metadata.cargo-xbuild section failed" ) ?;
153
152
@@ -193,7 +192,7 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
193
192
} ;
194
193
195
194
if let Some ( cmode) = cmode {
196
- let home = xargo:: home ( target_directory , & crate_config) ?;
195
+ let home = xargo:: home ( root , & crate_config) ?;
197
196
let rustflags = cargo:: rustflags ( config. as_ref ( ) , cmode. triple ( ) ) ?;
198
197
199
198
sysroot:: update (
Original file line number Diff line number Diff line change 1
1
use std:: path:: { Display , PathBuf } ;
2
2
use std:: process:: { Command , ExitStatus } ;
3
- use std:: { fs , mem} ;
3
+ use std:: mem;
4
4
use std:: io:: { self , Write } ;
5
5
use std:: path:: Path ;
6
6
@@ -69,16 +69,9 @@ impl Home {
69
69
}
70
70
}
71
71
72
- pub fn home ( target_directory : & Path , config : & Config ) -> Result < Home > {
73
- let path = if let Some ( ref p) = config. sysroot_path {
74
- let path = Path :: new ( p) ;
75
- fs:: create_dir_all ( & path) . map_err ( |_| String :: from ( "Could not create sysroot folder" ) ) ?;
76
- path. canonicalize ( ) . map_err ( |_| String :: from ( "Invalid sysroot path" ) ) ?
77
- } else {
78
- let mut p = PathBuf :: from ( target_directory) ;
79
- p. push ( "sysroot" ) ;
80
- p
81
- } ;
72
+ pub fn home ( root : & Path , config : & Config ) -> Result < Home > {
73
+ let mut path = PathBuf :: from ( root) ;
74
+ path. push ( & config. sysroot_path ) ;
82
75
83
76
Ok ( Home {
84
77
path : Filesystem :: new ( path) ,
You can’t perform that action at this time.
0 commit comments