def UpdateSdk(args): ''' Uses Maven to download the latest Google Play Services SDK. Its installation path is //third_party/android_tools/sdk/extras/google/m2repository. ''' # This should function should not run on bots and could fail for many user # and setup related reasons. Also, exceptions here are not caught, so we # disable breakpad to avoid spamming the logs. breakpad.IS_ENABLED = False config = utils.ConfigParser(args.config) target_repo = os.path.join(args.sdk_root, EXTRAS_GOOGLE_M2REPOSITORY) # Remove the old SDK. # TODO(https://crbug.com/778650) not everything should be deleted. shutil.rmtree(target_repo, ignore_errors=True) downloader = maven_downloader.MavenDownloader() artifact_list = [ 'com.google.android.gms:{}:{}:aar'.format(client, config.version_number) for client in config.clients ] downloader.Install(target_repo, artifact_list) return 0
def Upload(args): ''' Uploads the library from the local Google Play services SDK to a Google Cloud storage bucket. The version of the library and the list of clients to be uploaded will be taken from the configuration file. (see --config parameter) By default, a local commit will be made at the end of the operation. ''' # This should function should not run on bots and could fail for many user # and setup related reasons. Also, exceptions here are not caught, so we # disable breakpad to avoid spamming the logs. breakpad.IS_ENABLED = False config = utils.ConfigParser(args.config) paths = PlayServicesPaths(args.sdk_root, config.version_number, config.clients) logging.debug('-- Loaded paths --\n%s\n------------------', paths) if not args.skip_git and utils.IsRepoDirty(host_paths.DIR_SOURCE_ROOT): logging.error( 'The repo is dirty. Please commit or stash your changes.') return -1 tmp_root = tempfile.mkdtemp() try: new_lib_zip = os.path.join(tmp_root, ZIP_FILE_NAME) new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) _ZipLibrary(new_lib_zip, paths.client_paths, paths.package) _ExtractLicenseFile(new_license, paths.source_prop) bucket_path = _VerifyBucketPathFormat(args.bucket, config.version_number, args.dry_run) files_to_upload = [new_lib_zip, new_license] logging.debug('Uploading %s to %s', files_to_upload, bucket_path) _UploadToBucket(bucket_path, files_to_upload, args.dry_run) new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, ZIP_FILE_NAME + '.sha1') new_license_sha1 = os.path.join(SHA1_DIRECTORY, LICENSE_FILE_NAME + '.sha1') shutil.copy(new_lib_zip + '.sha1', new_lib_zip_sha1) shutil.copy(new_license + '.sha1', new_license_sha1) finally: shutil.rmtree(tmp_root) if not args.skip_git: commit_message = ('Update the Google Play services dependency to %s\n' '\n') % config.version_number utils.MakeLocalCommit( host_paths.DIR_SOURCE_ROOT, [new_lib_zip_sha1, new_license_sha1, config.path], commit_message) return 0
def ProcessGooglePlayServices(repo, out_dir, config_path): config = utils.ConfigParser(config_path) tmp_root = tempfile.mkdtemp() try: tmp_paths = _SetupTempDir(tmp_root) _ImportFromExtractedRepo(config, tmp_paths, repo) _ProcessResources(config, tmp_paths, repo) _CopyToOutput(tmp_paths, out_dir) _UpdateVersionInConfig(config, tmp_paths) finally: shutil.rmtree(tmp_root) return 0
def ProcessGooglePlayServices(repo, out_dir, config_path, is_extracted_repo): config = utils.ConfigParser(config_path) tmp_root = tempfile.mkdtemp() try: tmp_paths = _SetupTempDir(tmp_root) if is_extracted_repo: _ImportFromExtractedRepo(config, tmp_paths, repo) else: _ImportFromAars(config, tmp_paths, repo) _GenerateCombinedJar(tmp_paths) _ProcessResources(config, tmp_paths) _BuildOutput(config, tmp_paths, out_dir) finally: shutil.rmtree(tmp_root) return 0
def Upload(args): ''' Uploads the library from the local Google Play services SDK to a Google Cloud storage bucket. The version of the library and the list of clients to be uploaded will be taken from the configuration file. (see --config parameter) By default, a local commit will be made at the end of the operation. ''' # This should function should not run on bots and could fail for many user # and setup related reasons. Also, exceptions here are not caught, so we # disable breakpad to avoid spamming the logs. breakpad.IS_ENABLED = False config = utils.ConfigParser(args.config) paths = PlayServicesPaths(args.sdk_root, config.version_number, config.clients) logging.debug('-- Loaded paths --\n%s\n------------------', paths) with tempfile_ext.NamedTemporaryDirectory() as tmp_root: new_lib_zip = os.path.join(tmp_root, ZIP_FILE_NAME) new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) _ZipLibrary(new_lib_zip, paths.client_paths, paths.package) _ExtractLicenseFile(new_license, paths.source_prop) bucket_path = _VerifyBucketPathFormat(args.bucket, config.version_number, args.dry_run) files_to_upload = [new_lib_zip, new_license] logging.debug('Uploading %s to %s', files_to_upload, bucket_path) _UploadToBucket(bucket_path, files_to_upload, args.dry_run) new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, ZIP_FILE_NAME + '.sha1') new_license_sha1 = os.path.join(SHA1_DIRECTORY, LICENSE_FILE_NAME + '.sha1') shutil.copy(new_lib_zip + '.sha1', new_lib_zip_sha1) shutil.copy(new_license + '.sha1', new_license_sha1) logging.info('Update to version %s complete', config.version_number) return 0
def Download(args): ''' Downloads the Google Play services library from a Google Cloud Storage bucket and installs it to //third_party/android_tools/sdk/extras/google/m2repository. A license check will be made, and the user might have to accept the license if that has not been done before. ''' if not os.path.isdir(args.sdk_root): logging.debug('Did not find the Android SDK root directory at "%s".', args.sdk_root) if not args.force: logging.info('Skipping, not on an android checkout.') return 0 config = utils.ConfigParser(args.config) paths = PlayServicesPaths(args.sdk_root, config.version_number, config.clients) if os.path.isdir(paths.package) and not os.access(paths.package, os.W_OK): logging.error('Failed updating the Google Play Services library. ' 'The location is not writable. Please remove the ' 'directory (%s) and try again.', paths.package) return -2 new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, ZIP_FILE_NAME + '.sha1') logging.debug('Comparing zip hashes: %s and %s', new_lib_zip_sha1, paths.lib_zip_sha1) if utils.FileEquals(new_lib_zip_sha1, paths.lib_zip_sha1) and not args.force: logging.info('Skipping, the Google Play services library is up to date.') return 0 bucket_path = _VerifyBucketPathFormat(args.bucket, config.version_number, args.dry_run) tmp_root = tempfile.mkdtemp() try: # setup the destination directory if not os.path.isdir(paths.package): os.makedirs(paths.package) # download license file from bucket/{version_number}/license.sha1 new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) license_sha1 = os.path.join(SHA1_DIRECTORY, LICENSE_FILE_NAME + '.sha1') _DownloadFromBucket(bucket_path, license_sha1, new_license, args.verbose, args.dry_run) if (not _IsBotEnvironment() and not _CheckLicenseAgreement(new_license, paths.license, config.version_number)): logging.warning('Your version of the Google Play services library is ' 'not up to date. You might run into issues building ' 'or running the app. Please run `%s download` to ' 'retry downloading it.', __file__) return 0 new_lib_zip = os.path.join(tmp_root, ZIP_FILE_NAME) _DownloadFromBucket(bucket_path, new_lib_zip_sha1, new_lib_zip, args.verbose, args.dry_run) try: # Remove the deprecated sdk directory. deprecated_package_path = os.path.join(args.sdk_root, 'extras', 'google', 'google_play_services') if os.path.exists(deprecated_package_path): shutil.rmtree(deprecated_package_path) # We remove the current version of the Google Play services SDK. if os.path.exists(paths.package): shutil.rmtree(paths.package) os.makedirs(paths.package) logging.debug('Extracting the library to %s', paths.package) with zipfile.ZipFile(new_lib_zip, "r") as new_lib_zip_file: new_lib_zip_file.extractall(paths.package) logging.debug('Copying %s to %s', new_license, paths.license) shutil.copy(new_license, paths.license) logging.debug('Copying %s to %s', new_lib_zip_sha1, paths.lib_zip_sha1) shutil.copy(new_lib_zip_sha1, paths.lib_zip_sha1) logging.info('Update complete.') except Exception as e: # pylint: disable=broad-except logging.error('Failed updating the Google Play Services library. ' 'An error occurred while installing the new version in ' 'the SDK directory: %s ', e) return -3 finally: shutil.rmtree(tmp_root) return 0
def Upload(args): ''' Uploads the library from the local Google Play services SDK to a Google Cloud storage bucket. By default, a local commit will be made at the end of the operation. ''' # This should function should not run on bots and could fail for many user # and setup related reasons. Also, exceptions here are not caught, so we # disable breakpad to avoid spamming the logs. breakpad.IS_ENABLED = False config = utils.ConfigParser(args.config) paths = PlayServicesPaths(args.sdk_root, config.version_xml_path) if not args.skip_git and utils.IsRepoDirty(host_paths.DIR_SOURCE_ROOT): logging.error( 'The repo is dirty. Please commit or stash your changes.') return -1 new_version_number = utils.GetVersionNumberFromLibraryResources( paths.version_xml) logging.debug('comparing versions: new=%d, old=%s', new_version_number, config.version_number) if new_version_number <= config.version_number and not args.force: logging.info( 'The checked in version of the library is already the latest ' 'one. No update is needed. Please rerun with --force to skip ' 'this check.') return 0 tmp_root = tempfile.mkdtemp() try: new_lib_zip = os.path.join(tmp_root, ZIP_FILE_NAME) new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) # need to strip '.zip' from the file name here shutil.make_archive(new_lib_zip[:-4], 'zip', paths.lib) _ExtractLicenseFile(new_license, paths.source_prop) bucket_path = _VerifyBucketPathFormat(args.bucket, new_version_number, args.dry_run) files_to_upload = [new_lib_zip, new_license] logging.debug('Uploading %s to %s', files_to_upload, bucket_path) _UploadToBucket(bucket_path, files_to_upload, args.dry_run) new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, ZIP_FILE_NAME + '.sha1') new_license_sha1 = os.path.join(SHA1_DIRECTORY, LICENSE_FILE_NAME + '.sha1') shutil.copy(new_lib_zip + '.sha1', new_lib_zip_sha1) shutil.copy(new_license + '.sha1', new_license_sha1) finally: shutil.rmtree(tmp_root) config.UpdateVersionNumber(new_version_number) if not args.skip_git: commit_message = ('Update the Google Play services dependency to %s\n' '\n') % new_version_number utils.MakeLocalCommit( host_paths.DIR_SOURCE_ROOT, [new_lib_zip_sha1, new_license_sha1, config.path], commit_message) return 0
def Download(args): ''' Downloads the Google Play services client library from a Google Cloud Storage bucket and installs it to //third_party/android_tools/sdk/extras/google/google_play_services. A license check will be made, and the user might have to accept the license if that has not been done before. ''' paths = _InitPaths(constants.ANDROID_SDK_ROOT) new_lib_zip_sha1 = os.path.join(SHA1_DIRECTORY, LIBRARY_FILE_NAME + '.sha1') old_lib_zip_sha1 = os.path.join(paths.package, LIBRARY_FILE_NAME + '.sha1') logging.debug('Comparing library hashes: %s and %s', new_lib_zip_sha1, old_lib_zip_sha1) if utils.FileEquals(new_lib_zip_sha1, old_lib_zip_sha1) and not args.force: logging.debug('The Google Play services library is up to date.') return 0 config = utils.ConfigParser(args.config) bucket_path = _VerifyBucketPathFormat(args.bucket, config.version_number, args.dry_run) tmp_root = tempfile.mkdtemp() try: if not os.environ.get('CHROME_HEADLESS'): if not os.path.isdir(paths.package): os.makedirs(paths.package) # download license file from bucket/{version_number}/license.sha1 new_license = os.path.join(tmp_root, LICENSE_FILE_NAME) old_license = os.path.join(paths.package, LICENSE_FILE_NAME) license_sha1 = os.path.join(SHA1_DIRECTORY, LICENSE_FILE_NAME + '.sha1') _DownloadFromBucket(bucket_path, license_sha1, new_license, args.verbose, args.dry_run) if not _CheckLicenseAgreement(new_license, old_license): logging.warning( 'Your version of the Google Play services library is ' 'not up to date. You might run into issues building ' 'or running the app. Please run `%s download` to ' 'retry downloading it.', __file__) return 0 new_lib_zip = os.path.join(tmp_root, LIBRARY_FILE_NAME) _DownloadFromBucket(bucket_path, new_lib_zip_sha1, new_lib_zip, args.verbose, args.dry_run) # We remove only the library itself. Users having a SDK manager installed # library before will keep the documentation and samples from it. shutil.rmtree(paths.lib, ignore_errors=True) os.makedirs(paths.lib) logging.debug('Extracting the library to %s', paths.lib) with zipfile.ZipFile(new_lib_zip, "r") as new_lib_zip_file: new_lib_zip_file.extractall(paths.lib) logging.debug('Copying %s to %s', new_license, old_license) shutil.copy(new_license, old_license) logging.debug('Copying %s to %s', new_lib_zip_sha1, old_lib_zip_sha1) shutil.copy(new_lib_zip_sha1, old_lib_zip_sha1) finally: shutil.rmtree(tmp_root) return 0