Björn Pedersen | c357ceb | 2015-05-27 10:17:36 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 2 | # Copyright (C) 2013 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
David Pursehouse | 7a16e85 | 2013-10-18 15:08:44 +0900 | [diff] [blame] | 16 | from __future__ import print_function |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 17 | from optparse import OptionParser |
David Ostrovsky | 8c36caf | 2016-01-04 21:44:27 +0100 | [diff] [blame] | 18 | from os import makedirs, path, symlink |
David Ostrovsky | e3721d1 | 2015-10-17 00:32:20 +0200 | [diff] [blame] | 19 | from subprocess import check_call |
David Pursehouse | 7a16e85 | 2013-10-18 15:08:44 +0900 | [diff] [blame] | 20 | import sys |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 21 | |
| 22 | opts = OptionParser() |
| 23 | opts.add_option('-o', help='path to write WAR to') |
| 24 | opts.add_option('--lib', action='append', help='target for WEB-INF/lib') |
| 25 | opts.add_option('--pgmlib', action='append', help='target for WEB-INF/pgm-lib') |
Shawn Pearce | 55583ac | 2013-10-17 20:29:05 -0700 | [diff] [blame] | 26 | opts.add_option('--tmp', help='temporary directory') |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 27 | args, ctx = opts.parse_args() |
| 28 | |
Shawn Pearce | 55583ac | 2013-10-17 20:29:05 -0700 | [diff] [blame] | 29 | war = args.tmp |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 30 | jars = set() |
| 31 | |
David Ostrovsky | e3721d1 | 2015-10-17 00:32:20 +0200 | [diff] [blame] | 32 | def prune(l): |
David Ostrovsky | 8c36caf | 2016-01-04 21:44:27 +0100 | [diff] [blame] | 33 | return [j for e in l for j in e.split(':')] |
David Pursehouse | 15a9f53 | 2014-06-23 10:55:20 +0900 | [diff] [blame] | 34 | |
David Pursehouse | 6c25ea8 | 2013-09-26 16:48:27 +0900 | [diff] [blame] | 35 | def link_jars(libs, directory): |
| 36 | makedirs(directory) |
David Ostrovsky | e3721d1 | 2015-10-17 00:32:20 +0200 | [diff] [blame] | 37 | for j in libs: |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 38 | if j not in jars: |
| 39 | jars.add(j) |
| 40 | n = path.basename(j) |
David Ostrovsky | 8c36caf | 2016-01-04 21:44:27 +0100 | [diff] [blame] | 41 | if j.find('buck-out/gen/gerrit-') > 0: |
| 42 | n = j[j.find('buck-out'):].split('/')[2] + '-' + n |
| 43 | symlink(j, path.join(directory, n)) |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 44 | |
| 45 | if args.lib: |
David Ostrovsky | e3721d1 | 2015-10-17 00:32:20 +0200 | [diff] [blame] | 46 | link_jars(prune(args.lib), path.join(war, 'WEB-INF', 'lib')) |
Shawn Pearce | fd6bb9f | 2013-05-08 14:14:24 -0700 | [diff] [blame] | 47 | if args.pgmlib: |
David Ostrovsky | e3721d1 | 2015-10-17 00:32:20 +0200 | [diff] [blame] | 48 | link_jars(prune(args.pgmlib), path.join(war, 'WEB-INF', 'pgm-lib')) |
David Pursehouse | 7a16e85 | 2013-10-18 15:08:44 +0900 | [diff] [blame] | 49 | try: |
| 50 | for s in ctx: |
| 51 | check_call(['unzip', '-q', '-d', war, s]) |
David Pursehouse | 15a9f53 | 2014-06-23 10:55:20 +0900 | [diff] [blame] | 52 | check_call(['zip', '-9qr', args.o, '.'], cwd=war) |
David Pursehouse | 7a16e85 | 2013-10-18 15:08:44 +0900 | [diff] [blame] | 53 | except KeyboardInterrupt: |
| 54 | print('Interrupted by user', file=sys.stderr) |
Shawn Pearce | 55583ac | 2013-10-17 20:29:05 -0700 | [diff] [blame] | 55 | exit(1) |