blob: bef9413b912a8328d8585fb1181f56b67447da63 [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
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020017AOSP_MANIFEST_XML = join(utils.REPO_ROOT, 'third_party', 'aosp_manifest.xml')
Søren Gjesse298759e2017-09-08 08:22:41 +020018AOSP_MANIFEST_URL = 'https://android.googlesource.com/platform/manifest'
Søren Gjesse298759e2017-09-08 08:22:41 +020019J_DEFAULT = multiprocessing.cpu_count() - 2
20
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020021
Søren Gjesse298759e2017-09-08 08:22:41 +020022# 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):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020024 utils.makedirs_if_needed(aosp_root)
25 command = ['repo', 'init', '-u', url]
26 if (shallow):
27 command.extend(['--depth=1'])
28 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
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020037 check_call(['repo', 'sync', '-dq', '-j' + concurrency], cwd=aosp_root)
38
Søren Gjesse298759e2017-09-08 08:22:41 +020039
40def parse_arguments():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020041 parser = argparse.ArgumentParser(
42 description='Checkout the AOSP source tree.')
43 utils_aosp.add_root_argument(parser)
44 parser.add_argument('--url',
45 help='URL the repo. ' + 'Defaults to ' +
46 AOSP_MANIFEST_URL + '.',
47 default=AOSP_MANIFEST_URL)
48 parser.add_argument('--manifest',
49 help='Manifest to use for the checkout. ' +
50 'Defaults to ' + AOSP_MANIFEST_XML + '.',
51 default=AOSP_MANIFEST_XML)
52 parser.add_argument('--branch',
53 help='Branch to checkout. This overrides ' +
54 'passing --manifest')
55 parser.add_argument('--shallow',
56 action='store_true',
57 help='Shallow checkout.')
58 parser.add_argument('-j',
59 help='Projects to fetch simultaneously. ' +
60 'Defaults to ' + str(J_DEFAULT) + '.',
61 default=str(J_DEFAULT))
62 return parser.parse_args()
63
Søren Gjesse298759e2017-09-08 08:22:41 +020064
65def Main():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020066 args = parse_arguments()
67 checkout_aosp(args.aosp_root, args.url, args.branch, args.manifest, args.j,
68 args.shallow)
69
Søren Gjesse298759e2017-09-08 08:22:41 +020070
71if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020072 sys.exit(Main())