@@ -568,12 +568,30 @@ pub(crate) fn register(engine: &Engine, target: &Target, msg_info: &mut MessageI
568568 docker. run ( msg_info, false ) . map_err ( Into :: into)
569569}
570570
571- fn validate_env_var ( var : & str ) -> Result < ( & str , Option < & str > ) > {
571+ fn validate_env_var < ' a > (
572+ var : & ' a str ,
573+ warned : & mut bool ,
574+ var_type : & ' static str ,
575+ var_syntax : & ' static str ,
576+ msg_info : & mut MessageInfo ,
577+ ) -> Result < ( & ' a str , Option < & ' a str > ) > {
572578 let ( key, value) = match var. split_once ( '=' ) {
573579 Some ( ( key, value) ) => ( key, Some ( value) ) ,
574580 _ => ( var, None ) ,
575581 } ;
576582
583+ if value. is_none ( )
584+ && !* warned
585+ && !var
586+ . chars ( )
587+ . all ( |c| matches ! ( c, 'a' ..='z' | 'A' ..='Z' | '_' ) )
588+ {
589+ msg_info. warn ( format_args ! (
590+ "got {var_type} of \" {var}\" which is not a valid environment variable name. the proper syntax is {var_syntax}"
591+ ) ) ?;
592+ * warned = true ;
593+ }
594+
577595 if key == "CROSS_RUNNER" {
578596 eyre:: bail!(
579597 "CROSS_RUNNER environment variable name is reserved and cannot be pass through"
@@ -631,12 +649,19 @@ pub(crate) fn docker_envvars(
631649 dirs : & ToolchainDirectories ,
632650 msg_info : & mut MessageInfo ,
633651) -> Result < ( ) > {
652+ let mut warned = false ;
634653 for ref var in options
635654 . config
636655 . env_passthrough ( & options. target ) ?
637656 . unwrap_or_default ( )
638657 {
639- validate_env_var ( var) ?;
658+ validate_env_var (
659+ var,
660+ & mut warned,
661+ "environment variable" ,
662+ "`passthrough = [\" ENVVAR=value\" ]`" ,
663+ msg_info,
664+ ) ?;
640665
641666 // Only specifying the environment variable name in the "-e"
642667 // flag forwards the value from the parent shell
@@ -714,13 +739,21 @@ pub(crate) fn docker_mount(
714739 paths : & DockerPaths ,
715740 mount_cb : impl Fn ( & mut Command , & Path , & Path ) -> Result < ( ) > ,
716741 mut store_cb : impl FnMut ( ( String , String ) ) ,
742+ msg_info : & mut MessageInfo ,
717743) -> Result < ( ) > {
744+ let mut warned = false ;
718745 for ref var in options
719746 . config
720747 . env_volumes ( & options. target ) ?
721748 . unwrap_or_default ( )
722749 {
723- let ( var, value) = validate_env_var ( var) ?;
750+ let ( var, value) = validate_env_var (
751+ var,
752+ & mut warned,
753+ "volume" ,
754+ "`volumes = [\" ENVVAR=/path/to/directory\" ]`" ,
755+ msg_info,
756+ ) ?;
724757 let value = match value {
725758 Some ( v) => Ok ( v. to_owned ( ) ) ,
726759 None => env:: var ( var) ,
0 commit comments