blob: 4082fc7782e2d33e08986967c5a9348e3a958b0a [file] [log] [blame]
Tibor Goldschwendtc748dfca42019-10-24 19:39:051#!/usr/bin/env python
2#
3# Copyright 2019 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"""Writes Java module descriptor to srcjar file."""
7
8import argparse
9import os
10import sys
11import zipfile
12
13sys.path.append(
14 os.path.join(
15 os.path.dirname(__file__), '..', '..', '..', 'build', 'android', 'gyp'))
16from util import build_utils
17
18_TEMPLATE = '''\
19// This file is autogenerated by
20// components/module_installer/android/module_desc_java.py
21// Please do not change its content.
22
23package org.chromium.components.module_installer.builder;
24
25import org.chromium.base.annotations.UsedByReflection;
26
27@UsedByReflection("Module.java")
28public class ModuleDescriptor_{MODULE} implements ModuleDescriptor {{
29 private static final String[] LIBRARIES = {{{LIBRARIES}}};
30
31 @Override
32 public String[] getLibraries() {{
33 return LIBRARIES;
34 }}
35}}
36'''
37
38
39def main():
40 parser = argparse.ArgumentParser()
41 parser.add_argument('--module', required=True, help='The module name.')
42 parser.add_argument(
43 '--libraries', required=True, help='GN list of native library paths.')
44 parser.add_argument(
45 '--output', required=True, help='Path to the generated srcjar file.')
46 options = parser.parse_args(build_utils.ExpandFileArgs(sys.argv[1:]))
47 options.libraries = build_utils.ParseGnList(options.libraries)
48
49 libraries = []
50 for path in options.libraries:
51 path = path.strip()
52 filename = os.path.split(path)[1]
53 assert filename.startswith('lib')
54 assert filename.endswith('.so')
55 # Remove lib prefix and .so suffix.
56 libraries += [filename[3:-3]]
57
58 format_dict = {
59 'MODULE': options.module,
60 'LIBRARIES': ','.join(['"%s"' % l for l in libraries]),
61 }
62 with build_utils.AtomicOutput(options.output) as f:
63 with zipfile.ZipFile(f.name, 'w') as srcjar_file:
64 build_utils.AddToZipHermetic(
65 srcjar_file,
66 'org/chromium/components/module_installer/builder/'
67 'ModuleDescriptor_%s.java' % options.module,
68 data=_TEMPLATE.format(**format_dict))
69
70
71if __name__ == '__main__':
72 sys.exit(main())