Bazel: Implement GWT UI build for the plugins

TEST PLAN:

  $ bazel build plugins/cookbook-plugin

Deploy to the server site and verify that it works.

Change-Id: I98af807f9c92ba4ed7efad332d8fdee407bb8ce6
This commit is contained in:
David Ostrovsky
2016-11-15 14:30:26 -08:00
parent 63408c9ce8
commit 2502fab15a
4 changed files with 73 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ package(default_visibility = ['//visibility:public'])
load('//tools/bzl:java.bzl', 'java_library2') load('//tools/bzl:java.bzl', 'java_library2')
SRCS = glob(['src/main/java/com/google/gerrit/**/*.java']) SRCS = glob(['src/main/java/com/google/gerrit/**/*.java'])
DEPS = ['//lib/gwt:user'] DEPS = ['//lib/gwt:user-neverlink']
java_binary( java_binary(
name = 'gwtui-api', name = 'gwtui-api',
@@ -18,7 +18,16 @@ java_library2(
srcs = SRCS, srcs = SRCS,
resources = glob(['src/main/**/*']), resources = glob(['src/main/**/*']),
exported_deps = ['//gerrit-gwtui-common:client-lib'], exported_deps = ['//gerrit-gwtui-common:client-lib'],
deps = DEPS + ['//lib/gwt:dev'], # we want this to be exported deps deps = DEPS + ['//lib/gwt:dev'],
)
java_library2(
name = 'gwtui-api-lib-neverlink',
srcs = SRCS,
resources = glob(['src/main/**/*']),
exported_deps = ['//gerrit-gwtui-common:client-lib'],
neverlink = 1, # we want this to be exported deps
deps = DEPS + ['//lib/gwt:dev'],
) )
java_binary( java_binary(

View File

@@ -14,6 +14,14 @@
'w3c-css-sac', 'w3c-css-sac',
]] ]]
java_library(
name = 'user-neverlink',
exports = ['@user//jar'],
visibility = ['//visibility:public'],
neverlink = 1,
data = ['//lib:LICENSE-Apache2.0'],
)
java_library( java_library(
name = 'javax-validation_src', name = 'javax-validation_src',
exports = ['@javax_validation//src'], exports = ['@javax_validation//src'],

View File

@@ -48,6 +48,19 @@ GWT_COMPILER_ARGS_RELEASE_MODE = GWT_COMPILER_ARGS + [
'-XdisableCastChecking', '-XdisableCastChecking',
] ]
PLUGIN_DEPS_NEVERLINK = [
'//gerrit-plugin-api:lib-neverlink',
]
GWT_PLUGIN_DEPS_NEVERLINK = [
'//gerrit-plugin-gwtui:gwtui-api-lib-neverlink',
'//lib/gwt:user-neverlink',
]
GWT_PLUGIN_DEPS = [
'//gerrit-plugin-gwtui:gwtui-api-lib',
]
GWT_TRANSITIVE_DEPS = [ GWT_TRANSITIVE_DEPS = [
'//lib/gwt:ant', '//lib/gwt:ant',
'//lib/gwt:colt', '//lib/gwt:colt',
@@ -126,7 +139,7 @@ def _gwt_user_agent_module(ctx):
) )
def _gwt_binary_impl(ctx): def _gwt_binary_impl(ctx):
module = MODULE module = ctx.attr.module[0]
output_zip = ctx.outputs.output output_zip = ctx.outputs.output
output_dir = output_zip.path + '.gwt_output' output_dir = output_zip.path + '.gwt_output'
deploy_dir = output_zip.path + '.gwt_deploy' deploy_dir = output_zip.path + '.gwt_deploy'
@@ -195,6 +208,7 @@ gwt_binary = rule(
"style": attr.string(default = "OBF"), "style": attr.string(default = "OBF"),
"optimize": attr.string(default = "9"), "optimize": attr.string(default = "9"),
"deps": attr.label_list(allow_files=jar_filetype), "deps": attr.label_list(allow_files=jar_filetype),
"module": attr.string_list(default = [MODULE]),
"module_deps": attr.label_list(allow_files=jar_filetype), "module_deps": attr.label_list(allow_files=jar_filetype),
"compiler_args": attr.string_list(), "compiler_args": attr.string_list(),
"jvm_args": attr.string_list(), "jvm_args": attr.string_list(),
@@ -237,6 +251,7 @@ def gwt_genrule(suffix = ""):
gwt_binary( gwt_binary(
name = opt, name = opt,
module = [MODULE],
module_deps = [module_dep], module_deps = [module_dep],
deps = DEPS, deps = DEPS,
compiler_args = args, compiler_args = args,
@@ -279,6 +294,7 @@ def gwt_user_agent_permutations():
user_agent = ua, user_agent = ua,
style = 'PRETTY', style = 'PRETTY',
optimize = "0", optimize = "0",
module = [MODULE],
module_deps = [':ui_module'], module_deps = [':ui_module'],
deps = DEPS, deps = DEPS,
compiler_args = GWT_COMPILER_ARGS, compiler_args = GWT_COMPILER_ARGS,

View File

@@ -1,9 +1,14 @@
load('//tools/bzl:genrule2.bzl', 'genrule2') load('//tools/bzl:genrule2.bzl', 'genrule2')
load('//tools/bzl:gwt.bzl', 'GWT_PLUGIN_DEPS',
'GWT_PLUGIN_DEPS_NEVERLINK', 'GWT_TRANSITIVE_DEPS',
'GWT_COMPILER_ARGS', 'PLUGIN_DEPS_NEVERLINK',
'GWT_JVM_ARGS', 'gwt_binary')
def gerrit_plugin( def gerrit_plugin(
name, name,
deps = [], deps = [],
srcs = [], srcs = [],
gwt_module = [],
resources = [], resources = [],
manifest_entries = [], manifest_entries = [],
**kwargs): **kwargs):
@@ -11,10 +16,14 @@ def gerrit_plugin(
name = name + '__plugin', name = name + '__plugin',
srcs = srcs, srcs = srcs,
resources = resources, resources = resources,
deps = deps + ['//gerrit-plugin-api:lib-neverlink'], deps = deps + GWT_PLUGIN_DEPS_NEVERLINK + PLUGIN_DEPS_NEVERLINK,
visibility = ['//visibility:public'], visibility = ['//visibility:public'],
) )
static_jars = []
if gwt_module:
static_jars = [':%s-static' % name]
native.java_binary( native.java_binary(
name = '%s__non_stamped' % name, name = '%s__non_stamped' % name,
deploy_manifest_lines = manifest_entries + [ deploy_manifest_lines = manifest_entries + [
@@ -24,11 +33,37 @@ def gerrit_plugin(
main_class = 'Dummy', main_class = 'Dummy',
runtime_deps = [ runtime_deps = [
':%s__plugin' % name, ':%s__plugin' % name,
], ] + static_jars,
visibility = ['//visibility:public'], visibility = ['//visibility:public'],
**kwargs **kwargs
) )
if gwt_module:
native.java_library(
name = name + '__gwt_module',
resources = list(set(srcs + resources)),
runtime_deps = deps + GWT_PLUGIN_DEPS,
visibility = ['//visibility:public'],
)
genrule2(
name = '%s-static' % name,
cmd = ' && '.join([
'mkdir -p $$TMP/static',
'unzip -qd $$TMP/static $(location %s__gwt_application)' % name,
'cd $$TMP',
'zip -qr $$ROOT/$@ .']),
tools = [':%s__gwt_application' % name],
outs = ['%s-static.jar' % name],
)
gwt_binary(
name = name + '__gwt_application',
module = [gwt_module],
deps = GWT_PLUGIN_DEPS + GWT_TRANSITIVE_DEPS + ['//lib/gwt:dev'],
module_deps = [':%s__gwt_module' % name],
compiler_args = GWT_COMPILER_ARGS,
jvm_args = GWT_JVM_ARGS,
)
# TODO(davido): Remove manual merge of manifest file when this feature # TODO(davido): Remove manual merge of manifest file when this feature
# request is implemented: https://github.com/bazelbuild/bazel/issues/2009 # request is implemented: https://github.com/bazelbuild/bazel/issues/2009
genrule2( genrule2(