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 11use serde_json;
22use cargo_metadata;
3+ use std:: path:: PathBuf ;
34
4- #[ derive( Debug , Deserialize , Hash ) ]
5+ #[ derive( Debug , Hash ) ]
56pub struct Config {
67 pub memcpy : bool ,
7- pub sysroot_path : Option < String > ,
8+ pub sysroot_path : PathBuf ,
89}
910
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 > ,
1715}
1816
1917impl Config {
2018 pub fn from_metadata ( metadata : & cargo_metadata:: Metadata ) -> Result < Config , serde_json:: Error > {
2119 let package_metadata = metadata. packages . first ( ) . map ( |p| & p. metadata ) ;
2220 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+ } )
2730 }
2831}
Original file line number Diff line number Diff line change @@ -147,7 +147,6 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
147147 let metadata =
148148 cargo_metadata:: metadata ( args. manifest_path ( ) ) . expect ( "cargo metadata invocation failed" ) ;
149149 let root = Path :: new ( & metadata. workspace_root ) ;
150- let target_directory = Path :: new ( & metadata. target_directory ) ;
151150 let crate_config = config:: Config :: from_metadata ( & metadata)
152151 . map_err ( |_| "parsing package.metadata.cargo-xbuild section failed" ) ?;
153152
@@ -193,7 +192,7 @@ fn build(args: cli::Args) -> Result<(ExitStatus)> {
193192 } ;
194193
195194 if let Some ( cmode) = cmode {
196- let home = xargo:: home ( target_directory , & crate_config) ?;
195+ let home = xargo:: home ( root , & crate_config) ?;
197196 let rustflags = cargo:: rustflags ( config. as_ref ( ) , cmode. triple ( ) ) ?;
198197
199198 sysroot:: update (
Original file line number Diff line number Diff line change 11use std:: path:: { Display , PathBuf } ;
22use std:: process:: { Command , ExitStatus } ;
3- use std:: { fs , mem} ;
3+ use std:: mem;
44use std:: io:: { self , Write } ;
55use std:: path:: Path ;
66
@@ -69,16 +69,9 @@ impl Home {
6969 }
7070}
7171
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 ) ;
8275
8376 Ok ( Home {
8477 path : Filesystem :: new ( path) ,
You can’t perform that action at this time.
0 commit comments