blob: a557170f4741dda2c5cffa905b459bc10d1bfc20 [file] [log] [blame]
Shawn Pearce06497862013-07-29 15:44:49 -07001# 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 Nienhuys2e7f5cc2016-04-20 18:15:56 +020015sh_bang_template = (' && '.join([
David Ostrovsky6b330422016-11-03 20:07:09 +010016 "echo '#!/bin/bash -e' > $OUT",
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020017 'echo "# this script should run from the root of your workspace." >> $OUT',
18 'echo "" >> $OUT',
David Ostrovsky6b330422016-11-03 20:07:09 +010019 "echo 'if [[ \"${VERBOSE}\" ]]; then set -x ; fi' >> $OUT",
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020020 '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 Pearce06497862013-07-29 15:44:49 -070028def maven_package(
29 version,
30 repository = None,
31 url = None,
32 jar = {},
David Ostrovskybb360eb2013-11-23 22:28:05 +010033 src = {},
Jonathan Niederf24b7f92014-05-01 12:44:01 -070034 doc = {},
Dariusz Luksza3ffc86a2014-04-30 13:01:19 +020035 war = {}):
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020036
37 build_cmd = ['buck', 'build']
38
Han-Wen Nienhuys20217592016-05-12 19:10:26 +020039 # 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 Nienhuys2e7f5cc2016-04-20 18:15:56 +020042 api_cmd = mvn_cmd[:]
Han-Wen Nienhuys20217592016-05-12 19:10:26 +020043 api_targets = []
David Ostrovsky358a4582014-05-13 23:55:04 +020044 for type,d in [('jar', jar), ('java-source', src), ('javadoc', doc)]:
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020045 for a,t in sorted(d.iteritems()):
David Ostrovsky358a4582014-05-13 23:55:04 +020046 api_cmd.append('-s %s:%s:$(location %s)' % (a,type,t))
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020047 api_targets.append(t)
Shawn Pearce06497862013-07-29 15:44:49 -070048
49 genrule(
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020050 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 Pearce06497862013-07-29 15:44:49 -070056 )
57
58 if repository and url:
59 genrule(
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020060 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 Ostrovsky358a4582014-05-13 23:55:04 +020068 )
69
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020070 war_cmd = mvn_cmd[:]
Han-Wen Nienhuys20217592016-05-12 19:10:26 +020071 war_targets = []
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020072 for a,t in sorted(war.iteritems()):
David Ostrovsky358a4582014-05-13 23:55:04 +020073 war_cmd.append('-s %s:war:$(location %s)' % (a,t))
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020074 war_targets.append(t)
David Ostrovsky358a4582014-05-13 23:55:04 +020075
76 genrule(
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020077 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 Ostrovsky358a4582014-05-13 23:55:04 +020082 )
83
84 if repository and url:
85 genrule(
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020086 name = 'gen_war_deploy',
87 cmd = sh_bang_template % (
88 ' '.join(build_cmd + war_targets),
89 ' '.join(war_cmd + [
David Ostrovsky358a4582014-05-13 23:55:04 +020090 '-a', 'deploy',
91 '--repository', repository,
Han-Wen Nienhuys2e7f5cc2016-04-20 18:15:56 +020092 '--url', url])),
93 out = 'war_deploy.sh',
94 executable = True,
Shawn Pearce06497862013-07-29 15:44:49 -070095 )