Commit ffda6b98 authored by Wez's avatar Wez Committed by Commit Bot

[fuchsia] Remove legacy Fuchsia SDK cleanup & tidy up logging.

Remove logic from update-sdk.py for cleaning up the Fuchsia SDK from the
old download path, since it has been ~years since we migrated.

Replace all use of print() with logging.info() and set default logging
level to logging.INFO.

Bug: 1050703
Change-Id: I816d68988506fd6d5c7b98514048b41c34ab550f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056809Reviewed-by: default avatarFabrice de Gans-Riberi <fdegans@chromium.org>
Commit-Queue: Fabrice de Gans-Riberi <fdegans@chromium.org>
Auto-Submit: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741514}
parent 287a1627
......@@ -6,8 +6,6 @@
"""Updates the Fuchsia SDK to the given revision. Should be used in a 'hooks_os'
entry so that it only runs when .gclient's target_os includes 'fuchsia'."""
from __future__ import print_function
import argparse
import itertools
import logging
......@@ -17,7 +15,6 @@ import shutil
import subprocess
import sys
import tarfile
import tempfile
from common import GetHostOsFromPlatform, GetHostArchFromPlatform, \
DIR_SOURCE_ROOT, SDK_ROOT, IMAGES_ROOT
......@@ -64,7 +61,7 @@ def GetSdkHashForPlatform():
# If both files are empty, return an error.
if not sdk_hash and not extra_sdk_hash:
print(
logging.error(
'No SHA1 found in {} or {}'.format(hash_file, extra_hash_file),
file=sys.stderr)
return 1
......@@ -87,19 +84,6 @@ def EnsureDirExists(path):
os.makedirs(path)
# Removes legacy SDK if it's detected.
def CleanupLegacySDK():
legacy_sdk_root = os.path.join(DIR_SOURCE_ROOT, 'third_party', 'fuchsia-sdk')
hash_file = os.path.join(legacy_sdk_root, '.hash')
if os.path.exists(hash_file):
print('Removing legacy SDK.')
for d in SDK_SUBDIRS:
to_remove = os.path.join(legacy_sdk_root, d)
if os.path.isdir(to_remove):
shutil.rmtree(to_remove)
os.remove(hash_file)
# Updates the modification timestamps of |path| and its contents to the
# current time.
def UpdateTimestampsRecursive():
......@@ -157,7 +141,8 @@ def DownloadSdkBootImages(sdk_hash, boot_image_names):
if os.path.exists(image_output_dir):
continue
print('Downloading Fuchsia boot images for %s.%s...' % (device_type, arch))
logging.info(
'Downloading Fuchsia boot images for %s.%s...' % (device_type, arch))
images_tarball_url = \
'gs://fuchsia/development/{sdk_hash}/images/'\
'{device_type}-{arch}.tgz'.format(
......@@ -177,7 +162,7 @@ def main():
'If omitted, no boot images will be downloaded.')
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.WARNING)
logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
# Quietly exit if there's no SDK support for this platform.
try:
......@@ -185,45 +170,25 @@ def main():
except:
return 0
# Previously SDK was unpacked in //third_party/fuchsia-sdk instead of
# //third_party/fuchsia-sdk/sdk . Remove the old files if they are still
# there.
CleanupLegacySDK()
sdk_hash = GetSdkHashForPlatform()
if not sdk_hash:
return 1
hash_filename = os.path.join(SDK_ROOT, '.hash')
if os.path.exists(hash_filename):
with open(hash_filename, 'r') as f:
if f.read().strip() == sdk_hash:
# Ensure that the boot images are downloaded for this SDK.
# If the developer opted into downloading hardware boot images in their
# .gclient file, then only the hardware boot images will be downloaded.
DownloadSdkBootImages(sdk_hash, args.boot_images)
# Nothing to do. Generate sdk/BUILD.gn anyway, in case the conversion
# script changed.
logging.info("Generating sdk/BUILD.gn")
cmd = [os.path.join(SDK_ROOT, '..', 'gen_build_defs.py')]
logging.debug("Running '%s'", " ".join(cmd))
subprocess.check_call(cmd)
return 0
print('Downloading SDK %s...' % sdk_hash)
if os.path.isdir(SDK_ROOT):
shutil.rmtree(SDK_ROOT)
fd, tmp = tempfile.mkstemp()
os.close(fd)
EnsureDirExists(SDK_ROOT)
DownloadAndUnpackFromCloudStorage(GetSdkBucketForPlatform() + sdk_hash,
SDK_ROOT)
# Generate sdk/BUILD.gn.
if ((not os.path.exists(hash_filename))
or (open(hash_filename, 'r').read().strip() != sdk_hash)):
logging.info('Downloading SDK %s...' % sdk_hash)
if os.path.isdir(SDK_ROOT):
shutil.rmtree(SDK_ROOT)
EnsureDirExists(SDK_ROOT)
DownloadAndUnpackFromCloudStorage(GetSdkBucketForPlatform() + sdk_hash,
SDK_ROOT)
# Always re-generate sdk/BUILD.gn, even if the SDK hash has not changed,
# in case the gen_build_defs.py script changed.
logging.info("Generating sdk/BUILD.gn")
cmd = [os.path.join(SDK_ROOT, '..', 'gen_build_defs.py')]
logging.debug("Running '%s'", " ".join(cmd))
subprocess.check_call(cmd)
......@@ -234,6 +199,9 @@ def main():
os.mkdir(IMAGES_ROOT)
try:
# Ensure that the boot images are downloaded for this SDK.
# If the developer opted into downloading hardware boot images in their
# .gclient file, then only the hardware boot images will be downloaded.
DownloadSdkBootImages(sdk_hash, args.boot_images)
except subprocess.CalledProcessError as e:
logging.error((
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment