68 upload_to_partner_bucket, dm_path):
69 """Create the SKP asset.
70
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
75 them (see below).
76
77 The script runs the following cmd on the non-generated SKPs stored in
78 $PRIVATE_SKPS_GS -
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.
82 """
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)
87
88 if not os.path.exists(target_dir):
89 os.makedirs(target_dir)
90
91
93
94
96 if os.environ.get('CHROME_HEADLESS'):
97 print(
'Starting xvfb')
98
99 try:
100 xvfb_proc = subprocess.Popen([
101 'sudo', 'Xvfb', ':0', '-screen', '0', '1280x1024x24'])
102 except Exception:
103
104
105 xvfb_proc = None
106
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,
112 '--non-interactive',
113 '--output_dir', os.getcwd(),
114 '--chrome_src_path', chrome_src_path,
115 ]
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))
120 try:
121 subprocess.check_call(webpages_playback_cmd)
122 finally:
123 if xvfb_proc:
124 try:
125 xvfb_proc.kill()
126 except OSError as e:
127 print(
'Failed to kill xvfb process via Popen.kill();'
128 ' attempting `sudo kill`...')
129 try:
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.')
134
135
136
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))
144 try:
145 subprocess.check_call(['kill', '-9', str(pid)])
146 except subprocess.CalledProcessError as e:
148 else:
149 pass
150 if 'Xvfb' in line:
152 pid = line.strip().split(' ')[0]
153 print(
'Kill Xvfb process %s' % str(pid))
154 try:
155 subprocess.check_call(['sudo', 'kill', '-9', str(pid)])
156 except subprocess.CalledProcessError as e:
158
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.')
164
165
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([
173 dm_path,
174 '--config', 'skp',
175 '-w', new_skps_dir,
176 '--skps', old_skps_dir,
177 '--src', 'skp'])
178
179
180
181 for f in os.listdir(os.path.join(new_skps_dir, 'skp', 'skp')):
182 if f.endswith('.skp'):
183
184
185
186 shutil.copyfile(
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)
191
192
def print(*args, **kwargs)
def get_flutter_skps(target_dir)
static DecodeResult decode(std::string path)
static SkString join(const CommandLineFlags::StringArray &)