11use std:: any:: Any ;
2+ use std:: borrow:: Cow ;
23use std:: cell:: { Cell , RefCell } ;
34use std:: collections:: BTreeSet ;
45use std:: env;
@@ -50,7 +51,7 @@ impl<'a> Deref for Builder<'a> {
5051 }
5152}
5253
53- pub trait Step : ' static + Clone + Debug + PartialEq + Eq + Hash {
54+ pub ( crate ) trait Step : ' static + Clone + Debug + PartialEq + Eq + Hash {
5455 /// `PathBuf` when directories are created or to return a `Compiler` once
5556 /// it's been assembled.
5657 type Output : Clone ;
@@ -67,15 +68,7 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
6768 std:: any:: type_name :: < Self > ( )
6869 }
6970
70- // fn kind(&self) -> Kind;
71-
72- fn compiler ( & self ) -> Option < & Compiler > {
73- None
74- }
75-
76- fn target ( & self ) -> Option < & TargetSelection > {
77- None
78- }
71+ fn info ( _step_info : & mut StepInfo < ' _ , ' _ , Self > ) { }
7972
8073 /// The path that should be used on the command line to run this step.
8174 fn path ( & self , builder : & Builder < ' _ > ) -> PathBuf {
@@ -656,37 +649,10 @@ impl<'a> Builder<'a> {
656649 StepDescription :: run ( v, self , paths) ;
657650 }
658651
659- /// Print a command that will run the current step.
660- ///
661- /// This serves two purposes:
662- /// 1. Describe what step is currently being run.
663- /// 2. Describe how to run only this step in case it fails.
664652 pub ( crate ) fn step_info ( & self , step : & impl Step ) {
665- if self . config . dry_run {
666- return ;
667- }
668- let ( stage, host) = if let Some ( compiler) = step. compiler ( ) {
669- ( compiler. stage , Some ( compiler. host ) )
670- } else {
671- ( self . top_stage , None )
672- } ;
673- print ! (
674- "{} {} --stage {}" ,
675- // TODO: this is wrong, e.g. `check --stage 1` runs build commands first
676- self . kind,
677- step. path( self ) . display( ) ,
678- stage,
679- ) ;
680- if let Some ( host) = host {
681- print ! ( " --host {}" , host) ;
682- }
683- if let Some ( target) = step. target ( ) {
684- print ! ( " --target {}" , target) ;
685- }
686- for arg in self . config . cmd . test_args ( ) {
687- print ! ( " --test-args \" {}\" " , arg) ;
688- }
689- println ! ( ) ;
653+ let mut info = StepInfo :: new ( self , step) ;
654+ Step :: info ( & mut info) ;
655+ info. print ( ) ;
690656 }
691657
692658 /// Obtain a compiler at a given stage and for a given host. Explicitly does
@@ -1611,7 +1577,7 @@ impl<'a> Builder<'a> {
16111577 /// Ensure that a given step is built, returning its output. This will
16121578 /// cache the step, so it is safe (and good!) to call this as often as
16131579 /// needed to ensure that all dependencies are built.
1614- pub fn ensure < S : Step > ( & ' a self , step : S ) -> S :: Output {
1580+ pub ( crate ) fn ensure < S : Step > ( & ' a self , step : S ) -> S :: Output {
16151581 {
16161582 let mut stack = self . stack . borrow_mut ( ) ;
16171583 for stack_step in stack. iter ( ) {
@@ -1772,3 +1738,105 @@ impl From<Cargo> for Command {
17721738 cargo. command
17731739 }
17741740}
1741+
1742+ pub ( crate ) struct StepInfo < ' a , ' b , S > {
1743+ pub ( crate ) builder : & ' a Builder < ' b > ,
1744+ pub ( crate ) step : & ' a S ,
1745+ compiler : Option < Cow < ' a , Compiler > > ,
1746+ stage : Option < u32 > ,
1747+ host : Option < TargetSelection > ,
1748+ target : Option < TargetSelection > ,
1749+ cmd : Option < Kind > ,
1750+ }
1751+
1752+ impl < ' a > From < Compiler > for Cow < ' a , Compiler > {
1753+ fn from ( val : Compiler ) -> Self {
1754+ Self :: Owned ( val)
1755+ }
1756+ }
1757+
1758+ impl < ' a > From < & ' a Compiler > for Cow < ' a , Compiler > {
1759+ fn from ( val : & ' a Compiler ) -> Self {
1760+ Self :: Borrowed ( val)
1761+ }
1762+ }
1763+
1764+ impl < ' a , ' b , S > StepInfo < ' a , ' b , S > {
1765+ pub ( crate ) fn new ( builder : & ' a Builder < ' b > , step : & ' a S ) -> Self {
1766+ Self { builder, step, compiler : None , stage : None , host : None , target : None , cmd : None }
1767+ }
1768+
1769+ pub ( crate ) fn compiler ( & mut self , val : impl Into < Cow < ' a , Compiler > > ) -> & mut Self {
1770+ if self . compiler . is_some ( ) {
1771+ panic ! ( "cannot overwrite compiler" ) ;
1772+ }
1773+ let val = val. into ( ) ;
1774+ self . stage ( val. stage ) . host ( val. host ) ;
1775+ self . compiler = Some ( val) ;
1776+ self
1777+ }
1778+
1779+ pub ( crate ) fn stage ( & mut self , stage : u32 ) -> & mut Self {
1780+ if self . stage . is_some ( ) {
1781+ panic ! ( "cannot overwrite stage" ) ;
1782+ }
1783+ self . stage = Some ( stage) ;
1784+ self
1785+ }
1786+
1787+ pub ( crate ) fn host ( & mut self , host : TargetSelection ) -> & mut Self {
1788+ if self . host . is_some ( ) {
1789+ panic ! ( "cannot overwrite host" ) ;
1790+ }
1791+ self . host = Some ( host) ;
1792+ self
1793+ }
1794+
1795+ pub ( crate ) fn target ( & mut self , target : TargetSelection ) -> & mut Self {
1796+ if self . target . is_some ( ) {
1797+ panic ! ( "cannot overwrite target" ) ;
1798+ }
1799+ self . target = Some ( target) ;
1800+ self
1801+ }
1802+
1803+ pub ( crate ) fn cmd ( & mut self , val : Kind ) -> & mut Self {
1804+ if self . cmd . is_some ( ) {
1805+ panic ! ( "cannot overwrite cmd" ) ;
1806+ }
1807+ self . cmd = Some ( val) ;
1808+ self
1809+ }
1810+
1811+ /// Print a command that will run the current step.
1812+ ///
1813+ /// This serves two purposes:
1814+ /// 1. Describe what step is currently being run.
1815+ /// 2. Describe how to run only this step in case it fails.
1816+ pub ( crate ) fn print ( & self )
1817+ where
1818+ S : Step ,
1819+ {
1820+ if self . builder . config . dry_run {
1821+ return ;
1822+ }
1823+ // let stage = self.stage.unwrap_or(self.builder.top_stage);
1824+ let stage = self . stage . expect ( "missing stage" ) ;
1825+ let host = self . host ;
1826+ let kind = self . cmd . unwrap_or ( self . builder . kind ) ;
1827+ let target = self . target ;
1828+ print ! ( "{} {} --stage {}" , kind, self . step. path( self . builder) . display( ) , stage, ) ;
1829+ if let Some ( host) = host {
1830+ print ! ( " --host {}" , host) ;
1831+ }
1832+ if let Some ( target) = target {
1833+ print ! ( " --target {}" , target) ;
1834+ }
1835+ if kind == Kind :: Test {
1836+ for arg in self . builder . config . cmd . test_args ( ) {
1837+ print ! ( " --test-args \" {}\" " , arg) ;
1838+ }
1839+ }
1840+ println ! ( ) ;
1841+ }
1842+ }
0 commit comments