Bazel: Build user agent specific GWT modules
User agent specific GWT modules are used for development only. The build is triggered from the IDE (Eclipse) in GWT compile filter. It turns out, that ie11 and edge are not valid user agents, but known as gecko1_8. Change it in Buck code as well. TEST PLAN: $ bazel build gerrit-gwtui/... Contributed-By: Damien Martin-Guillerez <dmarting@google.com> Change-Id: I0c8731f765fda2824bb5145abdb12e295658fe04
This commit is contained in:
parent
ef227128ee
commit
13a2fc4561
@ -1,4 +1,5 @@
|
||||
load('//tools/bzl:gwt.bzl', 'gwt_genrule', 'gen_ui_module')
|
||||
load('//tools/bzl:gwt.bzl', 'gwt_genrule', 'gen_ui_module',
|
||||
'gwt_user_agent_permutations')
|
||||
load('//tools/bzl:license.bzl', 'license_test')
|
||||
|
||||
gwt_genrule()
|
||||
@ -7,6 +8,8 @@ gwt_genrule('_r')
|
||||
gen_ui_module(name = 'ui_module')
|
||||
gen_ui_module(name = 'ui_module', suffix = '_r')
|
||||
|
||||
gwt_user_agent_permutations()
|
||||
|
||||
license_test(
|
||||
name = "ui_module_license_test",
|
||||
target = ":ui_module",
|
||||
|
@ -18,14 +18,14 @@ BROWSERS = [
|
||||
'firefox',
|
||||
'gecko1_8',
|
||||
'safari',
|
||||
'msie', 'ie8', 'ie9', 'ie10', 'ie11',
|
||||
'msie', 'ie8', 'ie9', 'ie10',
|
||||
'edge',
|
||||
]
|
||||
ALIASES = {
|
||||
'chrome': 'safari',
|
||||
'firefox': 'gecko1_8',
|
||||
'msie': 'ie11',
|
||||
'edge': 'edge',
|
||||
'msie': 'ie10',
|
||||
'edge': 'gecko1_8',
|
||||
}
|
||||
MODULE = 'com.google.gerrit.GerritGwtUI'
|
||||
CPU_COUNT = cpu_count()
|
||||
|
@ -12,13 +12,28 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# GWT Rules Skylark rules for building [GWT](http://www.gwtproject.org/)
|
||||
# modules using Bazel.
|
||||
# Port of Buck native gwt_binary() rule. See discussion in context of
|
||||
# https://github.com/facebook/buck/issues/109
|
||||
load('//tools/bzl:genrule2.bzl', 'genrule2')
|
||||
load('//tools/bzl:java.bzl', 'java_library2')
|
||||
|
||||
jar_filetype = FileType(['.jar'])
|
||||
|
||||
BROWSERS = [
|
||||
'chrome',
|
||||
'firefox',
|
||||
'gecko1_8',
|
||||
'safari',
|
||||
'msie', 'ie8', 'ie9', 'ie10',
|
||||
'edge',
|
||||
]
|
||||
ALIASES = {
|
||||
'chrome': 'safari',
|
||||
'firefox': 'gecko1_8',
|
||||
'msie': 'ie10',
|
||||
'edge': 'gecko1_8',
|
||||
}
|
||||
|
||||
MODULE = 'com.google.gerrit.GerritGwtUI'
|
||||
|
||||
GWT_COMPILER = "com.google.gwt.dev.Compiler"
|
||||
@ -56,6 +71,13 @@ DEPS = GWT_TRANSITIVE_DEPS + [
|
||||
'@jgit_src//file',
|
||||
]
|
||||
|
||||
USER_AGENT_XML = """<module rename-to='gerrit_ui'>
|
||||
<inherits name='%s'/>
|
||||
<set-property name='user.agent' value='%s'/>
|
||||
<set-property name='locale' value='default'/>
|
||||
</module>
|
||||
"""
|
||||
|
||||
def gwt_module(gwt_xml=None, resources=[], srcs=[], **kwargs):
|
||||
if gwt_xml:
|
||||
resources += [gwt_xml]
|
||||
@ -65,7 +87,46 @@ def gwt_module(gwt_xml=None, resources=[], srcs=[], **kwargs):
|
||||
resources = resources,
|
||||
**kwargs)
|
||||
|
||||
def _impl(ctx):
|
||||
def _gwt_user_agent_module(ctx):
|
||||
"""Generate user agent specific GWT module."""
|
||||
if not ctx.attr.user_agent:
|
||||
return None
|
||||
|
||||
ua = ctx.attr.user_agent
|
||||
impl = ua
|
||||
if ua in ALIASES:
|
||||
impl = ALIASES[ua]
|
||||
|
||||
# intermediate artifact: user agent speific GWT xml file
|
||||
gwt_user_agent_xml = ctx.new_file(ctx.label.name + "_gwt.xml")
|
||||
ctx.file_action(output = gwt_user_agent_xml,
|
||||
content=USER_AGENT_XML % (MODULE, impl))
|
||||
|
||||
# intermediate artifact: user agent specific zip with GWT module
|
||||
gwt_user_agent_zip = ctx.new_file(ctx.label.name + "_gwt.zip")
|
||||
gwt = '%s_%s.gwt.xml' % (MODULE.replace('.', '/'), ua)
|
||||
dir = gwt_user_agent_zip.path + ".dir"
|
||||
cmd = " && ".join([
|
||||
"p=$PWD",
|
||||
"mkdir -p %s" % dir,
|
||||
"cd %s" % dir,
|
||||
"mkdir -p $(dirname %s)" % gwt,
|
||||
"cp $p/%s %s" % (gwt_user_agent_xml.path, gwt),
|
||||
"$p/%s cC $p/%s $(find . | sed 's|^./||')" % (ctx.executable._zip.path, gwt_user_agent_zip.path)
|
||||
])
|
||||
ctx.action(
|
||||
inputs = [gwt_user_agent_xml] + ctx.files._zip,
|
||||
outputs = [gwt_user_agent_zip],
|
||||
command = cmd,
|
||||
mnemonic = "GenerateUserAgentGWTModule")
|
||||
|
||||
return struct(
|
||||
zip=gwt_user_agent_zip,
|
||||
module=MODULE + '_' + ua
|
||||
)
|
||||
|
||||
def _gwt_binary_impl(ctx):
|
||||
module = MODULE
|
||||
output_zip = ctx.outputs.output
|
||||
output_dir = output_zip.path + '.gwt_output'
|
||||
deploy_dir = output_zip.path + '.gwt_deploy'
|
||||
@ -76,6 +137,13 @@ def _impl(ctx):
|
||||
for dep in deps:
|
||||
paths.append(dep.path)
|
||||
|
||||
gwt_user_agent_modules = []
|
||||
ua = _gwt_user_agent_module(ctx)
|
||||
if ua:
|
||||
paths.append(ua.zip.path)
|
||||
gwt_user_agent_modules.append(ua.zip)
|
||||
module = ua.module
|
||||
|
||||
cmd = "external/local_jdk/bin/java %s -Dgwt.normalizeTimestamps=true -cp %s %s -war %s -deploy %s " % (
|
||||
" ".join(ctx.attr.jvm_args),
|
||||
":".join(paths),
|
||||
@ -89,7 +157,7 @@ def _impl(ctx):
|
||||
"-optimize %s" % ctx.attr.optimize,
|
||||
"-strict",
|
||||
" ".join(ctx.attr.compiler_args),
|
||||
" ".join(ctx.attr.modules) + "\n",
|
||||
module + "\n",
|
||||
"rm -rf %s/gwt-unitCache\n" % output_dir,
|
||||
"root=`pwd`\n",
|
||||
"cd %s; $root/%s Cc ../%s $(find .)\n" % (
|
||||
@ -100,7 +168,7 @@ def _impl(ctx):
|
||||
])
|
||||
|
||||
ctx.action(
|
||||
inputs = list(deps) + ctx.files._jdk + ctx.files._zip,
|
||||
inputs = list(deps) + ctx.files._jdk + ctx.files._zip + gwt_user_agent_modules,
|
||||
outputs = [output_zip],
|
||||
mnemonic = "GwtBinary",
|
||||
progress_message = "GWT compiling " + output_zip.short_path,
|
||||
@ -121,12 +189,12 @@ def _get_transitive_closure(ctx):
|
||||
return deps
|
||||
|
||||
gwt_binary = rule(
|
||||
implementation = _impl,
|
||||
implementation = _gwt_binary_impl,
|
||||
attrs = {
|
||||
"user_agent": attr.string(),
|
||||
"style": attr.string(default = "OBF"),
|
||||
"optimize": attr.string(default = "9"),
|
||||
"deps": attr.label_list(allow_files=jar_filetype),
|
||||
"modules": attr.string_list(mandatory=True),
|
||||
"module_deps": attr.label_list(allow_files=jar_filetype),
|
||||
"compiler_args": attr.string_list(),
|
||||
"jvm_args": attr.string_list(),
|
||||
@ -169,7 +237,6 @@ def gwt_genrule(suffix = ""):
|
||||
|
||||
gwt_binary(
|
||||
name = opt,
|
||||
modules = [MODULE],
|
||||
module_deps = [module_dep],
|
||||
deps = DEPS,
|
||||
compiler_args = args,
|
||||
@ -178,7 +245,6 @@ def gwt_genrule(suffix = ""):
|
||||
|
||||
gwt_binary(
|
||||
name = dbg,
|
||||
modules = [MODULE],
|
||||
style = 'PRETTY',
|
||||
optimize = "0",
|
||||
module_deps = [module_dep],
|
||||
@ -206,4 +272,15 @@ def gen_ui_module(name, suffix = ""):
|
||||
visibility = ['//visibility:public'],
|
||||
)
|
||||
|
||||
|
||||
def gwt_user_agent_permutations():
|
||||
for ua in BROWSERS:
|
||||
gwt_binary(
|
||||
name = "ui_%s" % ua,
|
||||
user_agent = ua,
|
||||
style = 'PRETTY',
|
||||
optimize = "0",
|
||||
module_deps = [':ui_module'],
|
||||
deps = DEPS,
|
||||
compiler_args = GWT_COMPILER_ARGS,
|
||||
jvm_args = GWT_JVM_ARGS,
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user