• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# Copyright (c) 2021 Huawei Device Co., Ltd.
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
16import optparse
17import os
18import sys
19import json
20
21sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
22from scripts.util import build_utils  # noqa: E402
23
24MAP_FILE_TEMPLATE = '''
25%s {
26  global:
27  %s
28  local:
29  *;
30};
31'''
32
33
34def parse_args(args):
35    args = build_utils.expand_file_args(args)
36
37    parser = optparse.OptionParser()
38    build_utils.add_depfile_option(parser)
39    parser.add_option('--output', help='generated ndk stub file')
40    parser.add_option('--ndk-description-file', help='ndk description file')
41    parser.add_option('--shlib-name', help='output name of shared library')
42
43    options, _ = parser.parse_args(args)
44    return options
45
46
47def generate_version_script(options):
48    contents = []
49    with open(options.ndk_description_file, 'r') as f:
50        interfaces = json.load(f)
51        for inf in interfaces:
52            name = inf['name']
53            contents.append('\t%s;' % name)
54    with open(options.output, 'w') as f:
55        f.write(MAP_FILE_TEMPLATE %
56                (options.shlib_name.upper(), '\n'.join(contents)))
57
58
59def main(args):
60    options = parse_args(args)
61
62    depfile_deps = ([options.ndk_description_file])
63
64    build_utils.call_and_write_depfile_if_stale(
65        lambda: generate_version_script(options),
66        options,
67        depfile_deps=depfile_deps,
68        input_paths=depfile_deps,
69        input_strings=[options.shlib_name],
70        output_paths=([options.output]),
71        force=False,
72        add_pydeps=False)
73
74
75if __name__ == '__main__':
76    sys.exit(main(sys.argv[1:]))
77