• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright (C) 2015 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17"""Packages the platform's GCC for the NDK."""
18import os
19import site
20import subprocess
21import sys
22
23site.addsitedir(os.path.join(os.path.dirname(__file__), '../lib'))
24
25import build_support  # pylint: disable=import-error
26
27
28class ArgParser(build_support.ArgParser):
29    def __init__(self):  # pylint: disable=super-on-old-class
30        super(ArgParser, self).__init__()
31
32        self.add_argument(
33            '--arch', choices=build_support.ALL_ARCHITECTURES,
34            help='Architecture to build. Builds all if not present.')
35
36
37def get_gcc_prebuilt_path(host):
38    rel_prebuilt_path = 'prebuilts/ndk/current/toolchains/{}'.format(host)
39    prebuilt_path = os.path.join(build_support.android_path(),
40                                 rel_prebuilt_path)
41    if not os.path.isdir(prebuilt_path):
42        sys.exit('Could not find prebuilt GCC at {}'.format(prebuilt_path))
43    return prebuilt_path
44
45
46def package_gcc(package_dir, host_tag, arch, version):
47    toolchain_name = build_support.arch_to_toolchain(arch) + '-' + version
48    prebuilt_path = get_gcc_prebuilt_path(host_tag)
49
50    package_name = 'gcc-{}-{}.zip'.format(arch, host_tag)
51    package_path = os.path.join(package_dir, package_name)
52    if os.path.exists(package_path):
53        os.unlink(package_path)
54    os.chdir(prebuilt_path)
55    subprocess.check_call(
56        ['zip', '-9qr', package_path, toolchain_name])
57
58
59def main(args):
60    GCC_VERSION = '4.9'
61
62    arches = build_support.ALL_ARCHITECTURES
63    if args.arch is not None:
64        arches = [args.arch]
65
66    host_tag = build_support.host_to_tag(args.host)
67    for arch in arches:
68        package_gcc(args.dist_dir, host_tag, arch, GCC_VERSION)
69
70
71if __name__ == '__main__':
72    build_support.run(main, ArgParser)
73