-
Notifications
You must be signed in to change notification settings - Fork 25
/
aosp-minimal-regen.py
executable file
·168 lines (125 loc) · 4.83 KB
/
aosp-minimal-regen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python3
import os
import re
import sys
import xml.etree.ElementTree as ET
def groups_for_repo(repo, extra=[]):
groups = set(extra)
if re.match(r"device/.*[_-]kernel", repo):
groups.add("kernel")
if re.match(r"kernel/prebuilts/", repo):
groups.add("kernel")
if re.match(r"device/generic/.*mips", repo):
groups.add("mips")
if re.match(r"platform/prebuilts/.*/mips/.*", repo):
groups.add("mips")
if repo == "platform/external/chromium-webview":
groups.add("chromium")
if repo.startswith("platform/hardware/bsp/"):
groups.add("bsp")
if re.match(r"platform/prebuilts/.*darwin(-x86)?.*", repo):
groups.add("darwin")
if re.match(r"platform/prebuilts/.*windows(-x86)?.*", repo):
groups.add("windows")
return sorted(groups)
def get_git_repo(url, path):
if os.path.isdir(path):
print("Updating {} repository...".format(path))
repo = git.Repo(path)
repo.remote("origin").fetch()
else:
print("Downloading {} repository...".format(path))
repo = git.Repo.clone_from(url, path)
return repo
def parse_all_refs(manifest, refs):
repos = set()
for index, ref in enumerate(refs, 1):
print("\033[K[{}/{}] Parsing `{}`...".format(index, len(refs), ref), end="\r")
# Load the XML
try:
manifest_contents = manifest.git.show("{}:default.xml".format(ref))
except git.exc.GitCommandError as e:
print("Skipping revision '{}' with non-existing default.xml".format(ref))
continue
manifest_xml = ET.fromstring(manifest_contents)
for child in manifest_xml:
# Skip all non-project tags
if child.tag != "project":
continue
if "remote" in child.attrib and child.attrib["remote"] != "aosp":
print(
"Skipping project '{}' with non-AOSP remote '{}'".format(
child.attrib["name"], child.attrib["remote"]
)
)
continue
name = child.attrib["name"].rstrip("/")
# Fix a typo introduced in 5932ee3fa06190382680a4c804a54b45df5e3070
if name == "kernel//google-modules/uwb/qorvo/dw3000":
name = "kernel/google-modules/uwb/qorvo/dw3000"
repos.add(name)
return repos
try:
import git
except ImportError:
sys.exit("Please install the GitPython package via pip3")
# Clone (or update) the repositories
platform_manifest = get_git_repo(
"https://android.googlesource.com/platform/manifest", "aosp_manifest"
)
kernel_manifest = get_git_repo(
"https://android.googlesource.com/kernel/manifest", "aosp_kernel_manifest"
)
# Get all the refs
platform_refs = [
tag for tag in sorted(platform_manifest.git.tag(l=True).splitlines())
] # All the tags...
platform_refs.append("origin/main") # ...and main
kernel_refs = [
ref.name for ref in kernel_manifest.refs
] # All the refs, repo only has branches no tags...
# Skip a broken kernel ref
kernel_refs.remove("origin/android-gs-raviole-mainline")
# Look for repo names in each ref
platform_repos = parse_all_refs(platform_manifest, platform_refs)
kernel_repos = parse_all_refs(kernel_manifest, kernel_refs)
# Always add the manifest so one can sync from this mirror
platform_repos.add("platform/manifest")
kernel_repos.add("kernel/manifest")
# Include repositories that we added to the default manifest ourselves
platform_repos.add("kernel/prebuilts/build-tools")
platform_repos.add("platform/external/dwarves")
platform_repos.add("platform/prebuilts/gas/linux-x86")
# Remove kernel repositories that are already in the platform manifest
kernel_repos = kernel_repos - platform_repos
# Generate groups for all repositories
repos = {}
for repo in platform_repos:
repos[repo] = groups_for_repo(repo)
for repo in kernel_repos:
repos[repo] = groups_for_repo(repo, extra=["kernel-extra", "notdefault"])
file = open("aosp-minimal.xml", "w")
file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
file.write("<manifest>\n")
file.write("\n")
file.write(' <remote name="aosp"\n')
file.write(' fetch="https://android.googlesource.com" />\n')
file.write(' <default revision="main"\n')
file.write(' remote="aosp"\n')
file.write(' sync-j="4" />\n')
file.write("\n")
for repo in sorted(repos):
# remove an unavailable repository
if repo == "platform/packages/apps/OMA-DM":
continue
line = 'name="' + repo + '"'
# Would we get a path conflict?
if any(s.startswith(repo + "/") for s in repos):
line += ' path="' + repo + '.git"'
# Add groups
groups = repos[repo]
if len(groups) > 0:
line += ' groups="' + ",".join(groups) + '"'
file.write(" <project " + line + " />\n")
file.write("</manifest>\n")
file.close()