-
Notifications
You must be signed in to change notification settings - Fork 25
/
caf-minimal-regen.py
executable file
·179 lines (134 loc) · 5.01 KB
/
caf-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
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env python3
import os
import re
import sys
import xml.etree.ElementTree as ET
# Checks what file should be checked for that specific revision
def manifest_for_ref(ref):
# Only default.xml was updated
if ref == "M7201JSDCBALYA6375":
return "default"
if ref.startswith("AU_LINUX_ANDROID_") or ref.startswith("AU_LINUX_KERNEL."):
return "caf_{}".format(ref)
return ref
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")
manifest_name = manifest_for_ref(ref)
if manifest_name is None:
continue
# Load the XML
manifest_xml = ET.fromstring(
manifest.git.show("{}:{}.xml".format(ref, manifest_name))
)
# Check for the correct remote
for remote in manifest_xml.findall("remote"):
if remote.attrib["fetch"] == "https://source.codeaurora.org/quic/la/":
break
else:
# This runs if no break has been encountered
continue
for child in manifest_xml.findall("project"):
# Filter remaining quic/ repos
if child.attrib["name"].startswith("quic/"):
continue
repos.add(child.attrib["name"])
return repos
try:
import git
except ImportError:
sys.exit("Please install the GitPython package via pip3")
# Clone (or update) the repositories
# Use AOSP repository for filtering AOSP tags
platform_manifest = get_git_repo(
"https://source.codeaurora.org/quic/la/platform/manifest", "caf_manifest"
)
kernel_manifest = get_git_repo(
"https://source.codeaurora.org/quic/la/kernelplatform/manifest",
"caf_kernel_manifest",
)
aosp_manifest = get_git_repo(
"https://android.googlesource.com/platform/manifest", "aosp_manifest"
)
# Get all the refs
platform_refs = [tag for tag in sorted(platform_manifest.git.tag(l=True).splitlines())]
kernel_refs = [tag for tag in sorted(kernel_manifest.git.tag(l=True).splitlines())]
aosp_refs = [tag for tag in sorted(aosp_manifest.git.tag(l=True).splitlines())]
# Exclude refs found on AOSP (assume that `android-*` is also from there)
platform_refs = [
ref
for ref in platform_refs
if not ref.startswith("android-") and ref not in aosp_refs
]
# Skip a broken ref
platform_refs.remove("M7630AABBQVLZA0020")
# 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("kernelplatform/manifest")
# 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("caf-minimal.xml", "w")
file.write('<?xml version="1.0" encoding="UTF-8"?>\n')
file.write("<manifest>\n")
file.write("\n")
file.write(' <remote name="caf"\n')
file.write(' fetch="https://source.codeaurora.org/quic/la/" />\n')
file.write(' <default revision="master"\n')
file.write(' remote="caf"\n')
file.write(' sync-j="4" />\n')
file.write("\n")
for repo in sorted(repos):
# Remove a few repositories
if repo == "platform/tools/vendor/google_prebuilts/arc" or repo.startswith(
"platform/vendor/google_"
):
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()