David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 1 | # 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 Ostrovsky | ea6d48e | 2015-03-02 08:06:21 +0100 | [diff] [blame] | 23 | # //lib/ow2:ow2-asm |
| 24 | # //lib/ow2:ow2-asm-analysis |
| 25 | # //lib/ow2:ow2-asm-util |
| 26 | # //lib/ow2:ow2-asm-tree |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 27 | # |
| 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 | |
| 45 | GWT_JVM_ARGS = ['-Xmx512m'] |
| 46 | |
| 47 | GWT_COMPILER_ARGS = [ |
| 48 | '-XdisableClassMetadata', |
| 49 | '-XdisableCastChecking', |
| 50 | ] |
| 51 | |
David Ostrovsky | b3e0129 | 2014-07-19 21:02:52 +0200 | [diff] [blame] | 52 | GERRIT_GWT_API = ['//lib/gerrit:gwtui-api'] |
David Ostrovsky | faf3540 | 2015-09-24 22:01:08 +0200 | [diff] [blame] | 53 | GERRIT_PLUGIN_API = ['//lib/gerrit:plugin-api'] |
| 54 | GERRIT_TESTS = ['//lib/gerrit:acceptance-framework'] |
David Ostrovsky | b3e0129 | 2014-07-19 21:02:52 +0200 | [diff] [blame] | 55 | |
| 56 | GWT_DEPS = [ |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 57 | '//lib/gwt:user', |
| 58 | '//lib/gwt:dev', |
David Ostrovsky | ea6d48e | 2015-03-02 08:06:21 +0100 | [diff] [blame] | 59 | '//lib/ow2:ow2-asm', |
| 60 | '//lib/ow2:ow2-asm-analysis', |
| 61 | '//lib/ow2:ow2-asm-util', |
| 62 | '//lib/ow2:ow2-asm-tree', |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 63 | ] |
| 64 | |
David Ostrovsky | 9622230 | 2014-11-22 11:10:45 +0100 | [diff] [blame] | 65 | STANDALONE_MODE = True |
David Ostrovsky | feac5aa | 2014-07-21 00:35:51 +0200 | [diff] [blame] | 66 | |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 67 | def gerrit_plugin( |
| 68 | name, |
| 69 | deps = [], |
| 70 | provided_deps = [], |
| 71 | srcs = [], |
| 72 | resources = [], |
| 73 | gwt_module = None, |
| 74 | manifest_entries = [], |
| 75 | type = 'plugin', |
Doug Kelly | 48e70a0 | 2015-08-03 09:15:20 -0500 | [diff] [blame] | 76 | visibility = ['PUBLIC'], |
| 77 | target_suffix = ''): |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 78 | from multiprocessing import cpu_count |
David Ostrovsky | 1e442a6 | 2014-10-26 22:51:00 +0100 | [diff] [blame] | 79 | 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 Ostrovsky | 3dad378 | 2014-07-12 10:44:45 +0200 | [diff] [blame] | 89 | 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 Ostrovsky | bccbb0b | 2014-12-19 00:36:53 +0100 | [diff] [blame] | 93 | mf_cmd = 'v=\$(git describe --always HEAD) && ' |
David Ostrovsky | 3dad378 | 2014-07-12 10:44:45 +0200 | [diff] [blame] | 94 | else: # cannot retrieve plugin version, guessing '1.0' |
| 95 | mf_cmd = 'v=1.0 && ' |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 96 | 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 Ostrovsky | b3e0129 | 2014-07-19 21:02:52 +0200 | [diff] [blame] | 111 | gwt_deps = GWT_DEPS + GERRIT_GWT_API |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 112 | static_jars = [':%s-static-jar' % name] |
| 113 | java_library( |
| 114 | name = name + '__plugin', |
| 115 | srcs = srcs, |
| 116 | resources = resources, |
| 117 | deps = deps, |
David Ostrovsky | b3e0129 | 2014-07-19 21:02:52 +0200 | [diff] [blame] | 118 | provided_deps = GERRIT_PLUGIN_API + provided_deps + gwt_deps, |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 119 | visibility = ['PUBLIC'], |
| 120 | ) |
| 121 | if gwt_module: |
David Ostrovsky | d1d72a4 | 2015-01-23 23:24:46 +0100 | [diff] [blame] | 122 | 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 Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 130 | 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 Ostrovsky | d1d72a4 | 2015-01-23 23:24:46 +0100 | [diff] [blame] | 147 | module_deps = [':%s__gwt_module' % name], |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 148 | 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 Kelly | 48e70a0 | 2015-08-03 09:15:20 -0500 | [diff] [blame] | 155 | name = name + target_suffix, |
David Ostrovsky | f7b643b | 2014-05-31 16:13:31 +0200 | [diff] [blame] | 156 | manifest_file = ':%s__manifest' % name, |
| 157 | merge_manifests = False, |
| 158 | deps = [ |
| 159 | ':%s__plugin' % name, |
| 160 | ] + static_jars, |
| 161 | visibility = visibility, |
| 162 | ) |