Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 1 | # Copyright (C) 2013 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 | |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 15 | sh_bang_template = (' && '.join([ |
David Ostrovsky | 6b33042 | 2016-11-03 20:07:09 +0100 | [diff] [blame] | 16 | "echo '#!/bin/bash -e' > $OUT", |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 17 | 'echo "# this script should run from the root of your workspace." >> $OUT', |
| 18 | 'echo "" >> $OUT', |
David Ostrovsky | 6b33042 | 2016-11-03 20:07:09 +0100 | [diff] [blame] | 19 | "echo 'if [[ \"${VERBOSE}\" ]]; then set -x ; fi' >> $OUT", |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 20 | 'echo "" >> $OUT', |
| 21 | 'echo %s >> $OUT', |
| 22 | 'echo "" >> $OUT', |
| 23 | 'echo %s >> $OUT', |
| 24 | # This is supposed to be handled by executable=True, but it doesn't |
| 25 | # work. Bug? |
| 26 | 'chmod +x $OUT' ])) |
| 27 | |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 28 | def maven_package( |
| 29 | version, |
| 30 | repository = None, |
| 31 | url = None, |
| 32 | jar = {}, |
David Ostrovsky | bb360eb | 2013-11-23 22:28:05 +0100 | [diff] [blame] | 33 | src = {}, |
Jonathan Nieder | f24b7f9 | 2014-05-01 12:44:01 -0700 | [diff] [blame] | 34 | doc = {}, |
Dariusz Luksza | 3ffc86a | 2014-04-30 13:01:19 +0200 | [diff] [blame] | 35 | war = {}): |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 36 | |
| 37 | build_cmd = ['buck', 'build'] |
| 38 | |
Han-Wen Nienhuys | 2021759 | 2016-05-12 19:10:26 +0200 | [diff] [blame] | 39 | # This is not using python_binary() to avoid the baggage and bugs |
| 40 | # that PEX brings along. |
| 41 | mvn_cmd = ['python', 'tools/maven/mvn.py', '-v', version] |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 42 | api_cmd = mvn_cmd[:] |
Han-Wen Nienhuys | 2021759 | 2016-05-12 19:10:26 +0200 | [diff] [blame] | 43 | api_targets = [] |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 44 | for type,d in [('jar', jar), ('java-source', src), ('javadoc', doc)]: |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 45 | for a,t in sorted(d.iteritems()): |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 46 | api_cmd.append('-s %s:%s:$(location %s)' % (a,type,t)) |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 47 | api_targets.append(t) |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 48 | |
| 49 | genrule( |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 50 | name = 'gen_api_install', |
| 51 | cmd = sh_bang_template % ( |
| 52 | ' '.join(build_cmd + api_targets), |
| 53 | ' '.join(api_cmd + ['-a', 'install'])), |
| 54 | out = 'api_install.sh', |
| 55 | executable = True, |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 56 | ) |
| 57 | |
| 58 | if repository and url: |
| 59 | genrule( |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 60 | name = 'gen_api_deploy', |
| 61 | cmd = sh_bang_template % ( |
| 62 | ' '.join(build_cmd + api_targets), |
| 63 | ' '.join(api_cmd + ['-a', 'deploy', |
| 64 | '--repository', repository, |
| 65 | '--url', url])), |
| 66 | out = 'api_deploy.sh', |
| 67 | executable = True, |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 68 | ) |
| 69 | |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 70 | war_cmd = mvn_cmd[:] |
Han-Wen Nienhuys | 2021759 | 2016-05-12 19:10:26 +0200 | [diff] [blame] | 71 | war_targets = [] |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 72 | for a,t in sorted(war.iteritems()): |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 73 | war_cmd.append('-s %s:war:$(location %s)' % (a,t)) |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 74 | war_targets.append(t) |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 75 | |
| 76 | genrule( |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 77 | name = 'gen_war_install', |
| 78 | cmd = sh_bang_template % (' '.join(build_cmd + war_targets), |
| 79 | ' '.join(war_cmd + ['-a', 'install'])), |
| 80 | out = 'war_install.sh', |
| 81 | executable = True, |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 82 | ) |
| 83 | |
| 84 | if repository and url: |
| 85 | genrule( |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 86 | name = 'gen_war_deploy', |
| 87 | cmd = sh_bang_template % ( |
| 88 | ' '.join(build_cmd + war_targets), |
| 89 | ' '.join(war_cmd + [ |
David Ostrovsky | 358a458 | 2014-05-13 23:55:04 +0200 | [diff] [blame] | 90 | '-a', 'deploy', |
| 91 | '--repository', repository, |
Han-Wen Nienhuys | 2e7f5cc | 2016-04-20 18:15:56 +0200 | [diff] [blame] | 92 | '--url', url])), |
| 93 | out = 'war_deploy.sh', |
| 94 | executable = True, |
Shawn Pearce | 0649786 | 2013-07-29 15:44:49 -0700 | [diff] [blame] | 95 | ) |