From d6f4808784f364ec40e000d69c82b7dd752c65e8 Mon Sep 17 00:00:00 2001 From: Damien Martin-Guillerez Date: Fri, 5 Jun 2015 10:50:43 +0000 Subject: Bootstrapping tools using Bazel Added target to use java skylark rules to bootstrap JavaBuilder and SingleJar. Uses thoses target to bootstrap JavaBuilder and SingleJar and compiles all tools using Bazel. -- Change-Id: I5142917c8b31e04015fbab89382df36b4892d8c6 Reviewed-on: https://bazel-review.googlesource.com/#/c/1451/ MOS_MIGRATED_REVID=95281092 --- tools/build_rules/java_rules_skylark.bzl | 44 +++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'tools/build_rules') diff --git a/tools/build_rules/java_rules_skylark.bzl b/tools/build_rules/java_rules_skylark.bzl index 1f556ef0d1..16640e965f 100644 --- a/tools/build_rules/java_rules_skylark.bzl +++ b/tools/build_rules/java_rules_skylark.bzl @@ -31,6 +31,7 @@ def path_separator(ctx): # production ready. def java_library_impl(ctx): + javac_options = ctx.configuration.fragment(java_configuration).default_javac_flags class_jar = ctx.outputs.class_jar compile_time_jars = set(order="link") runtime_jars = set(order="link") @@ -39,11 +40,14 @@ def java_library_impl(ctx): runtime_jars += dep.runtime_jars jars = jar_filetype.filter(ctx.files.jars) - compile_time_jars += jars + neverlink_jars = jar_filetype.filter(ctx.files.neverlink_jars) + compile_time_jars += jars + neverlink_jars runtime_jars += jars compile_time_jars_list = list(compile_time_jars) # TODO: This is weird. build_output = class_jar.path + ".build_output" + java_output = class_jar.path + ".build_java" + javalist_output = class_jar.path + ".build_java_list" sources = ctx.files.srcs sources_param_file = ctx.new_file( @@ -54,12 +58,22 @@ def java_library_impl(ctx): executable = False) # Cleaning build output directory - cmd = "set -e;rm -rf " + build_output + ";mkdir " + build_output + "\n" - if ctx.files.srcs: + cmd = "set -e;rm -rf " + build_output + " " + java_output + " " + javalist_output + "\n" + cmd += "mkdir " + build_output + " " + java_output + "\n" + files = " @" + sources_param_file.path + + if ctx.files.srcjars: + files += " @" + javalist_output + for file in ctx.files.srcjars: + cmd += "jar tf %s | grep '\.java$' | sed 's|^|%s/|' >> %s\n" % (file.path, java_output, javalist_output) + cmd += "unzip %s -d %s >/dev/null\n" % (file.path, java_output) + + if ctx.files.srcs or ctx.files.srcjars: cmd += JAVA_PATH + "javac" + cmd += " " + " ".join(javac_options) if compile_time_jars: cmd += " -classpath '" + cmd_helper.join_paths(path_separator(ctx), compile_time_jars) + "'" - cmd += " -d " + build_output + " @" + sources_param_file.path + "\n" + cmd += " -d " + build_output + files + "\n" # We haven't got a good story for where these should end up, so # stick them in the root of the jar. @@ -69,7 +83,7 @@ def java_library_impl(ctx): "touch " + build_output + "\n") ctx.action( inputs = (sources + compile_time_jars_list + [sources_param_file] + - ctx.files.resources), + ctx.files.resources + ctx.files.srcjars), outputs = [class_jar], mnemonic='Javac', command=cmd, @@ -167,9 +181,10 @@ def java_import_impl(ctx): # TODO(bazel-team): Why do we need to filter here? The attribute # already says only jars are allowed. jars = set(jar_filetype.filter(ctx.files.jars)) + neverlink_jars = set(jar_filetype.filter(ctx.files.neverlink_jars)) runfiles = ctx.runfiles(collect_data = True) return struct(files = jars, - compile_time_jars = jars, + compile_time_jars = jars + neverlink_jars, runtime_jars = jars, runfiles = runfiles) @@ -179,6 +194,8 @@ java_library_attrs = { "resources": attr.label_list(allow_files=True), "srcs": attr.label_list(allow_files=java_filetype), "jars": attr.label_list(allow_files=jar_filetype), + "neverlink_jars": attr.label_list(allow_files=jar_filetype), + "srcjars": attr.label_list(allow_files=srcjar_filetype), "deps": attr.label_list( allow_files=False, providers = ["compile_time_jars", "runtime_jars"]), @@ -191,6 +208,14 @@ java_library = rule( "class_jar": "lib%{name}.jar", }) +# A copy to avoid conflict with native rule. +bootstrap_java_library = rule( + java_library_impl, + attrs = java_library_attrs, + outputs = { + "class_jar": "lib%{name}.jar", + }) + java_binary_attrs_common = java_library_attrs + { "jvm_flags": attr.string_list(), "jvm": attr.label(default=Label("//tools/jdk:jdk"), allow_files=True), @@ -213,6 +238,12 @@ java_binary = rule(java_binary_impl, attrs = java_binary_attrs, outputs = java_binary_outputs) +# A copy to avoid conflict with native rule +bootstrap_java_binary = rule(java_binary_impl, + executable = True, + attrs = java_binary_attrs, + outputs = java_binary_outputs) + java_test = rule(java_binary_impl, executable = True, attrs = java_binary_attrs_common + { @@ -230,4 +261,5 @@ java_import = rule( attrs = { "jars": attr.label_list(allow_files=jar_filetype), "srcjar": attr.label(allow_files=srcjar_filetype), + "neverlink_jars": attr.label_list(allow_files=jar_filetype, default=[]), }) -- cgit v1.2.3