Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright 2014 The Chromium Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | """Invokes Android's aidl |
| 8 | """ |
| 9 | |
| 10 | import optparse |
| 11 | import os |
| 12 | import re |
| 13 | import sys |
| 14 | import zipfile |
| 15 | |
| 16 | from util import build_utils |
| 17 | |
| 18 | |
| 19 | def main(argv): |
| 20 | option_parser = optparse.OptionParser() |
| 21 | build_utils.AddDepfileOption(option_parser) |
| 22 | option_parser.add_option('--aidl-path', help='Path to the aidl binary.') |
| 23 | option_parser.add_option('--imports', help='Files to import.') |
| 24 | option_parser.add_option('--includes', |
| 25 | help='Directories to add as import search paths.') |
| 26 | option_parser.add_option('--srcjar', help='Path for srcjar output.') |
| 27 | options, args = option_parser.parse_args(argv[1:]) |
| 28 | |
| 29 | with build_utils.TempDir() as temp_dir: |
| 30 | for f in args: |
| 31 | classname = os.path.splitext(os.path.basename(f))[0] |
| 32 | output = os.path.join(temp_dir, classname + '.java') |
| 33 | aidl_cmd = [options.aidl_path] |
| 34 | aidl_cmd += [ |
| 35 | '-p' + s for s in build_utils.ParseGypList(options.imports) |
| 36 | ] |
| 37 | if options.includes is not None: |
| 38 | aidl_cmd += [ |
| 39 | '-I' + s for s in build_utils.ParseGypList(options.includes) |
| 40 | ] |
| 41 | aidl_cmd += [ |
| 42 | f, |
| 43 | output |
| 44 | ] |
| 45 | build_utils.CheckOutput(aidl_cmd) |
| 46 | |
| 47 | with zipfile.ZipFile(options.srcjar, 'w') as srcjar: |
| 48 | for path in build_utils.FindInDirectory(temp_dir, '*.java'): |
| 49 | with open(path) as fileobj: |
| 50 | data = fileobj.read() |
| 51 | pkg_name = re.search(r'^\s*package\s+(.*?)\s*;', data, re.M).group(1) |
| 52 | arcname = '%s/%s' % (pkg_name.replace('.', '/'), os.path.basename(path)) |
| 53 | srcjar.writestr(arcname, data) |
| 54 | |
| 55 | if options.depfile: |
| 56 | build_utils.WriteDepfile( |
| 57 | options.depfile, |
| 58 | build_utils.GetPythonDependencies()) |
| 59 | |
| 60 | |
| 61 | if __name__ == '__main__': |
| 62 | sys.exit(main(sys.argv)) |