blob: 842ae3b6496a4db5c4e26f39e5a04010e8e1f284 [file] [log] [blame]
Søren Gjesse298759e2017-09-08 08:22:41 +02001#!/usr/bin/env python
2# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6from os.path import basename, join
7from shutil import copy2
8from subprocess import check_call
9import argparse
10import multiprocessing
11import os
12import sys
13
14import utils
Søren Gjesse9bfed012017-09-15 08:15:44 +020015import utils_aosp
Søren Gjesse298759e2017-09-08 08:22:41 +020016
17AOSP_MANIFEST_XML = join(utils.REPO_ROOT, 'third_party',
18 'aosp_manifest.xml')
19AOSP_MANIFEST_URL = 'https://android.googlesource.com/platform/manifest'
20
21J_DEFAULT = multiprocessing.cpu_count() - 2
22
23# Checkout AOSP source to the specified direcotry using the speficied manifest.
Søren Gjesse18c5cf12017-09-15 09:02:29 +020024def checkout_aosp(aosp_root, url, branch, manifest_xml, concurrency):
25 utils.makedirs_if_needed(aosp_root)
26 command = ['repo', 'init', '-u', url, '--depth=1']
27 if (branch):
28 command.extend(['-b', branch])
29 else:
30 manifests_dir = join(aosp_root, '.repo', 'manifests')
31 utils.makedirs_if_needed(manifests_dir)
32 copy2(manifest_xml, manifests_dir)
33 command.extend(['-m', basename(manifest_xml)])
34 check_call(command, cwd = aosp_root)
Søren Gjesse298759e2017-09-08 08:22:41 +020035
36 check_call(['repo', 'sync', '-dq', '-j' + concurrency], cwd = aosp_root)
37
38def parse_arguments():
39 parser = argparse.ArgumentParser(
40 description = 'Checkout the AOSP source tree.')
Søren Gjesse9bfed012017-09-15 08:15:44 +020041 utils_aosp.add_root_argument(parser)
Søren Gjesse18c5cf12017-09-15 09:02:29 +020042 parser.add_argument('--url',
43 help='URL the repo. ' +
44 'Defaults to ' + AOSP_MANIFEST_URL + '.',
45 default=AOSP_MANIFEST_URL)
Søren Gjesse298759e2017-09-08 08:22:41 +020046 parser.add_argument('--manifest',
47 help='Manifest to use for the checkout. ' +
48 'Defaults to ' + AOSP_MANIFEST_XML + '.',
49 default=AOSP_MANIFEST_XML)
Søren Gjesse18c5cf12017-09-15 09:02:29 +020050 parser.add_argument('--branch',
51 help='Branch to checkout. This overrides ' +
52 'passing --manifest')
Søren Gjesse298759e2017-09-08 08:22:41 +020053 parser.add_argument('-j',
54 help='Projects to fetch simultaneously. ' +
55 'Defaults to ' + str(J_DEFAULT) + '.',
56 default=str(J_DEFAULT))
57 return parser.parse_args()
58
59def Main():
60 args = parse_arguments()
Søren Gjesse18c5cf12017-09-15 09:02:29 +020061 checkout_aosp(args.aosp_root, args.url, args.branch, args.manifest, args.j)
Søren Gjesse298759e2017-09-08 08:22:41 +020062
63if __name__ == '__main__':
64 sys.exit(Main())