@@ -18,8 +18,9 @@ use std::str::FromStr;
18
18
19
19
use anyhow:: { anyhow, bail, Context , Result } ;
20
20
21
- use crate :: dist:: dist:: { PartialTargetTriple , Profile , TargetTriple } ;
21
+ use crate :: dist:: dist:: { Profile , TargetTriple } ;
22
22
use crate :: errors:: * ;
23
+ use crate :: toolchain:: distributable:: DistributableToolchain ;
23
24
use crate :: utils:: toml_utils:: * ;
24
25
25
26
use super :: { config:: Config , dist:: ToolchainDesc } ;
@@ -588,21 +589,37 @@ impl Component {
588
589
}
589
590
}
590
591
591
- pub ( crate ) fn new_with_target ( pkg_with_target : & str , is_extension : bool ) -> Option < Self > {
592
- for ( pos, _) in pkg_with_target. match_indices ( '-' ) {
593
- let pkg = & pkg_with_target[ 0 ..pos] ;
594
- let target = & pkg_with_target[ pos + 1 ..] ;
595
- if let Some ( partial) = PartialTargetTriple :: new ( target) {
596
- if let Ok ( triple) = TargetTriple :: try_from ( partial) {
597
- return Some ( Self {
598
- pkg : pkg. to_string ( ) ,
599
- target : Some ( triple) ,
600
- is_extension,
601
- } ) ;
602
- }
592
+ pub ( crate ) fn try_new (
593
+ name : & str ,
594
+ distributable : & DistributableToolchain < ' _ > ,
595
+ fallback_target : Option < & TargetTriple > ,
596
+ ) -> Result < Self > {
597
+ let manifestation = distributable. get_manifestation ( ) ?;
598
+ let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
599
+ let manifest = distributable. get_manifest ( ) ?;
600
+ let manifest_components = manifest. query_components ( distributable. desc ( ) , & config) ?;
601
+
602
+ for component_status in manifest_components {
603
+ let short_name = component_status. component . short_name_in_manifest ( ) ;
604
+ let target = component_status. component . target . as_ref ( ) ;
605
+
606
+ if name. starts_with ( short_name)
607
+ && target. is_some ( )
608
+ && name == format ! ( "{}-{}" , short_name, target. unwrap( ) )
609
+ {
610
+ return Ok ( Component :: new (
611
+ short_name. to_string ( ) ,
612
+ target. cloned ( ) ,
613
+ false ,
614
+ ) ) ;
603
615
}
604
616
}
605
- None
617
+
618
+ Ok ( Component :: new (
619
+ name. to_string ( ) ,
620
+ fallback_target. cloned ( ) ,
621
+ true ,
622
+ ) )
606
623
}
607
624
608
625
pub ( crate ) fn wildcard ( & self ) -> Self {
0 commit comments