1#!/usr/bin/env python 2# 3# Copyright 2016 Google Inc. 4# 5# Use of this source code is governed by a BSD-style license that can be 6# found in the LICENSE file. 7 8 9"""Create the asset and upload it.""" 10 11 12import argparse 13import os 14import subprocess 15import sys 16import tempfile 17import create 18 19 20FILE_DIR = os.path.dirname(os.path.abspath(__file__)) 21ASSET = os.path.basename(FILE_DIR) 22 23 24def main(): 25 parser = argparse.ArgumentParser() 26 parser.add_argument('--chrome_src_path', '-c', required=True) 27 parser.add_argument('--browser_executable', '-e', required=True) 28 parser.add_argument('--dm_path', '-d', required=True) 29 parser.add_argument('--upload_to_partner_bucket', action='store_true') 30 parser.add_argument('--dry_run', action='store_true') 31 parser.add_argument('--local', action='store_true') 32 args = parser.parse_args() 33 # Pass the flags to the creation script via environment variables, since 34 # we're calling the script via `sk` and not directly. 35 os.environ[create.BROWSER_EXECUTABLE_ENV_VAR] = args.browser_executable 36 os.environ[create.CHROME_SRC_PATH_ENV_VAR] = args.chrome_src_path 37 os.environ[create.UPLOAD_TO_PARTNER_BUCKET_ENV_VAR] = ( 38 '1' if args.upload_to_partner_bucket else '0') 39 os.environ[create.DM_PATH_ENV_VAR] = args.dm_path 40 41 sk = os.path.realpath(os.path.join( 42 FILE_DIR, os.pardir, os.pardir, os.pardir, os.pardir, 'bin', 'sk')) 43 if os.name == 'nt': 44 sk += '.exe' 45 if not os.path.isfile(sk): 46 raise Exception('`sk` not found at %s; maybe you need to run bin/fetch-sk?') 47 48 # Find the Chromium revision and supply it as a tag. 49 chromium_revision = subprocess.check_output( 50 ['git', 'rev-parse', 'HEAD'], cwd=args.chrome_src_path).decode().rstrip() 51 52 # Upload the asset. 53 cmd = [ 54 sk, 'asset', 'upload', 55 '--tags', 'chromium_revision:%s' % chromium_revision, 56 ] 57 if args.dry_run: 58 cmd.append('--dry-run') 59 if not args.local: 60 cmd.append('--ci') 61 cmd.append('skp') 62 subprocess.check_call(cmd, cwd=FILE_DIR) 63 64 65if __name__ == '__main__': 66 main() 67