-
Notifications
You must be signed in to change notification settings - Fork 1
/
gerrit_plugin.bucklet
171 lines (164 loc) · 4.75 KB
/
gerrit_plugin.bucklet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This depends on gerrit-plugin-api and optionally
# gerrit-plugin-gwtui (GWT module) and gwt-user libraries to be
# available under:
#
# //lib/gerrit:plugin-api
# //lib/gerrit:plugin-gwtui
# //lib/gwt:user
# //lib/gwt:dev
# //lib/ow2:ow2-asm
# //lib/ow2:ow2-asm-analysis
# //lib/ow2:ow2-asm-util
# //lib/ow2:ow2-asm-tree
#
# To provide it maven_jar() or bucklet can be used in lib/gerrit/BUCK:
#
# include_defs('//bucklets/maven_jar.bucklet')
#
# VER = '2.10'
#
# maven_jar(
# name = 'plugin-api',
# id = 'com.google.gerrit:gerrit-plugin-api:' + VER',
# )
#
# maven_jar(
# name = 'plugin-gwtui',
# id = 'com.google.gerrit:gerrit-plugin-gwtui:' + VER',
# )
#
GWT_JVM_ARGS = ['-Xmx512m']
GWT_COMPILER_ARGS = [
'-XdisableClassMetadata',
'-XdisableCastChecking',
]
GERRIT_GWT_API = ['//lib/gerrit:gwtui-api']
GERRIT_PLUGIN_API = ['//lib/gerrit:plugin-api']
GERRIT_TESTS = ['//lib/gerrit:acceptance-framework']
GWT_DEPS = [
'//lib/gwt:user',
'//lib/gwt:dev',
'//lib/gwt:ant',
'//lib/gwt:colt',
'//lib/gwt:javax-validation',
'//lib/gwt:javax-validation_src',
'//lib/gwt:jsinterop-annotations',
'//lib/gwt:jsinterop-annotations_src',
'//lib/gwt:tapestry',
'//lib/gwt:w3c-css-sac',
'//lib/ow2:ow2-asm',
'//lib/ow2:ow2-asm-analysis',
'//lib/ow2:ow2-asm-commons',
'//lib/ow2:ow2-asm-tree',
'//lib/ow2:ow2-asm-util',
]
STANDALONE_MODE = True
def gerrit_plugin(
name,
deps = [],
provided_deps = [],
srcs = [],
resources = [],
gwt_module = None,
manifest_entries = [],
type = 'plugin',
visibility = ['PUBLIC'],
target_suffix = ''):
from multiprocessing import cpu_count
from os import path,getcwd
# TODO(davido): Remove this hack and replace all this mess with just
# ROOT = get_base_path()
# when this issue is fixed:
# https://github.com/facebook/buck/issues/200
# Or this PR is merged:
# https://github.com/facebook/buck/pull/201
ROOT = getcwd()
while not path.lexists(path.join(ROOT, '.buckconfig')):
ROOT = path.dirname(ROOT)
if path.exists(path.join(ROOT, 'VERSION')):
include_defs('//' + path.join(ROOT, 'VERSION'))
mf_cmd = 'v=%s && ' % PLUGIN_VERSION
elif path.exists(path.join(ROOT, '.git')):
mf_cmd = 'v=\$(git describe --always HEAD) && '
else: # cannot retrieve plugin version, guessing '1.0'
mf_cmd = 'v=1.0 && '
mf_cmd += 'echo "Manifest-Version: 1.0" >$OUT && '
mf_cmd += 'echo "Gerrit-ApiType: %s" >>$OUT && ' % type
mf_cmd += 'echo "Implementation-Version: $v" >>$OUT && '
mf_cmd += 'echo "Implementation-Vendor: Gerrit Code Review" >>$OUT'
for line in manifest_entries:
line = line.replace('$', '\$')
mf_cmd += ' && echo "%s" >> $OUT' % line
genrule(
name = name + '__manifest',
cmd = mf_cmd,
out = 'MANIFEST.MF',
)
gwt_deps = []
static_jars = []
if gwt_module:
gwt_deps = GWT_DEPS + GERRIT_GWT_API
static_jars = [':%s-static-jar' % name]
java_library(
name = name + '__plugin',
srcs = srcs,
resources = resources,
deps = deps,
provided_deps = GERRIT_PLUGIN_API + provided_deps + gwt_deps,
visibility = ['PUBLIC'],
)
if gwt_module:
java_library(
name = name + '__gwt_module',
srcs = [],
resources = list(set(srcs + resources)),
deps = deps,
provided_deps = gwt_deps,
visibility = ['PUBLIC'],
)
prebuilt_jar(
name = '%s-static-jar' % name,
binary_jar = ':%s-static' % name,
)
genrule(
name = '%s-static' % name,
cmd = 'mkdir -p $TMP/static' +
';unzip -qd $TMP/static $(location %s)' %
':%s__gwt_application' % name +
';cd $TMP' +
';zip -qr $OUT .',
out = '%s-static.jar' % name,
)
gwt_binary(
name = name + '__gwt_application',
modules = [gwt_module],
deps = gwt_deps,
module_deps = [':%s__gwt_module' % name],
local_workers = cpu_count(),
strict = True,
experimental_args = GWT_COMPILER_ARGS,
vm_args = GWT_JVM_ARGS,
)
java_binary(
name = name + target_suffix,
manifest_file = ':%s__manifest' % name,
merge_manifests = False,
deps = [
':%s__plugin' % name,
] + static_jars,
visibility = visibility,
)