def _GetSdkHashList(bucket): """Read filename entries from sdk-hash-files.list (one per line), substitute {platform} in each entry if present, and read from each filename.""" if bucket == 'fuchsia-sdk': assert (GetHostOsFromPlatform() == 'linux') platform = 'linux_internal' else: platform = GetHostOsFromPlatform() filenames = [ line.strip() for line in _ReadFile('sdk-hash-files.list').replace( '{platform}', platform).splitlines() ] sdk_hashes = [_ReadFile(filename).strip() for filename in filenames] return sdk_hashes
def GetSdkHashForPlatform(): filename = '{platform}.sdk.sha1'.format(platform=GetHostOsFromPlatform()) # Get the hash of the SDK in chromium. sdk_hash = None hash_file = os.path.join(os.path.dirname(__file__), filename) with open(hash_file, 'r') as f: sdk_hash = f.read().strip() # Get the hash of the SDK with the extra prefix. extra_sdk_hash = None if EXTRA_SDK_HASH_PREFIX: extra_hash_file = os.path.join(os.path.dirname(__file__), EXTRA_SDK_HASH_PREFIX + filename) with open(extra_hash_file, 'r') as f: extra_sdk_hash = f.read().strip() # If both files are empty, return an error. if not sdk_hash and not extra_sdk_hash: print >> sys.stderr, 'No SHA1 found in {} or {}'.format( hash_file, extra_hash_file) return 1 # Return the newer SDK based on the generation number. sdk_generation = GetSdkGeneration(sdk_hash) extra_sdk_generation = GetSdkGeneration(extra_sdk_hash) if extra_sdk_generation > sdk_generation: return extra_sdk_hash return sdk_hash
def main(): if len(sys.argv) != 1: print >>sys.stderr, 'usage: %s' % sys.argv[0] return 1 # Quietly exit if there's no SDK support for this platform. try: GetHostOsFromPlatform() 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. sdk_root = os.path.join(REPOSITORY_ROOT, 'third_party', 'fuchsia-sdk') Cleanup(sdk_root) sdk_hash = GetSdkHashForPlatform() if not sdk_hash: return 1 output_dir = os.path.join(sdk_root, 'sdk') hash_filename = os.path.join(output_dir, '.hash') if os.path.exists(hash_filename): with open(hash_filename, 'r') as f: if f.read().strip() == sdk_hash: # Nothing to do. Generate sdk/BUILD.gn anyways, in case the conversion # script changed. subprocess.check_call([os.path.join(sdk_root, 'gen_build_defs.py')]) return 0 print 'Downloading SDK %s...' % sdk_hash if os.path.isdir(output_dir): shutil.rmtree(output_dir) fd, tmp = tempfile.mkstemp() os.close(fd) try: cmd = [os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gsutil.py'), 'cp', GetBucketForPlatform() + sdk_hash, tmp] subprocess.check_call(cmd) with open(tmp, 'rb') as f: EnsureDirExists(output_dir) tarfile.open(mode='r:gz', fileobj=f).extractall(path=output_dir) finally: os.remove(tmp) # Generate sdk/BUILD.gn. subprocess.check_call([os.path.join(sdk_root, 'gen_build_defs.py')]) with open(hash_filename, 'w') as f: f.write(sdk_hash) UpdateTimestampsRecursive(output_dir) return 0
def main(): if len(sys.argv) != 1: print('usage: %s' % sys.argv[0], file=sys.stderr) return 1 # Quietly exit if there's no SDK support for this platform. try: GetHostOsFromPlatform() 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. Cleanup() 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: # Used to download boot images if "gclient runhooks" is called on a # output directory which had previously built Fuchsia on the same SDK # hash, but did not use separate boot images. if not os.path.exists(IMAGES_ROOT): DownloadSdkBootImages(sdk_hash) # Nothing to do. Generate sdk/BUILD.gn anyway, in case the conversion # script changed. subprocess.check_call([os.path.join(SDK_ROOT, '..', 'gen_build_defs.py')]) 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. subprocess.check_call([os.path.join(SDK_ROOT, '..', 'gen_build_defs.py')]) DownloadSdkBootImages(sdk_hash) with open(hash_filename, 'w') as f: f.write(sdk_hash) UpdateTimestampsRecursive() return 0
def GetSdkHashList(): """Read filename entries from sdk-hash-files.list (one per line), substitute {platform} in each entry if present, and read from each filename.""" platform = GetHostOsFromPlatform() filenames = [ line.strip() for line in ReadFile('sdk-hash-files.list').replace( '{platform}', platform).splitlines() ] sdk_hashes = [ReadFile(filename).strip() for filename in filenames] return sdk_hashes
def GetSdkHashForPlatform(): filename = '{platform}.sdk.sha1'.format(platform = GetHostOsFromPlatform()) hash_file = os.path.join(os.path.dirname(__file__), filename) with open(hash_file, 'r') as f: sdk_hash = f.read().strip() if not sdk_hash: print >>sys.stderr, 'No SHA1 found in %s' % hash_file return 1 return sdk_hash
def main(): parser = argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action='store_true', help='Enable debug-level logging.') parser.add_argument( '--default-bucket', type=str, default='fuchsia', help='The Google Cloud Storage bucket in which the Fuchsia SDK is ' 'stored. Entry in sdk-bucket.txt will override this flag.') args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) # Quietly exit if there's no SDK support for this platform. try: GetHostOsFromPlatform() except: return 0 # Use the bucket in sdk-bucket.txt if an entry exists. # Otherwise use the default bucket. bucket = GetOverrideCloudStorageBucket() or args.default_bucket sdk_hash = GetSdkHash(bucket) if not sdk_hash: return 1 signature_filename = os.path.join(SDK_ROOT, SDK_SIGNATURE_FILE) current_signature = (open(signature_filename, 'r').read().strip() if os.path.exists(signature_filename) else '') if current_signature != sdk_hash: logging.info('Downloading GN SDK %s...' % sdk_hash) MakeCleanDirectory(SDK_ROOT) DownloadAndUnpackFromCloudStorage(GetSdkTarballPath(bucket, sdk_hash), SDK_ROOT) with open(signature_filename, 'w') as f: f.write(sdk_hash) UpdateTimestampsRecursive() return 0
def main(): parser = argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action='store_true', help='Enable debug-level logging.') args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) # Quietly exit if there's no SDK support for this platform. try: GetHostOsFromPlatform() except: return 0 bucket = GetCloudStorageBucket() sdk_hash = GetSdkHash(bucket) if not sdk_hash: return 1 signature_filename = os.path.join(SDK_ROOT, SDK_SIGNATURE_FILE) current_signature = (open(signature_filename, 'r').read().strip() if os.path.exists(signature_filename) else '') if current_signature != sdk_hash: logging.info('Downloading GN SDK %s...' % sdk_hash) MakeCleanDirectory(SDK_ROOT) DownloadAndUnpackFromCloudStorage(GetSdkTarballPath(bucket, sdk_hash), SDK_ROOT) with open(signature_filename, 'w') as f: f.write(sdk_hash) UpdateTimestampsRecursive() return 0
def main(): parser = argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action='store_true', help='Enable debug-level logging.') parser.add_argument( '--boot-images', type=str, nargs='?', help='List of boot images to download, represented as a comma separated ' 'list. Wildcards are allowed. ' 'If omitted, no boot images will be downloaded.') args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) # Quietly exit if there's no SDK support for this platform. try: GetHostOsFromPlatform() except: return 0 sdk_hash = GetSdkHashForPlatform() if not sdk_hash: return 1 signature_filename = os.path.join(SDK_ROOT, SDK_SIGNATURE_FILE) current_signature = (open(signature_filename, 'r').read().strip() if os.path.exists(signature_filename) else '') if current_signature != GetSdkSignature(sdk_hash, args.boot_images): logging.info('Downloading GN SDK %s...' % sdk_hash) if os.path.isdir(SDK_ROOT): shutil.rmtree(SDK_ROOT) EnsureDirExists(SDK_ROOT) DownloadAndUnpackFromCloudStorage( GetSdkTarballForPlatformAndHash(sdk_hash), SDK_ROOT) # Clean out the boot images directory. if (os.path.exists(IMAGES_ROOT)): shutil.rmtree(IMAGES_ROOT) 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(("command '%s' failed with status %d.%s"), " ".join(e.cmd), e.returncode, " Details: " + e.output if e.output else "") return 1 # 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) with open(signature_filename, 'w') as f: f.write(GetSdkSignature(sdk_hash, args.boot_images)) UpdateTimestampsRecursive() return 0
def GetBucketForPlatform(): return 'gs://fuchsia/sdk/core/{platform}-amd64/'.format( platform = GetHostOsFromPlatform())
def GetSdkTarballPath(bucket, sdk_hash): return SDK_TARBALL_PATH_TEMPLATE.format(bucket=bucket, sdk_hash=sdk_hash, platform=GetHostOsFromPlatform())
def GetSdkTarballForPlatformAndHash(sdk_hash): return SDK_TARBALL_PATH_TEMPLATE.format(sdk_hash=sdk_hash, platform=GetHostOsFromPlatform())
def main(): parser = argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action='store_true', help='Enable debug-level logging.') parser.add_argument( '--boot-images', type=str, required=True, help='List of boot images to download, represented as a comma separated ' 'list. Wildcards are allowed.') args = parser.parse_args() if not args.boot_images: raise Exception('--boot-images must be non-empty.') logging.basicConfig( level=logging.DEBUG if args.verbose else logging.WARNING) # Quietly exit if there's no SDK support for this platform. try: GetHostOsFromPlatform() 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. cmd = [os.path.join(SDK_ROOT, '..', 'gen_build_defs.py')] logging.debug("Running '%s'", " ".join(cmd)) subprocess.check_call(cmd) # Clean out the boot images directory. if (os.path.exists(IMAGES_ROOT)): shutil.rmtree(IMAGES_ROOT) os.mkdir(IMAGES_ROOT) try: DownloadSdkBootImages(sdk_hash, args.boot_images) except subprocess.CalledProcessError as e: logging.error(("command '%s' failed with status %d.%s"), " ".join(e.cmd), e.returncode, " Details: " + e.output if e.output else "") return 1 with open(hash_filename, 'w') as f: f.write(sdk_hash) UpdateTimestampsRecursive() return 0
def main(): parser = argparse.ArgumentParser() parser.add_argument('--verbose', '-v', action='store_true', help='Enable debug-level logging.') parser.add_argument( '--boot-images', type=str, required=True, help='List of boot images to download, represented as a comma separated ' 'list. Wildcards are allowed. ') parser.add_argument( '--default-bucket', type=str, default='fuchsia', help='The Google Cloud Storage bucket in which the Fuchsia images are ' 'stored. Entry in sdk-bucket.txt will override this flag.') parser.add_argument( '--image-root-dir', default=IMAGES_ROOT, help='Specify the root directory of the downloaded images. Optional') args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) # If no boot images need to be downloaded, exit. if not args.boot_images: return 0 # Check whether there's SDK support for this platform. GetHostOsFromPlatform() # Use the bucket in sdk-bucket.txt if an entry exists. # Otherwise use the default bucket. bucket = GetOverrideCloudStorageBucket() or args.default_bucket sdk_hash = GetSdkHash(bucket) if not sdk_hash: return 1 signature_filename = os.path.join(args.image_root_dir, SDK_SIGNATURE_FILE) current_signature = (open(signature_filename, 'r').read().strip() if os.path.exists(signature_filename) else '') new_signature = GetNewSignature(sdk_hash, args.boot_images) if current_signature != new_signature: logging.info('Downloading Fuchsia images %s...' % sdk_hash) MakeCleanDirectory(args.image_root_dir) try: DownloadSdkBootImages(bucket, sdk_hash, args.boot_images, args.image_root_dir) with open(signature_filename, 'w') as f: f.write(new_signature) except subprocess.CalledProcessError as e: logging.error(("command '%s' failed with status %d.%s"), " ".join(e.cmd), e.returncode, " Details: " + e.output if e.output else "") return 0
def GetSdkTarballForPlatformAndHash(sdk_hash): return 'gs://fuchsia/development/{sdk_hash}/sdk/{platform}-amd64/gn.tar.gz'.format( sdk_hash=sdk_hash, platform=GetHostOsFromPlatform())
def main(): parser = argparse.ArgumentParser() parser.add_argument("--verbose", "-v", action="store_true", help="Enable debug-level logging.") args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.verbose else logging.WARNING) # Quietly exit if there's no SDK support for this platform. try: GetHostOsFromPlatform() 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: # Used to download boot images if "gclient runhooks" is called on a # output directory which had previously built Fuchsia on the same SDK # hash, but did not use separate boot images. if not os.path.exists(IMAGES_ROOT): DownloadSdkBootImages(sdk_hash) # 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. cmd = [os.path.join(SDK_ROOT, '..', 'gen_build_defs.py')] logging.debug("Running '%s'", " ".join(cmd)) subprocess.check_call(cmd) try: DownloadSdkBootImages(sdk_hash) except subprocess.CalledProcessError as e: logging.error(( "command '%s' failed with status %d.%s"), " ".join(e.cmd), e.returncode, " Details: " + e.output if e.output else "") return 1 with open(hash_filename, 'w') as f: f.write(sdk_hash) UpdateTimestampsRecursive() return 0
def GetSdkHashForPlatform(): filename = '{platform}.sdk.sha1'.format(platform=GetHostOsFromPlatform()) return os.path.join(os.path.dirname(__file__), filename)