@@ -592,94 +592,100 @@ def _jar_path_based_on_java_bin(ctx):
592592
593593def _write_executable (ctx , executable , rjars , main_class , jvm_flags , wrapper , use_jacoco ):
594594 if (_is_windows (ctx )):
595- classpath = ";" .join (
596- [("external/%s" % (j .short_path [3 :]) if j .short_path .startswith ("../" ) else j .short_path ) for j in rjars .to_list ()],
595+ return _write_executable_windows (ctx , executable , rjars , main_class , jvm_flags , wrapper , use_jacoco )
596+ else :
597+ return _write_executable_non_windows (ctx , executable , rjars , main_class , jvm_flags , wrapper , use_jacoco )
598+
599+ def _write_executable_windows (ctx , executable , rjars , main_class , jvm_flags , wrapper , use_jacoco ):
600+ classpath = ";" .join (
601+ [("external/%s" % (j .short_path [3 :]) if j .short_path .startswith ("../" ) else j .short_path ) for j in rjars .to_list ()],
602+ )
603+ jvm_flags_str = ";" .join (jvm_flags )
604+ java_for_exe = str (ctx .attr ._java_runtime [java_common .JavaRuntimeInfo ].java_executable_exec_path )
605+
606+ cpfile = ctx .actions .declare_file ("%s.classpath" % ctx .label .name )
607+ ctx .actions .write (cpfile , classpath )
608+
609+ ctx .actions .run (
610+ outputs = [executable ],
611+ inputs = [cpfile ],
612+ executable = ctx .attr ._exe .files_to_run .executable ,
613+ arguments = [executable .path , ctx .workspace_name , java_for_exe , main_class , cpfile .path , jvm_flags_str ],
614+ mnemonic = "ExeLauncher" ,
615+ progress_message = "Creating exe launcher" ,
616+ )
617+ return []
618+
619+ def _write_executable_non_windows (ctx , executable , rjars , main_class , jvm_flags , wrapper , use_jacoco ):
620+ template = ctx .attr ._java_stub_template .files .to_list ()[0 ]
621+
622+ jvm_flags = " " .join (
623+ [ctx .expand_location (f , ctx .attr .data ) for f in jvm_flags ],
624+ )
625+
626+ javabin = "export REAL_EXTERNAL_JAVA_BIN=${JAVABIN};JAVABIN=%s/%s" % (
627+ _runfiles_root (ctx ),
628+ wrapper .short_path ,
629+ )
630+
631+ if use_jacoco and _coverage_replacements_provider .is_enabled (ctx ):
632+ classpath = ":" .join (
633+ ["${RUNPATH}%s" % (j .short_path ) for j in rjars .to_list () + ctx .files ._jacocorunner + ctx .files ._lcov_merger ],
597634 )
598- jvm_flags_str = ";" .join (jvm_flags )
599- java_for_exe = str (ctx .attr ._java_runtime [java_common .JavaRuntimeInfo ].java_executable_exec_path )
600-
601- cpfile = ctx .actions .declare_file ("%s.classpath" % ctx .label .name )
602- ctx .actions .write (cpfile , classpath )
603-
604- ctx .actions .run (
605- outputs = [executable ],
606- inputs = [cpfile ],
607- executable = ctx .attr ._exe .files_to_run .executable ,
608- arguments = [executable .path , ctx .workspace_name , java_for_exe , main_class , cpfile .path , jvm_flags_str ],
609- mnemonic = "ExeLauncher" ,
610- progress_message = "Creating exe launcher" ,
635+ jacoco_metadata_file = ctx .actions .declare_file (
636+ "%s.jacoco_metadata.txt" % ctx .attr .name ,
637+ sibling = executable ,
611638 )
612- return []
639+ ctx .actions .write (jacoco_metadata_file , "\n " .join ([
640+ jar .short_path .replace ("../" , "external/" )
641+ for jar in rjars
642+ ]))
643+ ctx .actions .expand_template (
644+ template = template ,
645+ output = executable ,
646+ substitutions = {
647+ "%classpath%" : classpath ,
648+ "%javabin%" : javabin ,
649+ "%jarbin%" : _jar_path_based_on_java_bin (ctx ),
650+ "%jvm_flags%" : jvm_flags ,
651+ "%needs_runfiles%" : "" ,
652+ "%runfiles_manifest_only%" : "" ,
653+ "%workspace_prefix%" : ctx .workspace_name + "/" ,
654+ "%java_start_class%" : "com.google.testing.coverage.JacocoCoverageRunner" ,
655+ "%set_jacoco_metadata%" : "export JACOCO_METADATA_JAR=\" $JAVA_RUNFILES/{}/{}\" " .format (ctx .workspace_name , jacoco_metadata_file .short_path ),
656+ "%set_jacoco_main_class%" : """export JACOCO_MAIN_CLASS={}""" .format (main_class ),
657+ "%set_jacoco_java_runfiles_root%" : """export JACOCO_JAVA_RUNFILES_ROOT=$JAVA_RUNFILES/{}/""" .format (ctx .workspace_name ),
658+ "%set_java_coverage_new_implementation%" : """export JAVA_COVERAGE_NEW_IMPLEMENTATION=YES""" ,
659+ },
660+ is_executable = True ,
661+ )
662+ return [jacoco_metadata_file ]
613663 else :
614- template = ctx . attr . _java_stub_template . files . to_list ()[ 0 ]
615-
616- jvm_flags = " " .join (
617- [ctx . expand_location ( f , ctx . attr . data ) for f in jvm_flags ],
664+ # RUNPATH is defined here:
665+ # https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227
666+ classpath = ": " .join (
667+ ["${RUNPATH}%s" % ( j . short_path ) for j in rjars . to_list () ],
618668 )
619-
620- javabin = "export REAL_EXTERNAL_JAVA_BIN=${JAVABIN};JAVABIN=%s/%s" % (
621- _runfiles_root (ctx ),
622- wrapper .short_path ,
669+ ctx .actions .expand_template (
670+ template = template ,
671+ output = executable ,
672+ substitutions = {
673+ "%classpath%" : classpath ,
674+ "%java_start_class%" : main_class ,
675+ "%javabin%" : javabin ,
676+ "%jarbin%" : _jar_path_based_on_java_bin (ctx ),
677+ "%jvm_flags%" : jvm_flags ,
678+ "%needs_runfiles%" : "" ,
679+ "%runfiles_manifest_only%" : "" ,
680+ "%set_jacoco_metadata%" : "" ,
681+ "%set_jacoco_main_class%" : "" ,
682+ "%set_jacoco_java_runfiles_root%" : "" ,
683+ "%workspace_prefix%" : ctx .workspace_name + "/" ,
684+ "%set_java_coverage_new_implementation%" : """export JAVA_COVERAGE_NEW_IMPLEMENTATION=NO""" ,
685+ },
686+ is_executable = True ,
623687 )
624-
625- if use_jacoco and _coverage_replacements_provider .is_enabled (ctx ):
626- classpath = ":" .join (
627- ["${RUNPATH}%s" % (j .short_path ) for j in rjars .to_list () + ctx .files ._jacocorunner + ctx .files ._lcov_merger ],
628- )
629- jacoco_metadata_file = ctx .actions .declare_file (
630- "%s.jacoco_metadata.txt" % ctx .attr .name ,
631- sibling = executable ,
632- )
633- ctx .actions .write (jacoco_metadata_file , "\n " .join ([
634- jar .short_path .replace ("../" , "external/" )
635- for jar in rjars
636- ]))
637- ctx .actions .expand_template (
638- template = template ,
639- output = executable ,
640- substitutions = {
641- "%classpath%" : classpath ,
642- "%javabin%" : javabin ,
643- "%jarbin%" : _jar_path_based_on_java_bin (ctx ),
644- "%jvm_flags%" : jvm_flags ,
645- "%needs_runfiles%" : "" ,
646- "%runfiles_manifest_only%" : "" ,
647- "%workspace_prefix%" : ctx .workspace_name + "/" ,
648- "%java_start_class%" : "com.google.testing.coverage.JacocoCoverageRunner" ,
649- "%set_jacoco_metadata%" : "export JACOCO_METADATA_JAR=\" $JAVA_RUNFILES/{}/{}\" " .format (ctx .workspace_name , jacoco_metadata_file .short_path ),
650- "%set_jacoco_main_class%" : """export JACOCO_MAIN_CLASS={}""" .format (main_class ),
651- "%set_jacoco_java_runfiles_root%" : """export JACOCO_JAVA_RUNFILES_ROOT=$JAVA_RUNFILES/{}/""" .format (ctx .workspace_name ),
652- "%set_java_coverage_new_implementation%" : """export JAVA_COVERAGE_NEW_IMPLEMENTATION=YES""" ,
653- },
654- is_executable = True ,
655- )
656- return [jacoco_metadata_file ]
657- else :
658- # RUNPATH is defined here:
659- # https://github.com/bazelbuild/bazel/blob/0.4.5/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt#L227
660- classpath = ":" .join (
661- ["${RUNPATH}%s" % (j .short_path ) for j in rjars .to_list ()],
662- )
663- ctx .actions .expand_template (
664- template = template ,
665- output = executable ,
666- substitutions = {
667- "%classpath%" : classpath ,
668- "%java_start_class%" : main_class ,
669- "%javabin%" : javabin ,
670- "%jarbin%" : _jar_path_based_on_java_bin (ctx ),
671- "%jvm_flags%" : jvm_flags ,
672- "%needs_runfiles%" : "" ,
673- "%runfiles_manifest_only%" : "" ,
674- "%set_jacoco_metadata%" : "" ,
675- "%set_jacoco_main_class%" : "" ,
676- "%set_jacoco_java_runfiles_root%" : "" ,
677- "%workspace_prefix%" : ctx .workspace_name + "/" ,
678- "%set_java_coverage_new_implementation%" : """export JAVA_COVERAGE_NEW_IMPLEMENTATION=NO""" ,
679- },
680- is_executable = True ,
681- )
682- return []
688+ return []
683689
684690def _declare_executable (ctx ):
685691 if (_is_windows (ctx )):
@@ -1166,7 +1172,7 @@ def scala_test_impl(ctx):
11661172 ctx = ctx ,
11671173 executable = executable ,
11681174 jvm_flags = [
1169- "-DRULES_SCALA_WS =%s" % ctx .workspace_name ,
1175+ "-DRULES_SCALA_MAIN_WS_NAME =%s" % ctx .workspace_name ,
11701176 "-DRULES_SCALA_ARGS_FILE=%s" % argsFile .short_path
11711177 ] + ctx .attr .jvm_flags ,
11721178 main_class = ctx .attr .main_class ,
0 commit comments