This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathget_source.py
executable file
·159 lines (124 loc) · 5.16 KB
/
get_source.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
#!/usr/bin/env python3
#
# Copyright © 2022 Github Lzhiyong
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pylint: disable=not-callable, line-too-long, no-else-return
import os
import requests
import tarfile
import shutil
import argparse
import subprocess
import json
from pathlib import Path
def untar(source, target):
tar = tarfile.open(source)
names = tar.getnames()
if os.path.isdir(target):
pass
else:
os.mkdir(target)
for name in names:
tar.extract(name, target)
tar.close()
def download(url, displayname, target):
print("downloading {}".format(displayname))
filename = os.path.basename(url)
content = requests.get(url).content
with open(filename, 'wb') as file:
file.write(content)
# extract tar file
print("extracting {} to {}".format(filename, target))
untar(filename, target)
# delete file
if os.path.exists(filename):
os.remove(filename)
def download_repo(path, url, tag):
if os.path.isdir(path):
print("Skipping {} as it is already cloned".format(path))
return True
print("Cloning repo {}".format(path))
command = "git clone -c advice.detachedHead=false {} --branch={} --depth=1 {}".format(url, tag, path)
subprocess.run(command.split(), shell=False, check=True)
print()
print()
return True
def patches():
inc = Path(os.getcwd() + "/src/incremental_delivery/sysprop/include")
if not inc.exists():
inc.mkdir()
shutil.copy2(Path("patches/misc/IncrementalProperties.sysprop.h"), inc)
shutil.copy2(
Path("patches/misc/IncrementalProperties.sysprop.cpp"), inc.parent)
shutil.copy2(Path("patches/misc/deployagent.inc"),
Path("src/adb/fastdeploy/deployagent"))
shutil.copy2(Path("patches/misc/deployagentscript.inc"),
Path("src/adb/fastdeploy/deployagent"))
shutil.copy2(Path("patches/misc/selabel_handle_utils.h"),
Path("src/selinux/libselinux/src"))
shutil.copy2(Path("patches/misc/selabel_handle_utils.c"),
Path("src/selinux/libselinux/src"))
shutil.copy2(Path("patches/misc/platform_tools_version.h"),
Path("src/libbuildversion/include"))
pattern = "\'s/frameworks\/base\/tools\/aapt2\/Configuration\.proto/Configuration\.proto/g\'"
pattern2 = "\'s/frameworks\/base\/tools\/aapt2\/Resources\.proto/Resources\.proto/g\'"
subprocess.run("sed -i {} {}".format(pattern, os.getcwd() +
"/src/base/tools/aapt2/Resources.proto"), shell=True)
subprocess.run("sed -i {} {}".format(pattern, os.getcwd() +
"/src/base/tools/aapt2/ResourcesInternal.proto"), shell=True)
subprocess.run("sed -i {} {}".format(pattern2, os.getcwd() +
"/src/base/tools/aapt2/ResourcesInternal.proto"), shell=True)
pattern3 = "\'s/\/usr\/src\/googletest/\$\{CMAKE_SOURCE_DIR\}\/src\/googletest/g\'"
subprocess.run("sed -i {} {}".format(pattern3, os.getcwd() +
"/src/abseil-cpp/CMakeLists.txt"), shell=True)
def check(command):
try:
output = subprocess.check_output(
"command -v {}".format(command), shell=True)
print(output.decode("utf-8"))
except subprocess.CalledProcessError as e:
print("please install the {} package".format(command))
exit()
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--tag", help="Specify the tag to download", required=True)
args = parser.parse_args()
# check git
check("git")
# check golang
check("go")
with open("repos.json") as repos_file:
repos = json.load(repos_file)
for repo in repos:
if not download_repo(repo['path'], repo['url'], args.tag):
break
# DO NOT DOWNLOAD THIS FROM TAG!!!
url = "https://android.googlesource.com/platform/system/libziparchive/+archive/9b2d511d0f3d656f879d18bdc542f7860f53aab6.tar.gz"
download(url, os.path.basename(url), "src/libziparchive")
# zipalign
url = "https://android.googlesource.com/platform/build.git/+archive/refs/tags/platform-tools-33.0.3/tools/zipalign.tar.gz"
download(url, os.path.basename(url), "src/zipalign")
# etc1tool
url = "https://android.googlesource.com/platform/development/+archive/refs/tags/platform-tools-33.0.3/tools/etc1tool.tar.gz"
download(url, os.path.basename(url), "src/etc1tool")
# libbuildversion
url = "https://android.googlesource.com/platform/build/soong/+archive/refs/tags/platform-tools-33.0.3/cc/libbuildversion.tar.gz"
download(url, os.path.basename(url), "src/libbuildversion")
# patch files
patches()
print("download success!!")
if __name__ == "__main__":
main()