blob: ca21790ad4b7682a212661b97e94cc7b60775127 [file] [log] [blame]
Björn Pedersenc357ceb2015-05-27 10:17:36 +02001#!/usr/bin/env python
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -07002# 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 Pursehouse7a16e852013-10-18 15:08:44 +090016from __future__ import print_function
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070017from optparse import OptionParser
David Ostrovsky8c36caf2016-01-04 21:44:27 +010018from os import makedirs, path, symlink
David Ostrovskye3721d12015-10-17 00:32:20 +020019from subprocess import check_call
David Pursehouse7a16e852013-10-18 15:08:44 +090020import sys
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070021
22opts = OptionParser()
23opts.add_option('-o', help='path to write WAR to')
24opts.add_option('--lib', action='append', help='target for WEB-INF/lib')
25opts.add_option('--pgmlib', action='append', help='target for WEB-INF/pgm-lib')
Shawn Pearce55583ac2013-10-17 20:29:05 -070026opts.add_option('--tmp', help='temporary directory')
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070027args, ctx = opts.parse_args()
28
Shawn Pearce55583ac2013-10-17 20:29:05 -070029war = args.tmp
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070030jars = set()
31
David Ostrovskye3721d12015-10-17 00:32:20 +020032def prune(l):
David Ostrovsky8c36caf2016-01-04 21:44:27 +010033 return [j for e in l for j in e.split(':')]
David Pursehouse15a9f532014-06-23 10:55:20 +090034
David Pursehouse6c25ea82013-09-26 16:48:27 +090035def link_jars(libs, directory):
36 makedirs(directory)
David Ostrovskye3721d12015-10-17 00:32:20 +020037 for j in libs:
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070038 if j not in jars:
39 jars.add(j)
40 n = path.basename(j)
David Ostrovsky8c36caf2016-01-04 21:44:27 +010041 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 Pearcefd6bb9f2013-05-08 14:14:24 -070044
45if args.lib:
David Ostrovskye3721d12015-10-17 00:32:20 +020046 link_jars(prune(args.lib), path.join(war, 'WEB-INF', 'lib'))
Shawn Pearcefd6bb9f2013-05-08 14:14:24 -070047if args.pgmlib:
David Ostrovskye3721d12015-10-17 00:32:20 +020048 link_jars(prune(args.pgmlib), path.join(war, 'WEB-INF', 'pgm-lib'))
David Pursehouse7a16e852013-10-18 15:08:44 +090049try:
50 for s in ctx:
51 check_call(['unzip', '-q', '-d', war, s])
David Pursehouse15a9f532014-06-23 10:55:20 +090052 check_call(['zip', '-9qr', args.o, '.'], cwd=war)
David Pursehouse7a16e852013-10-18 15:08:44 +090053except KeyboardInterrupt:
54 print('Interrupted by user', file=sys.stderr)
Shawn Pearce55583ac2013-10-17 20:29:05 -070055 exit(1)