@@ -16,6 +16,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
1616use std:: borrow:: Cow ;
1717use std:: env;
1818use std:: mem;
19+ use std:: path:: Path ;
1920use tracing:: { debug, instrument, warn} ;
2021
2122#[ derive( Debug , Default , PartialEq ) ]
@@ -580,8 +581,8 @@ impl<'graph> TokenExpander<'graph> {
580581 "arch" => Cow :: Borrowed ( env:: consts:: ARCH ) ,
581582 "os" => Cow :: Borrowed ( env:: consts:: OS ) ,
582583 "osFamily" => Cow :: Borrowed ( env:: consts:: FAMILY ) ,
583- "workingDir" => Cow :: Owned ( path :: to_string ( & self . context . working_dir ) ?) ,
584- "workspaceRoot" => Cow :: Owned ( path :: to_string ( & self . context . workspace_root ) ?) ,
584+ "workingDir" => Cow :: Owned ( self . stringify_path ( & self . context . working_dir ) ?) ,
585+ "workspaceRoot" => Cow :: Owned ( self . stringify_path ( & self . context . workspace_root ) ?) ,
585586 // Project
586587 "language" => Cow :: Owned ( project. language . to_string ( ) ) ,
587588 "project" => Cow :: Borrowed ( project. id . as_str ( ) ) ,
@@ -592,7 +593,7 @@ impl<'graph> TokenExpander<'graph> {
592593 "projectChannel" => get_metadata ( |md| md. channel . as_deref ( ) ) ,
593594 "projectName" => get_metadata ( |md| md. name . as_deref ( ) ) ,
594595 "projectOwner" => get_metadata ( |md| md. owner . as_deref ( ) ) ,
595- "projectRoot" => Cow :: Owned ( path :: to_string ( & project. root ) ?) ,
596+ "projectRoot" => Cow :: Owned ( self . stringify_path ( & project. root ) ?) ,
596597 "projectSource" => Cow :: Borrowed ( project. source . as_str ( ) ) ,
597598 "projectStack" => Cow :: Owned ( project. stack . to_string ( ) ) ,
598599 "projectType" => Cow :: Owned ( project. type_of . to_string ( ) ) ,
@@ -738,10 +739,33 @@ impl<'graph> TokenExpander<'graph> {
738739 } else {
739740 let abs_path = path. to_logical_path ( & self . context . workspace_root ) ;
740741
741- path :: to_virtual_string ( diff_paths ( & abs_path, & self . project . root ) . unwrap_or ( abs_path) )
742+ self . stringify_path ( & diff_paths ( & abs_path, & self . project . root ) . unwrap_or ( abs_path) )
742743 }
743744 }
744745
746+ fn stringify_path ( & self , orig_value : & Path ) -> miette:: Result < String > {
747+ let value = path:: to_string ( orig_value) ?;
748+
749+ // https://cygwin.com/cygwin-ug-net/cygpath.html
750+ #[ cfg( windows) ]
751+ if env:: var ( "MSYSTEM" ) . is_ok_and ( |value| value == "MINGW32" || value == "MINGW64" ) {
752+ let mut value = moon_common:: path:: standardize_separators ( value) ;
753+
754+ if orig_value. is_absolute ( ) {
755+ for drive in 'A' ..='Z' {
756+ if let Some ( suffix) = value. strip_prefix ( & format ! ( "{drive}:/" ) ) {
757+ value = format ! ( "/{}/{suffix}" , drive. to_ascii_lowercase( ) ) ;
758+ break ;
759+ }
760+ }
761+ }
762+
763+ return Ok ( value) ;
764+ }
765+
766+ Ok ( value)
767+ }
768+
745769 fn infer_inputs ( & self , task : & mut Task , result : & ExpandedResult ) {
746770 if task. options . infer_inputs {
747771 task. input_files . extend ( result. files . clone ( ) ) ;
0 commit comments