@@ -616,21 +616,24 @@ def testWindowsNativeLauncherInLongPath(self):
616616 if not self .IsWindows ():
617617 return
618618 self .CreateWorkspaceWithDefaultRepos ('WORKSPACE' )
619- self .ScratchFile ('bin/BUILD' , [
620- 'java_binary(' ,
621- ' name = "bin_java",' ,
622- ' srcs = ["Main.java"],' ,
623- ' main_class = "Main",' ,
624- ')' ,
625- 'sh_binary(' ,
626- ' name = "bin_sh",' ,
627- ' srcs = ["main.sh"],' ,
628- ')' ,
629- 'py_binary(' ,
630- ' name = "bin_py",' ,
631- ' srcs = ["bin_py.py"],' ,
632- ')' ,
633- ])
619+ self .ScratchFile (
620+ 'bin/BUILD' ,
621+ [
622+ 'java_binary(' ,
623+ ' name = "not_short_bin_java",' ,
624+ ' srcs = ["Main.java"],' ,
625+ ' main_class = "Main",' ,
626+ ')' ,
627+ 'sh_binary(' ,
628+ ' name = "not_short_bin_sh",' ,
629+ ' srcs = ["main.sh"],' ,
630+ ')' ,
631+ 'py_binary(' ,
632+ ' name = "not_short_bin_py",' ,
633+ ' srcs = ["not_short_bin_py.py"],' ,
634+ ')' ,
635+ ],
636+ )
634637 self .ScratchFile ('bin/Main.java' , [
635638 'public class Main {' ,
636639 ' public static void main(String[] args) {'
@@ -641,9 +644,12 @@ def testWindowsNativeLauncherInLongPath(self):
641644 self .ScratchFile ('bin/main.sh' , [
642645 'echo "helloworld"' ,
643646 ])
644- self .ScratchFile ('bin/bin_py.py' , [
645- 'print("helloworld")' ,
646- ])
647+ self .ScratchFile (
648+ 'bin/not_short_bin_py.py' ,
649+ [
650+ 'print("helloworld")' ,
651+ ],
652+ )
647653
648654 exit_code , stdout , stderr = self .RunBazel (['info' , 'bazel-bin' ])
649655 self .AssertExitCode (exit_code , 0 , stderr )
@@ -656,52 +662,133 @@ def testWindowsNativeLauncherInLongPath(self):
656662 long_dir_path = './' + '/' .join (
657663 [(c * 8 + '.' + c * 3 ) for c in string .ascii_lowercase ])
658664
665+ # The 'not_short_' prefix ensures that the basenames are not already 8.3
666+ # short paths. Due to the long directory path, the basename will thus be
667+ # replaced with a short path such as "not_sh~1.exe" below.
659668 for f in [
660- 'bin_java .exe' ,
661- 'bin_java .exe.runfiles_manifest' ,
662- 'bin_sh .exe' ,
663- 'bin_sh ' ,
664- 'bin_sh .exe.runfiles_manifest' ,
665- 'bin_py .exe' ,
666- 'bin_py .zip' ,
667- 'bin_py .exe.runfiles_manifest' ,
669+ 'not_short_bin_java .exe' ,
670+ 'not_short_bin_java .exe.runfiles_manifest' ,
671+ 'not_short_bin_sh .exe' ,
672+ 'not_short_bin_sh ' ,
673+ 'not_short_bin_sh .exe.runfiles_manifest' ,
674+ 'not_short_bin_py .exe' ,
675+ 'not_short_bin_py .zip' ,
676+ 'not_short_bin_py .exe.runfiles_manifest' ,
668677 ]:
669678 self .CopyFile (
670679 os .path .join (bazel_bin , 'bin' , f ), os .path .join (long_dir_path , f ))
671680
672- long_binary_path = os .path .abspath (long_dir_path + '/bin_java.exe' )
681+ long_binary_path = os .path .abspath (
682+ long_dir_path + '/not_short_bin_java.exe'
683+ )
673684 # subprocess doesn't support long path without shell=True
674685 exit_code , stdout , stderr = self .RunProgram ([long_binary_path ], shell = True )
675686 self .AssertExitCode (exit_code , 0 , stderr )
676687 self .assertEqual ('helloworld' , '' .join (stdout ))
677688 # Make sure we can launch the binary with a shortened Windows 8dot3 path
678689 short_binary_path = win32api .GetShortPathName (long_binary_path )
690+ self .assertIn ('~' , os .path .basename (short_binary_path ))
679691 exit_code , stdout , stderr = self .RunProgram ([short_binary_path ], shell = True )
680692 self .AssertExitCode (exit_code , 0 , stderr )
681693 self .assertEqual ('helloworld' , '' .join (stdout ))
682694
683- long_binary_path = os .path .abspath (long_dir_path + '/bin_sh .exe' )
695+ long_binary_path = os .path .abspath (long_dir_path + '/not_short_bin_sh .exe' )
684696 # subprocess doesn't support long path without shell=True
685697 exit_code , stdout , stderr = self .RunProgram ([long_binary_path ], shell = True )
686698 self .AssertExitCode (exit_code , 0 , stderr )
687699 self .assertEqual ('helloworld' , '' .join (stdout ))
688700 # Make sure we can launch the binary with a shortened Windows 8dot3 path
689701 short_binary_path = win32api .GetShortPathName (long_binary_path )
702+ self .assertIn ('~' , os .path .basename (short_binary_path ))
690703 exit_code , stdout , stderr = self .RunProgram ([short_binary_path ], shell = True )
691704 self .AssertExitCode (exit_code , 0 , stderr )
692705 self .assertEqual ('helloworld' , '' .join (stdout ))
693706
694- long_binary_path = os .path .abspath (long_dir_path + '/bin_py .exe' )
707+ long_binary_path = os .path .abspath (long_dir_path + '/not_short_bin_py .exe' )
695708 # subprocess doesn't support long path without shell=True
696709 exit_code , stdout , stderr = self .RunProgram ([long_binary_path ], shell = True )
697710 self .AssertExitCode (exit_code , 0 , stderr )
698711 self .assertEqual ('helloworld' , '' .join (stdout ))
699712 # Make sure we can launch the binary with a shortened Windows 8dot3 path
700713 short_binary_path = win32api .GetShortPathName (long_binary_path )
714+ self .assertIn ('~' , os .path .basename (short_binary_path ))
701715 exit_code , stdout , stderr = self .RunProgram ([short_binary_path ], shell = True )
702716 self .AssertExitCode (exit_code , 0 , stderr )
703717 self .assertEqual ('helloworld' , '' .join (stdout ))
704718
719+ def testWindowsNativeLauncherInvalidArgv0 (self ):
720+ if not self .IsWindows ():
721+ return
722+ self .CreateWorkspaceWithDefaultRepos ('WORKSPACE' )
723+ self .ScratchFile (
724+ 'bin/BUILD' ,
725+ [
726+ 'java_binary(' ,
727+ ' name = "bin_java",' ,
728+ ' srcs = ["Main.java"],' ,
729+ ' main_class = "Main",' ,
730+ ')' ,
731+ 'sh_binary(' ,
732+ ' name = "bin_sh",' ,
733+ ' srcs = ["main.sh"],' ,
734+ ')' ,
735+ 'py_binary(' ,
736+ ' name = "bin_py",' ,
737+ ' srcs = ["bin_py.py"],' ,
738+ ')' ,
739+ ],
740+ )
741+ self .ScratchFile (
742+ 'bin/Main.java' ,
743+ [
744+ 'public class Main {' ,
745+ (
746+ ' public static void main(String[] args) {'
747+ ' System.out.println("helloworld");'
748+ ),
749+ ' }' ,
750+ '}' ,
751+ ],
752+ )
753+ self .ScratchFile (
754+ 'bin/main.sh' ,
755+ [
756+ 'echo "helloworld"' ,
757+ ],
758+ )
759+ self .ScratchFile (
760+ 'bin/bin_py.py' ,
761+ [
762+ 'print("helloworld")' ,
763+ ],
764+ )
765+
766+ exit_code , stdout , stderr = self .RunBazel (['info' , 'bazel-bin' ])
767+ self .AssertExitCode (exit_code , 0 , stderr )
768+ bazel_bin = stdout [0 ]
769+
770+ exit_code , _ , stderr = self .RunBazel (['build' , '//bin/...' ])
771+ self .AssertExitCode (exit_code , 0 , stderr )
772+
773+ exit_code , stdout , stderr = self .RunProgram (
774+ ['C:\\ Invalid' ],
775+ executable = os .path .join (bazel_bin , 'bin' , 'bin_java.exe' ),
776+ )
777+ self .AssertExitCode (exit_code , 0 , stderr )
778+ self .assertEqual ('helloworld' , '' .join (stdout ))
779+
780+ exit_code , stdout , stderr = self .RunProgram (
781+ ['C:\\ Invalid' ], executable = os .path .join (bazel_bin , 'bin' , 'bin_sh.exe' )
782+ )
783+ self .AssertExitCode (exit_code , 0 , stderr )
784+ self .assertEqual ('helloworld' , '' .join (stdout ))
785+
786+ exit_code , stdout , stderr = self .RunProgram (
787+ ['C:\\ Invalid' ], executable = os .path .join (bazel_bin , 'bin' , 'bin_py.exe' )
788+ )
789+ self .AssertExitCode (exit_code , 0 , stderr )
790+ self .assertEqual ('helloworld' , '' .join (stdout ))
791+
705792 def AssertRunfilesManifestContains (self , manifest , entry ):
706793 with open (manifest , 'r' ) as f :
707794 for l in f :
0 commit comments