1# This Source Code Form is subject to the terms of the Mozilla Public 2# License, v. 2.0. If a copy of the MPL was not distributed with this 3# file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5# This script creates a zip file, but will also strip any binaries 6# it finds before adding them to the zip. 7 8from __future__ import absolute_import, print_function 9 10from mozpack.files import FileFinder 11from mozpack.copier import Jarrer 12from mozpack.errors import errors 13from mozpack.path import match 14from mozbuild.action.util import log_build_task 15 16import argparse 17import mozpack.path as mozpath 18import sys 19 20 21def main(args): 22 parser = argparse.ArgumentParser() 23 parser.add_argument( 24 "-C", 25 metavar="DIR", 26 default=".", 27 help="Change to given directory before considering " "other paths", 28 ) 29 parser.add_argument("--strip", action="store_true", help="Strip executables") 30 parser.add_argument( 31 "-x", 32 metavar="EXCLUDE", 33 default=[], 34 action="append", 35 help="Exclude files that match the pattern", 36 ) 37 parser.add_argument("zip", help="Path to zip file to write") 38 parser.add_argument("input", nargs="+", help="Path to files to add to zip") 39 args = parser.parse_args(args) 40 41 jarrer = Jarrer() 42 43 with errors.accumulate(): 44 finder = FileFinder(args.C, find_executables=args.strip) 45 for path in args.input: 46 for p, f in finder.find(path): 47 if not any([match(p, exclude) for exclude in args.x]): 48 jarrer.add(p, f) 49 jarrer.copy(mozpath.join(args.C, args.zip)) 50 51 52if __name__ == "__main__": 53 log_build_task(main, sys.argv[1:]) 54