blob: 922bd777b3160bb7580c7a494401ebf56c7a7126 [file] [log] [blame]
David Ostrovskyf7b643b2014-05-31 16:13:31 +02001# Copyright (C) 2014 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15# This depends on gerrit-plugin-api and optionally
16# gerrit-plugin-gwtui (GWT module) and gwt-user libraries to be
17# available under:
18#
19# //lib/gerrit:plugin-api
20# //lib/gerrit:plugin-gwtui
21# //lib/gwt:user
22# //lib/gwt:dev
David Ostrovskyea6d48e2015-03-02 08:06:21 +010023# //lib/ow2:ow2-asm
24# //lib/ow2:ow2-asm-analysis
25# //lib/ow2:ow2-asm-util
26# //lib/ow2:ow2-asm-tree
David Ostrovskyf7b643b2014-05-31 16:13:31 +020027#
28# To provide it maven_jar() or bucklet can be used in lib/gerrit/BUCK:
29#
30# include_defs('//bucklets/maven_jar.bucklet')
31#
32# VER = '2.10'
33#
34# maven_jar(
35# name = 'plugin-api',
36# id = 'com.google.gerrit:gerrit-plugin-api:' + VER',
37# )
38#
39# maven_jar(
40# name = 'plugin-gwtui',
41# id = 'com.google.gerrit:gerrit-plugin-gwtui:' + VER',
42# )
43#
44
45GWT_JVM_ARGS = ['-Xmx512m']
46
47GWT_COMPILER_ARGS = [
48 '-XdisableClassMetadata',
49 '-XdisableCastChecking',
50]
51
David Ostrovskyb3e01292014-07-19 21:02:52 +020052GERRIT_GWT_API = ['//lib/gerrit:gwtui-api']
David Ostrovskyfaf35402015-09-24 22:01:08 +020053GERRIT_PLUGIN_API = ['//lib/gerrit:plugin-api']
54GERRIT_TESTS = ['//lib/gerrit:acceptance-framework']
David Ostrovskyb3e01292014-07-19 21:02:52 +020055
56GWT_DEPS = [
David Ostrovskyf7b643b2014-05-31 16:13:31 +020057 '//lib/gwt:user',
58 '//lib/gwt:dev',
David Ostrovskyea6d48e2015-03-02 08:06:21 +010059 '//lib/ow2:ow2-asm',
60 '//lib/ow2:ow2-asm-analysis',
61 '//lib/ow2:ow2-asm-util',
62 '//lib/ow2:ow2-asm-tree',
David Ostrovskyf7b643b2014-05-31 16:13:31 +020063]
64
David Ostrovsky96222302014-11-22 11:10:45 +010065STANDALONE_MODE = True
David Ostrovskyfeac5aa2014-07-21 00:35:51 +020066
David Ostrovskyf7b643b2014-05-31 16:13:31 +020067def gerrit_plugin(
68 name,
69 deps = [],
70 provided_deps = [],
71 srcs = [],
72 resources = [],
73 gwt_module = None,
74 manifest_entries = [],
75 type = 'plugin',
Doug Kelly48e70a02015-08-03 09:15:20 -050076 visibility = ['PUBLIC'],
77 target_suffix = ''):
David Ostrovskyf7b643b2014-05-31 16:13:31 +020078 from multiprocessing import cpu_count
David Ostrovsky1e442a62014-10-26 22:51:00 +010079 from os import path,getcwd
80 # TODO(davido): Remove this hack and replace all this mess with just
81 # ROOT = get_base_path()
82 # when this issue is fixed:
83 # https://github.com/facebook/buck/issues/200
84 # Or this PR is merged:
85 # https://github.com/facebook/buck/pull/201
86 ROOT = getcwd()
87 while not path.lexists(path.join(ROOT, '.buckconfig')):
88 ROOT = path.dirname(ROOT)
David Ostrovsky3dad3782014-07-12 10:44:45 +020089 if path.exists(path.join(ROOT, 'VERSION')):
90 include_defs('//' + path.join(ROOT, 'VERSION'))
91 mf_cmd = 'v=%s && ' % PLUGIN_VERSION
92 elif path.exists(path.join(ROOT, '.git')):
David Ostrovskybccbb0b2014-12-19 00:36:53 +010093 mf_cmd = 'v=\$(git describe --always HEAD) && '
David Ostrovsky3dad3782014-07-12 10:44:45 +020094 else: # cannot retrieve plugin version, guessing '1.0'
95 mf_cmd = 'v=1.0 && '
David Ostrovskyf7b643b2014-05-31 16:13:31 +020096 mf_cmd += 'echo "Manifest-Version: 1.0" >$OUT && '
97 mf_cmd += 'echo "Gerrit-ApiType: %s" >>$OUT && ' % type
98 mf_cmd += 'echo "Implementation-Version: $v" >>$OUT && '
99 mf_cmd += 'echo "Implementation-Vendor: Gerrit Code Review" >>$OUT'
100 for line in manifest_entries:
101 line = line.replace('$', '\$')
102 mf_cmd += ' && echo "%s" >> $OUT' % line
103 genrule(
104 name = name + '__manifest',
105 cmd = mf_cmd,
106 out = 'MANIFEST.MF',
107 )
108 gwt_deps = []
109 static_jars = []
110 if gwt_module:
David Ostrovskyb3e01292014-07-19 21:02:52 +0200111 gwt_deps = GWT_DEPS + GERRIT_GWT_API
David Ostrovskyf7b643b2014-05-31 16:13:31 +0200112 static_jars = [':%s-static-jar' % name]
113 java_library(
114 name = name + '__plugin',
115 srcs = srcs,
116 resources = resources,
117 deps = deps,
David Ostrovskyb3e01292014-07-19 21:02:52 +0200118 provided_deps = GERRIT_PLUGIN_API + provided_deps + gwt_deps,
David Ostrovskyf7b643b2014-05-31 16:13:31 +0200119 visibility = ['PUBLIC'],
120 )
121 if gwt_module:
David Ostrovskyd1d72a42015-01-23 23:24:46 +0100122 java_library(
123 name = name + '__gwt_module',
124 srcs = [],
125 resources = list(set(srcs + resources)),
126 deps = deps,
127 provided_deps = gwt_deps,
128 visibility = ['PUBLIC'],
129 )
David Ostrovskyf7b643b2014-05-31 16:13:31 +0200130 prebuilt_jar(
131 name = '%s-static-jar' % name,
132 binary_jar = ':%s-static' % name,
133 )
134 genrule(
135 name = '%s-static' % name,
136 cmd = 'mkdir -p $TMP/static' +
137 ';unzip -qd $TMP/static $(location %s)' %
138 ':%s__gwt_application' % name +
139 ';cd $TMP' +
140 ';zip -qr $OUT .',
141 out = '%s-static.zip' % name,
142 )
143 gwt_binary(
144 name = name + '__gwt_application',
145 modules = [gwt_module],
146 deps = gwt_deps,
David Ostrovskyd1d72a42015-01-23 23:24:46 +0100147 module_deps = [':%s__gwt_module' % name],
David Ostrovskyf7b643b2014-05-31 16:13:31 +0200148 local_workers = cpu_count(),
149 strict = True,
150 experimental_args = GWT_COMPILER_ARGS,
151 vm_args = GWT_JVM_ARGS,
152 )
153
154 java_binary(
Doug Kelly48e70a02015-08-03 09:15:20 -0500155 name = name + target_suffix,
David Ostrovskyf7b643b2014-05-31 16:13:31 +0200156 manifest_file = ':%s__manifest' % name,
157 merge_manifests = False,
158 deps = [
159 ':%s__plugin' % name,
160 ] + static_jars,
161 visibility = visibility,
162 )