blob: 36a533342a4ac7633320dcf93deb7304f9c0972b [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Søren Gjesse298759e2017-09-08 08:22:41 +02002# 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'
Søren Gjesse298759e2017-09-08 08:22:41 +020020J_DEFAULT = multiprocessing.cpu_count() - 2
21
22# Checkout AOSP source to the specified direcotry using the speficied manifest.
Søren Gjesseadfde762017-10-13 09:51:38 +020023def checkout_aosp(aosp_root, url, branch, manifest_xml, concurrency, shallow):
Søren Gjesse18c5cf12017-09-15 09:02:29 +020024 utils.makedirs_if_needed(aosp_root)
Søren Gjesseadfde762017-10-13 09:51:38 +020025 command = ['repo', 'init', '-u', url]
26 if (shallow):
27 command.extend(['--depth=1'])
Søren Gjesse18c5cf12017-09-15 09:02:29 +020028 if (branch):
29 command.extend(['-b', branch])
30 else:
31 manifests_dir = join(aosp_root, '.repo', 'manifests')
32 utils.makedirs_if_needed(manifests_dir)
33 copy2(manifest_xml, manifests_dir)
34 command.extend(['-m', basename(manifest_xml)])
35 check_call(command, cwd = aosp_root)
Søren Gjesse298759e2017-09-08 08:22:41 +020036
37 check_call(['repo', 'sync', '-dq', '-j' + concurrency], cwd = aosp_root)
38
39def parse_arguments():
40 parser = argparse.ArgumentParser(
41 description = 'Checkout the AOSP source tree.')
Søren Gjesse9bfed012017-09-15 08:15:44 +020042 utils_aosp.add_root_argument(parser)
Søren Gjesse18c5cf12017-09-15 09:02:29 +020043 parser.add_argument('--url',
44 help='URL the repo. ' +
45 'Defaults to ' + AOSP_MANIFEST_URL + '.',
46 default=AOSP_MANIFEST_URL)
Søren Gjesse298759e2017-09-08 08:22:41 +020047 parser.add_argument('--manifest',
48 help='Manifest to use for the checkout. ' +
49 'Defaults to ' + AOSP_MANIFEST_XML + '.',
50 default=AOSP_MANIFEST_XML)
Søren Gjesse18c5cf12017-09-15 09:02:29 +020051 parser.add_argument('--branch',
52 help='Branch to checkout. This overrides ' +
53 'passing --manifest')
Søren Gjesseadfde762017-10-13 09:51:38 +020054 parser.add_argument('--shallow',
55 action = 'store_true',
56 help='Shallow checkout.')
Søren Gjesse298759e2017-09-08 08:22:41 +020057 parser.add_argument('-j',
58 help='Projects to fetch simultaneously. ' +
59 'Defaults to ' + str(J_DEFAULT) + '.',
60 default=str(J_DEFAULT))
61 return parser.parse_args()
62
63def Main():
64 args = parse_arguments()
Søren Gjesseadfde762017-10-13 09:51:38 +020065 checkout_aosp(args.aosp_root, args.url, args.branch, args.manifest,
66 args.j, args.shallow)
Søren Gjesse298759e2017-09-08 08:22:41 +020067
68if __name__ == '__main__':
69 sys.exit(Main())