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 @@ ...@@ -6,8 +6,6 @@
"""Updates the Fuchsia SDK to the given revision. Should be used in a 'hooks_os' """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'.""" entry so that it only runs when .gclient's target_os includes 'fuchsia'."""
from __future__ import print_function
import argparse import argparse
import itertools import itertools
import logging import logging
...@@ -17,7 +15,6 @@ import shutil ...@@ -17,7 +15,6 @@ import shutil
import subprocess import subprocess
import sys import sys
import tarfile import tarfile
import tempfile
from common import GetHostOsFromPlatform, GetHostArchFromPlatform, \ from common import GetHostOsFromPlatform, GetHostArchFromPlatform, \
DIR_SOURCE_ROOT, SDK_ROOT, IMAGES_ROOT DIR_SOURCE_ROOT, SDK_ROOT, IMAGES_ROOT
...@@ -64,7 +61,7 @@ def GetSdkHashForPlatform(): ...@@ -64,7 +61,7 @@ def GetSdkHashForPlatform():
# If both files are empty, return an error. # If both files are empty, return an error.
if not sdk_hash and not extra_sdk_hash: if not sdk_hash and not extra_sdk_hash:
print( logging.error(
'No SHA1 found in {} or {}'.format(hash_file, extra_hash_file), 'No SHA1 found in {} or {}'.format(hash_file, extra_hash_file),
file=sys.stderr) file=sys.stderr)
return 1 return 1
...@@ -87,19 +84,6 @@ def EnsureDirExists(path): ...@@ -87,19 +84,6 @@ def EnsureDirExists(path):
os.makedirs(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 # Updates the modification timestamps of |path| and its contents to the
# current time. # current time.
def UpdateTimestampsRecursive(): def UpdateTimestampsRecursive():
...@@ -157,7 +141,8 @@ def DownloadSdkBootImages(sdk_hash, boot_image_names): ...@@ -157,7 +141,8 @@ def DownloadSdkBootImages(sdk_hash, boot_image_names):
if os.path.exists(image_output_dir): if os.path.exists(image_output_dir):
continue 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 = \ images_tarball_url = \
'gs://fuchsia/development/{sdk_hash}/images/'\ 'gs://fuchsia/development/{sdk_hash}/images/'\
'{device_type}-{arch}.tgz'.format( '{device_type}-{arch}.tgz'.format(
...@@ -177,7 +162,7 @@ def main(): ...@@ -177,7 +162,7 @@ def main():
'If omitted, no boot images will be downloaded.') 'If omitted, no boot images will be downloaded.')
args = parser.parse_args() 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. # Quietly exit if there's no SDK support for this platform.
try: try:
...@@ -185,45 +170,25 @@ def main(): ...@@ -185,45 +170,25 @@ def main():
except: except:
return 0 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() sdk_hash = GetSdkHashForPlatform()
if not sdk_hash: if not sdk_hash:
return 1 return 1
hash_filename = os.path.join(SDK_ROOT, '.hash') hash_filename = os.path.join(SDK_ROOT, '.hash')
if os.path.exists(hash_filename): if ((not os.path.exists(hash_filename))
with open(hash_filename, 'r') as f: or (open(hash_filename, 'r').read().strip() != sdk_hash)):
if f.read().strip() == sdk_hash: logging.info('Downloading SDK %s...' % 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): if os.path.isdir(SDK_ROOT):
shutil.rmtree(SDK_ROOT) shutil.rmtree(SDK_ROOT)
fd, tmp = tempfile.mkstemp()
os.close(fd)
EnsureDirExists(SDK_ROOT) EnsureDirExists(SDK_ROOT)
DownloadAndUnpackFromCloudStorage(GetSdkBucketForPlatform() + sdk_hash, DownloadAndUnpackFromCloudStorage(GetSdkBucketForPlatform() + sdk_hash,
SDK_ROOT) SDK_ROOT)
# Generate sdk/BUILD.gn. # 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')] cmd = [os.path.join(SDK_ROOT, '..', 'gen_build_defs.py')]
logging.debug("Running '%s'", " ".join(cmd)) logging.debug("Running '%s'", " ".join(cmd))
subprocess.check_call(cmd) subprocess.check_call(cmd)
...@@ -234,6 +199,9 @@ def main(): ...@@ -234,6 +199,9 @@ def main():
os.mkdir(IMAGES_ROOT) os.mkdir(IMAGES_ROOT)
try: 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) DownloadSdkBootImages(sdk_hash, args.boot_images)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
logging.error(( 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