9"""Create the SKP asset."""
12from __future__
import print_function
14from distutils.dir_util
import copy_tree
21FILE_DIR = os.path.dirname(os.path.abspath(__file__))
22INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
23sys.path.insert(0, INFRA_BOTS_DIR)
27BROWSER_EXECUTABLE_ENV_VAR =
'SKP_BROWSER_EXECUTABLE'
28CHROME_SRC_PATH_ENV_VAR =
'SKP_CHROME_SRC_PATH'
29UPLOAD_TO_PARTNER_BUCKET_ENV_VAR =
'SKP_UPLOAD_TO_PARTNER_BUCKET'
30DM_PATH_ENV_VAR =
'DM_PATH'
32SKIA_TOOLS = os.path.join(INFRA_BOTS_DIR, os.pardir, os.pardir,
'tools')
33PRIVATE_SKPS_GS =
'gs://skia-skps/private/skps'
37 val = os.environ.get(key)
39 print((
'Environment variable %s not set; you should run this via '
40 'create_and_upload.py.' % key), file=sys.stderr)
46 """Creates SKPs using Flutter's skp_generator tool.
48 Documentation is at https://github.com/flutter/tests/tree/master/skp_generator
51 print(
'Retrieving Flutter SKPs...')
53 os.chdir(
'skp_generator')
54 subprocess.check_call([
'bash',
'build.sh'])
56 for f
in os.listdir(
'skps'):
57 original_file_name = os.path.splitext(f)[0]
58 new_file_name =
''.
join([x
if x.isalnum()
else "_"
59 for x
in original_file_name])
60 if new_file_name != original_file_name:
61 os.rename(os.path.join(
'skps', f),
62 os.path.join(
'skps', new_file_name +
'.skp'))
64 print(
'Done retrieving Flutter SKPs.')
68 upload_to_partner_bucket, dm_path):
69 """Create the SKP asset.
71 Creates the asset from 3 sources:
72 1. From Flutter
's skp_generator tool.
73 2. The web pages defined in the tools/skp/page_sets/ directory.
74 3. Any private SKPs stored
in $PRIVATE_SKPS_GS after running dm on
77 The script runs the following cmd on the non-generated SKPs stored
in
79 `dm --config skp -w newskps/ --skps oldskps/ --src skp`
80 The cmd updates the version stored
in the SKPs so that the versions
in
81 them do
not eventually become unsupported.
83 browser_executable = os.path.realpath(browser_executable)
84 chrome_src_path = os.path.realpath(chrome_src_path)
85 dm_path = os.path.realpath(dm_path)
86 target_dir = os.path.realpath(target_dir)
88 if not os.path.exists(target_dir):
89 os.makedirs(target_dir)
96 if os.environ.get(
'CHROME_HEADLESS'):
97 print(
'Starting xvfb')
100 xvfb_proc = subprocess.Popen([
101 'sudo',
'Xvfb',
':0',
'-screen',
'0',
'1280x1024x24'])
107 print(
'Running webpages_playback to generate SKPs...')
108 webpages_playback_cmd = [
109 'python',
'-u', os.path.join(SKIA_TOOLS,
'skp',
'webpages_playback.py'),
110 '--page_sets',
'all',
111 '--browser_executable', browser_executable,
113 '--output_dir', os.getcwd(),
114 '--chrome_src_path', chrome_src_path,
116 if upload_to_partner_bucket:
117 webpages_playback_cmd.append(
'--upload_to_partner_bucket')
118 print(
'Running webpages_playback command:\n$ %s' %
119 ' '.
join(webpages_playback_cmd))
121 subprocess.check_call(webpages_playback_cmd)
127 print(
'Failed to kill xvfb process via Popen.kill();'
128 ' attempting `sudo kill`...')
130 subprocess.check_call([
'sudo',
'kill',
'-9', str(xvfb_proc.pid)])
131 except subprocess.CalledProcessError
as e:
132 print(
'Failed to kill xvfb process via `sudo kill`;'
133 'this may cause a hang.')
137 procs = subprocess.check_output([
'ps',
'ax']).
decode()
138 for line
in procs.splitlines():
139 if browser_executable
in line:
141 pid = line.strip().split(
' ')[0]
142 if pid != str(os.getpid())
and not 'python' in line:
143 print(
'Kill browser process %s' % str(pid))
145 subprocess.check_call([
'kill',
'-9', str(pid)])
146 except subprocess.CalledProcessError
as e:
152 pid = line.strip().split(
' ')[0]
153 print(
'Kill Xvfb process %s' % str(pid))
155 subprocess.check_call([
'sudo',
'kill',
'-9', str(pid)])
156 except subprocess.CalledProcessError
as e:
159 src = os.path.join(os.getcwd(),
'playback',
'skps')
160 for f
in os.listdir(src):
161 if f.endswith(
'.skp'):
162 shutil.copyfile(os.path.join(src, f), os.path.join(target_dir, f))
163 print(
'Done running webpages_playback.')
166 old_skps_dir = tempfile.mkdtemp()
167 new_skps_dir = tempfile.mkdtemp()
168 print(
'Copying non-generated SKPs from private GCS bucket...')
169 subprocess.check_call([
170 'gsutil',
'cp', os.path.join(PRIVATE_SKPS_GS,
'*'), old_skps_dir])
171 print(
'Updating non-generated SKP versions')
172 subprocess.check_call([
176 '--skps', old_skps_dir,
181 for f
in os.listdir(os.path.join(new_skps_dir,
'skp',
'skp')):
182 if f.endswith(
'.skp'):
187 os.path.join(new_skps_dir,
'skp',
'skp', f),
188 os.path.join(target_dir, f.replace(
'.skp.skp',
'.skp')))
189 shutil.rmtree(old_skps_dir)
190 shutil.rmtree(new_skps_dir)
194 parser = argparse.ArgumentParser()
195 parser.add_argument(
'--target_dir',
'-t', required=
True)
196 args = parser.parse_args()
200 chrome_src_path =
getenv(CHROME_SRC_PATH_ENV_VAR)
201 browser_executable =
getenv(BROWSER_EXECUTABLE_ENV_VAR)
202 upload_to_partner_bucket =
getenv(UPLOAD_TO_PARTNER_BUCKET_ENV_VAR) ==
'1'
203 dm_path =
getenv(DM_PATH_ENV_VAR)
205 create_asset(chrome_src_path, browser_executable, args.target_dir,
206 upload_to_partner_bucket, dm_path)
209if __name__ ==
'__main__':
def print(*args, **kwargs)
def create_asset(chrome_src_path, browser_executable, target_dir, upload_to_partner_bucket, dm_path)
def get_flutter_skps(target_dir)
def git_clone(repo_url, dest_dir)
static DecodeResult decode(std::string path)
static SkString join(const CommandLineFlags::StringArray &)