@@ -616,21 +616,24 @@ def testWindowsNativeLauncherInLongPath(self):
616
616
if not self .IsWindows ():
617
617
return
618
618
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
+ )
634
637
self .ScratchFile ('bin/Main.java' , [
635
638
'public class Main {' ,
636
639
' public static void main(String[] args) {'
@@ -641,9 +644,12 @@ def testWindowsNativeLauncherInLongPath(self):
641
644
self .ScratchFile ('bin/main.sh' , [
642
645
'echo "helloworld"' ,
643
646
])
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
+ )
647
653
648
654
exit_code , stdout , stderr = self .RunBazel (['info' , 'bazel-bin' ])
649
655
self .AssertExitCode (exit_code , 0 , stderr )
@@ -656,52 +662,133 @@ def testWindowsNativeLauncherInLongPath(self):
656
662
long_dir_path = './' + '/' .join (
657
663
[(c * 8 + '.' + c * 3 ) for c in string .ascii_lowercase ])
658
664
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.
659
668
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' ,
668
677
]:
669
678
self .CopyFile (
670
679
os .path .join (bazel_bin , 'bin' , f ), os .path .join (long_dir_path , f ))
671
680
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
+ )
673
684
# subprocess doesn't support long path without shell=True
674
685
exit_code , stdout , stderr = self .RunProgram ([long_binary_path ], shell = True )
675
686
self .AssertExitCode (exit_code , 0 , stderr )
676
687
self .assertEqual ('helloworld' , '' .join (stdout ))
677
688
# Make sure we can launch the binary with a shortened Windows 8dot3 path
678
689
short_binary_path = win32api .GetShortPathName (long_binary_path )
690
+ self .assertIn ('~' , os .path .basename (short_binary_path ))
679
691
exit_code , stdout , stderr = self .RunProgram ([short_binary_path ], shell = True )
680
692
self .AssertExitCode (exit_code , 0 , stderr )
681
693
self .assertEqual ('helloworld' , '' .join (stdout ))
682
694
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' )
684
696
# subprocess doesn't support long path without shell=True
685
697
exit_code , stdout , stderr = self .RunProgram ([long_binary_path ], shell = True )
686
698
self .AssertExitCode (exit_code , 0 , stderr )
687
699
self .assertEqual ('helloworld' , '' .join (stdout ))
688
700
# Make sure we can launch the binary with a shortened Windows 8dot3 path
689
701
short_binary_path = win32api .GetShortPathName (long_binary_path )
702
+ self .assertIn ('~' , os .path .basename (short_binary_path ))
690
703
exit_code , stdout , stderr = self .RunProgram ([short_binary_path ], shell = True )
691
704
self .AssertExitCode (exit_code , 0 , stderr )
692
705
self .assertEqual ('helloworld' , '' .join (stdout ))
693
706
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' )
695
708
# subprocess doesn't support long path without shell=True
696
709
exit_code , stdout , stderr = self .RunProgram ([long_binary_path ], shell = True )
697
710
self .AssertExitCode (exit_code , 0 , stderr )
698
711
self .assertEqual ('helloworld' , '' .join (stdout ))
699
712
# Make sure we can launch the binary with a shortened Windows 8dot3 path
700
713
short_binary_path = win32api .GetShortPathName (long_binary_path )
714
+ self .assertIn ('~' , os .path .basename (short_binary_path ))
701
715
exit_code , stdout , stderr = self .RunProgram ([short_binary_path ], shell = True )
702
716
self .AssertExitCode (exit_code , 0 , stderr )
703
717
self .assertEqual ('helloworld' , '' .join (stdout ))
704
718
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
+
705
792
def AssertRunfilesManifestContains (self , manifest , entry ):
706
793
with open (manifest , 'r' ) as f :
707
794
for l in f :
0 commit comments