bootstrap-android: always run sdkmanager

It is quick when already up to date
This commit is contained in:
Simon Sapin 2018-06-28 16:22:15 +02:00
parent aa1c3cea2f
commit 65122b10d3

View file

@ -108,46 +108,45 @@ class MachCommands(CommandBase):
ndk_path = download(ndk.format(system=system, arch=arch), "ndk", flatten=True) ndk_path = download(ndk.format(system=system, arch=arch), "ndk", flatten=True)
tools_path = download(tools.format(system=system), "sdk") tools_path = download(tools.format(system=system), "sdk")
if update or not path.isdir(path.join(tools_path, "platform-tools")): subprocess.check_call([
subprocess.check_call([ path.join(tools_path, "tools", "bin", "sdkmanager"),
path.join(tools_path, "tools", "bin", "sdkmanager"), "platform-tools",
"platform-tools", "build-tools;" + sdk_build_tools,
"build-tools;" + sdk_build_tools, "emulator",
"emulator", ] + [
] + [ arg
arg for avd_name, api_level, system_image in emulator_images
for avd_name, api_level, system_image in emulator_images for arg in [
for arg in [ "platforms;android-" + api_level,
"platforms;android-" + api_level, "system-images;android-%s;%s" % (api_level, system_image),
"system-images;android-%s;%s" % (api_level, system_image), ]
] ])
for avd_name, api_level, system_image in emulator_images:
process = subprocess.Popen(stdin=subprocess.PIPE, stdout=subprocess.PIPE, args=[
path.join(tools_path, "tools", "bin", "avdmanager"),
"create", "avd",
"--path", path.join(toolchains, "avd", avd_name),
"--name", avd_name,
"--package", "system-images;android-%s;%s" % (api_level, system_image),
"--force",
]) ])
for avd_name, api_level, system_image in emulator_images: output = b""
process = subprocess.Popen(stdin=subprocess.PIPE, stdout=subprocess.PIPE, args=[ while 1:
path.join(tools_path, "tools", "bin", "avdmanager"), # Read one byte at a time because in Python:
"create", "avd", # * readline() blocks until "\n", which doesn't come before the prompt
"--path", path.join(toolchains, "avd", avd_name), # * read() blocks until EOF, which doesn't come before the prompt
"--name", avd_name, # * read(n) keeps reading until it gets n bytes or EOF,
"--package", "system-images;android-%s;%s" % (api_level, system_image), # but we don't know reliably how many bytes to read until the prompt
"--force", byte = process.stdout.read(1)
]) if len(byte) == 0:
output = b"" break
while 1: output += byte
# Read one byte at a time because in Python: # There seems to be no way to disable this prompt:
# * readline() blocks until "\n", which doesn't come before the prompt if output.endswith(b"Do you wish to create a custom hardware profile? [no]"):
# * read() blocks until EOF, which doesn't come before the prompt process.stdin.write("no\n")
# * read(n) keeps reading until it gets n bytes or EOF, assert process.wait() == 0
# but we don't know reliably how many bytes to read until the prompt with open(path.join(toolchains, "avd", avd_name, "config.ini"), "a") as f:
byte = process.stdout.read(1) f.write("disk.dataPartition.size=1G\n")
if len(byte) == 0:
break
output += byte
# There seems to be no way to disable this prompt:
if output.endswith(b"Do you wish to create a custom hardware profile? [no]"):
process.stdin.write("no\n")
assert process.wait() == 0
with open(path.join(toolchains, "avd", avd_name, "config.ini"), "a") as f:
f.write("disk.dataPartition.size=1G\n")
print("") print("")
print("export ANDROID_SDK=\"%s\"" % tools_path) print("export ANDROID_SDK=\"%s\"" % tools_path)