@@ -70,7 +70,7 @@ def change_dir(self, newdir):
7070 if os .path .isabs (newdir ):
7171 self .cwd = newdir
7272 else :
73- self .cwd = os . path . realpath (os .path .join (self .cwd , newdir ))
73+ self .cwd = lit . util . abs_path_preserve_drive (os .path .join (self .cwd , newdir ))
7474
7575class TimeoutHelper (object ):
7676 """
@@ -401,7 +401,7 @@ def executeBuiltinMkdir(cmd, cmd_shenv):
401401 dir = to_unicode (dir ) if kIsWindows else to_bytes (dir )
402402 cwd = to_unicode (cwd ) if kIsWindows else to_bytes (cwd )
403403 if not os .path .isabs (dir ):
404- dir = os . path . realpath (os .path .join (cwd , dir ))
404+ dir = lit . util . abs_path_preserve_drive (os .path .join (cwd , dir ))
405405 if parent :
406406 lit .util .mkdir_p (dir )
407407 else :
@@ -446,7 +446,7 @@ def on_rm_error(func, path, exc_info):
446446 path = to_unicode (path ) if kIsWindows else to_bytes (path )
447447 cwd = to_unicode (cwd ) if kIsWindows else to_bytes (cwd )
448448 if not os .path .isabs (path ):
449- path = os . path . realpath (os .path .join (cwd , path ))
449+ path = lit . util . abs_path_preserve_drive (os .path .join (cwd , path ))
450450 if force and not os .path .exists (path ):
451451 continue
452452 try :
@@ -1153,58 +1153,59 @@ def getDefaultSubstitutions(test, tmpDir, tmpBase, normalize_slashes=False):
11531153 substitutions .extend (test .config .substitutions )
11541154 tmpName = tmpBase + '.tmp'
11551155 baseName = os .path .basename (tmpBase )
1156- substitutions .extend ([('%s' , sourcepath ),
1157- ('%S' , sourcedir ),
1158- ('%p' , sourcedir ),
1159- ('%{pathsep}' , os .pathsep ),
1160- ('%t' , tmpName ),
1161- ('%basename_t' , baseName ),
1162- ('%T' , tmpDir )])
1163-
1164- substitutions .extend ([
1165- ('%{fs-src-root}' , pathlib .Path (sourcedir ).anchor ),
1166- ('%{fs-tmp-root}' , pathlib .Path (tmpBase ).anchor ),
1167- ('%{fs-sep}' , os .path .sep ),
1168- ])
1169-
1170- # "%/[STpst]" should be normalized.
1171- substitutions .extend ([
1172- ('%/s' , sourcepath .replace ('\\ ' , '/' )),
1173- ('%/S' , sourcedir .replace ('\\ ' , '/' )),
1174- ('%/p' , sourcedir .replace ('\\ ' , '/' )),
1175- ('%/t' , tmpBase .replace ('\\ ' , '/' ) + '.tmp' ),
1176- ('%/T' , tmpDir .replace ('\\ ' , '/' )),
1177- ('%/et' ,tmpName .replace ('\\ ' , '\\ \\ \\ \\ \\ \\ \\ \\ ' )),
1178- ])
1179-
1180- # "%{/[STpst]:regex_replacement}" should be normalized like "%/[STpst]" but we're
1181- # also in a regex replacement context of a s@@@ regex.
1156+
1157+ substitutions .append (("%{pathsep}" , os .pathsep ))
1158+ substitutions .append (("%basename_t" , baseName ))
1159+
1160+ substitutions .extend (
1161+ [
1162+ ("%{fs-src-root}" , pathlib .Path (sourcedir ).anchor ),
1163+ ("%{fs-tmp-root}" , pathlib .Path (tmpBase ).anchor ),
1164+ ("%{fs-sep}" , os .path .sep ),
1165+ ]
1166+ )
1167+
1168+ substitutions .append (("%/et" , tmpName .replace ("\\ " , "\\ \\ \\ \\ \\ \\ \\ \\ " )))
1169+
11821170 def regex_escape (s ):
11831171 s = s .replace ('@' , r'\@' )
11841172 s = s .replace ('&' , r'\&' )
11851173 return s
1186- substitutions .extend ([
1187- ('%{/s:regex_replacement}' ,
1188- regex_escape (sourcepath .replace ('\\ ' , '/' ))),
1189- ('%{/S:regex_replacement}' ,
1190- regex_escape (sourcedir .replace ('\\ ' , '/' ))),
1191- ('%{/p:regex_replacement}' ,
1192- regex_escape (sourcedir .replace ('\\ ' , '/' ))),
1193- ('%{/t:regex_replacement}' ,
1194- regex_escape (tmpBase .replace ('\\ ' , '/' )) + '.tmp' ),
1195- ('%{/T:regex_replacement}' ,
1196- regex_escape (tmpDir .replace ('\\ ' , '/' ))),
1197- ])
1198-
1199- # "%:[STpst]" are normalized paths without colons and without a leading
1200- # slash.
1201- substitutions .extend ([
1202- ('%:s' , colonNormalizePath (sourcepath )),
1203- ('%:S' , colonNormalizePath (sourcedir )),
1204- ('%:p' , colonNormalizePath (sourcedir )),
1205- ('%:t' , colonNormalizePath (tmpBase + '.tmp' )),
1206- ('%:T' , colonNormalizePath (tmpDir )),
1207- ])
1174+
1175+ path_substitutions = [
1176+ ("s" , sourcepath ), ("S" , sourcedir ), ("p" , sourcedir ),
1177+ ("t" , tmpName ), ("T" , tmpDir )
1178+ ]
1179+ for path_substitution in path_substitutions :
1180+ letter = path_substitution [0 ]
1181+ path = path_substitution [1 ]
1182+
1183+ # Original path variant
1184+ substitutions .append (("%" + letter , path ))
1185+
1186+ # Normalized path separator variant
1187+ substitutions .append (("%/" + letter , path .replace ("\\ " , "/" )))
1188+
1189+ # realpath variants
1190+ # Windows paths with substitute drives are not expanded by default
1191+ # as they are used to avoid MAX_PATH issues, but sometimes we do
1192+ # need the fully expanded path.
1193+ real_path = os .path .realpath (path )
1194+ substitutions .append (("%{" + letter + ":real}" , real_path ))
1195+ substitutions .append (("%{/" + letter + ":real}" ,
1196+ real_path .replace ("\\ " , "/" )))
1197+
1198+ # "%{/[STpst]:regex_replacement}" should be normalized like
1199+ # "%/[STpst]" but we're also in a regex replacement context
1200+ # of a s@@@ regex.
1201+ substitutions .append (
1202+ ("%{/" + letter + ":regex_replacement}" ,
1203+ regex_escape (path .replace ("\\ " , "/" ))))
1204+
1205+ # "%:[STpst]" are normalized paths without colons and without
1206+ # a leading slash.
1207+ substitutions .append (("%:" + letter , colonNormalizePath (path )))
1208+
12081209 return substitutions
12091210
12101211def _memoize (f ):
0 commit comments