11//! Provides functions to build the kernel and the bootloader.
22
3+ use crate :: config:: Config ;
34use cargo_metadata:: Metadata ;
45use error:: { BootloaderError , BuildKernelError , BuilderError , CreateBootimageError } ;
56use std:: {
@@ -46,27 +47,17 @@ impl Builder {
4647 pub fn build_kernel (
4748 & mut self ,
4849 args : & [ String ] ,
50+ config : & Config ,
4951 quiet : bool ,
5052 ) -> Result < Vec < PathBuf > , BuildKernelError > {
5153 if !quiet {
5254 println ! ( "Building kernel" ) ;
5355 }
5456
55- let build_arg = if self
56- . project_metadata ( )
57- . ok ( )
58- . and_then ( |m| m. packages . iter ( ) . find ( |p| p. name == "rlibc" ) )
59- . is_some ( )
60- {
61- "build"
62- } else {
63- "xbuild"
64- } ;
65-
6657 // try to run cargo xbuild
6758 let cargo = std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . to_owned ( ) ) ;
6859 let mut cmd = process:: Command :: new ( & cargo) ;
69- cmd. arg ( build_arg ) ;
60+ cmd. args ( & config . build_command ) ;
7061 cmd. args ( args) ;
7162 if !quiet {
7263 cmd. stdout ( process:: Stdio :: inherit ( ) ) ;
@@ -77,7 +68,7 @@ impl Builder {
7768 error : err,
7869 } ) ?;
7970 if !output. status . success ( ) {
80- if build_arg == "xbuild" {
71+ if config . build_command . starts_with ( & [ "xbuild" . into ( ) ] ) {
8172 // try executing `cargo xbuild --help` to check whether cargo-xbuild is installed
8273 let mut help_command = process:: Command :: new ( "cargo" ) ;
8374 help_command. arg ( "xbuild" ) . arg ( "--help" ) ;
@@ -96,7 +87,7 @@ impl Builder {
9687
9788 // Retrieve binary paths
9889 let mut cmd = process:: Command :: new ( cargo) ;
99- cmd. arg ( build_arg ) ;
90+ cmd. args ( & config . build_command ) ;
10091 cmd. args ( args) ;
10192 cmd. arg ( "--message-format" ) . arg ( "json" ) ;
10293 let output = cmd. output ( ) . map_err ( |err| BuildKernelError :: Io {
0 commit comments