@@ -50,15 +50,17 @@ def java_library_impl(ctx):
50
50
cmd = "set -e;rm -rf " + build_output + " " + java_output + " " + javalist_output + "\n "
51
51
cmd += "mkdir " + build_output + " " + java_output + "\n "
52
52
files = " @" + sources_param_file .path
53
+ java_runtime = ctx .attr ._jdk [java_common .JavaRuntimeInfo ]
54
+ jar_path = "%s/bin/jar" % java_runtime .java_home
53
55
54
56
if ctx .files .srcjars :
55
57
files += " @" + javalist_output
56
58
for file in ctx .files .srcjars :
57
- cmd += "%s tf %s | grep '\.java$' | sed 's|^|%s/|' >> %s\n " % (ctx . file . _jar . path , file .path , java_output , javalist_output )
59
+ cmd += "%s tf %s | grep '\.java$' | sed 's|^|%s/|' >> %s\n " % (jar_path , file .path , java_output , javalist_output )
58
60
cmd += "unzip %s -d %s >/dev/null\n " % (file .path , java_output )
59
61
60
62
if ctx .files .srcs or ctx .files .srcjars :
61
- cmd += ctx . file . _javac . path
63
+ cmd += "%s/bin/javac" % java_runtime . java_home
62
64
cmd += " " + " " .join (javac_options )
63
65
if compile_time_jars :
64
66
cmd += " -classpath '" + cmd_helper .join_paths (ctx .configuration .host_path_separator , compile_time_jars ) + "'"
@@ -68,11 +70,11 @@ def java_library_impl(ctx):
68
70
# stick them in the root of the jar.
69
71
for r in ctx .files .resources :
70
72
cmd += "cp %s %s\n " % (r .path , build_output )
71
- cmd += (ctx . file . _jar . path + " cf " + class_jar .path + " -C " + build_output + " .\n " +
73
+ cmd += (jar_path + " cf " + class_jar .path + " -C " + build_output + " .\n " +
72
74
"touch " + build_output + "\n " )
73
75
ctx .action (
74
76
inputs = (sources + compile_time_jars_list + [sources_param_file ] +
75
- [ ctx . file . _jar ] + ctx .files ._jdk + ctx .files .resources + ctx .files .srcjars ),
77
+ ctx .files ._jdk + ctx .files .resources + ctx .files .srcjars ),
76
78
outputs = [class_jar ],
77
79
mnemonic = "JavacBootstrap" ,
78
80
command = cmd ,
@@ -95,6 +97,8 @@ def java_binary_impl(ctx):
95
97
manifest = ctx .outputs .manifest
96
98
build_output = deploy_jar .path + ".build_output"
97
99
main_class = ctx .attr .main_class
100
+ java_runtime = ctx .attr ._jdk [java_common .JavaRuntimeInfo ]
101
+ jar_path = "%s/bin/jar" % java_runtime .java_home
98
102
ctx .file_action (
99
103
output = manifest ,
100
104
content = "Main-Class: " + main_class + "\n " ,
@@ -105,7 +109,7 @@ def java_binary_impl(ctx):
105
109
cmd = "set -e;rm -rf " + build_output + ";mkdir " + build_output + "\n "
106
110
for jar in library_result .runtime_jars :
107
111
cmd += "unzip -qn " + jar .path + " -d " + build_output + "\n "
108
- cmd += (ctx . file . _jar . path + " cmf " + manifest .path + " " +
112
+ cmd += (jar_path + " cmf " + manifest .path + " " +
109
113
deploy_jar .path + " -C " + build_output + " .\n " +
110
114
"touch " + build_output + "\n " )
111
115
@@ -138,7 +142,7 @@ def java_binary_impl(ctx):
138
142
" fi" ,
139
143
"fi" ,
140
144
"" ,
141
- "jvm_bin=%s" % (ctx .file . _java . path ),
145
+ "jvm_bin=%s" % (ctx .attr . _jdk [ java_common . JavaRuntimeInfo ]. java_executable_exec_path ),
142
146
"if [[ ! -x ${jvm_bin} ]]; then" ,
143
147
" jvm_bin=$(which java)" ,
144
148
"fi" ,
@@ -182,11 +186,11 @@ def java_import_impl(ctx):
182
186
)
183
187
184
188
java_library_attrs = {
185
- "_java " : attr .label (default = Label ( "//tools/jdk:java" ), single_file = True ),
186
- "_javac" : attr . label ( default = Label ("//tools/jdk:javac" ), single_file = True ),
187
- "_jar" : attr . label ( default = Label ( "//tools/jdk:jar" ), single_file = True ) ,
188
- "_jdk" : attr . label ( default = Label ( "//tools/jdk:jdk" ), allow_files = True ),
189
- "data" : attr .label_list (allow_files = True , cfg = "data" ),
189
+ "_jdk " : attr .label (
190
+ default = Label ("//tools/jdk:current_java_runtime" ),
191
+ providers = [ java_common . JavaRuntimeInfo ] ,
192
+ ),
193
+ "data" : attr .label_list (allow_files = True ),
190
194
"resources" : attr .label_list (allow_files = True ),
191
195
"srcs" : attr .label_list (allow_files = java_filetype ),
192
196
"jars" : attr .label_list (allow_files = jar_filetype ),
0 commit comments