blob: fff6331598a92adb3aa49fe88a9f2f57b150cc97 [file] [log] [blame]
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08001# -*- coding: utf-8 -*-
Kuang-che Wu2ea804f2017-11-28 17:11:41 +08002# Copyright 2017 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""ChromeOS utility.
6
7Terminology used in this module.
8 short_version: ChromeOS version number without milestone, like "9876.0.0".
9 full_version: ChromeOS version number with milestone, like "R62-9876.0.0".
Zheng-Jie Chang127c3302019-09-10 17:17:04 +080010 snapshot_version: ChromeOS version number with milestone and snapshot id,
11 like "R62-9876.0.0-12345".
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080012 version: if not specified, it could be in short or full format.
13"""
14
15from __future__ import print_function
Kuang-che Wub9705bd2018-06-28 17:59:18 +080016import ast
Zheng-Jie Chang127c3302019-09-10 17:17:04 +080017import datetime
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080018import errno
19import json
20import logging
21import os
22import re
23import subprocess
24import time
25
26from bisect_kit import cli
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080027from bisect_kit import codechange
Kuang-che Wu3eb6b502018-06-06 16:15:18 +080028from bisect_kit import cr_util
Kuang-che Wue121fae2018-11-09 16:18:39 +080029from bisect_kit import errors
Kuang-che Wubfc4a642018-04-19 11:54:08 +080030from bisect_kit import git_util
Kuang-che Wufb553102018-10-02 18:14:29 +080031from bisect_kit import locking
Kuang-che Wubfc4a642018-04-19 11:54:08 +080032from bisect_kit import repo_util
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080033from bisect_kit import util
34
35logger = logging.getLogger(__name__)
36
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080037re_chromeos_full_version = r'^R\d+-\d+\.\d+\.\d+$'
Kuang-che Wuacb6efd2018-04-25 18:52:58 +080038re_chromeos_localbuild_version = r'^\d+\.\d+\.\d{4}_\d\d_\d\d_\d{4}$'
39re_chromeos_short_version = r'^\d+\.\d+\.\d+$'
Zheng-Jie Chang127c3302019-09-10 17:17:04 +080040re_chromeos_snapshot_version = r'^R\d+-\d+\.\d+\.\d+-\d+$'
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080041
42gs_archive_path = 'gs://chromeos-image-archive/{board}-release'
43gs_release_path = (
Kuang-che Wu80bf6a52019-05-31 12:48:06 +080044 'gs://chromeos-releases/{channel}-channel/{boardpath}/{short_version}')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080045
46# Assume gsutil is in PATH.
47gsutil_bin = 'gsutil'
48
Kuang-che Wub9705bd2018-06-28 17:59:18 +080049chromeos_root_inside_chroot = '/mnt/host/source'
50# relative to chromeos_root
Kuang-che Wu7f82c6f2019-08-12 14:29:28 +080051prebuilt_autotest_dir = 'tmp/autotest-prebuilt'
Kuang-che Wu28980b22019-07-31 19:51:45 +080052# Relative to chromeos root. Images are cached_images_dir/$board/$image_name.
53cached_images_dir = 'src/build/images'
54test_image_filename = 'chromiumos_test_image.bin'
Kuang-che Wub9705bd2018-06-28 17:59:18 +080055
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080056VERSION_KEY_CROS_SHORT_VERSION = 'cros_short_version'
57VERSION_KEY_CROS_FULL_VERSION = 'cros_full_version'
58VERSION_KEY_MILESTONE = 'milestone'
59VERSION_KEY_CR_VERSION = 'cr_version'
Kuang-che Wu708310b2018-03-28 17:24:34 +080060VERSION_KEY_ANDROID_BUILD_ID = 'android_build_id'
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080061VERSION_KEY_ANDROID_BRANCH = 'android_branch'
62
63
Kuang-che Wu9890ce82018-07-07 15:14:10 +080064class NeedRecreateChrootException(Exception):
65 """Failed to build ChromeOS because of chroot mismatch or corruption"""
66
67
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080068def is_cros_short_version(s):
Kuang-che Wuacb6efd2018-04-25 18:52:58 +080069 """Determines if `s` is chromeos short version.
70
71 This function doesn't accept version number of local build.
72 """
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080073 return bool(re.match(re_chromeos_short_version, s))
74
75
Kuang-che Wuacb6efd2018-04-25 18:52:58 +080076def is_cros_localbuild_version(s):
77 """Determines if `s` is chromeos local build version."""
78 return bool(re.match(re_chromeos_localbuild_version, s))
79
80
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080081def is_cros_full_version(s):
Kuang-che Wuacb6efd2018-04-25 18:52:58 +080082 """Determines if `s` is chromeos full version.
83
84 This function doesn't accept version number of local build.
85 """
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080086 return bool(re.match(re_chromeos_full_version, s))
87
88
89def is_cros_version(s):
90 """Determines if `s` is chromeos version (either short or full)"""
91 return is_cros_short_version(s) or is_cros_full_version(s)
92
93
Zheng-Jie Chang127c3302019-09-10 17:17:04 +080094def is_cros_snapshot_version(s):
95 """Determines if `s` is chromeos snapshot version"""
96 return bool(re.match(re_chromeos_snapshot_version, s))
97
98
Kuang-che Wu2ea804f2017-11-28 17:11:41 +080099def make_cros_full_version(milestone, short_version):
100 """Makes full_version from milestone and short_version"""
Kuang-che Wuacb6efd2018-04-25 18:52:58 +0800101 assert milestone
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800102 return 'R%s-%s' % (milestone, short_version)
103
104
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800105def make_cros_snapshot_version(milestone, short_version, snapshot_id):
106 """Makes snapshot version from milestone, short_version and snapshot id"""
107 return 'R%s-%s-%s' % (milestone, short_version, snapshot_id)
108
109
110def version_split(version):
111 """Splits full_version or snapshot_version into milestone and short_version"""
112 assert is_cros_full_version(version) or is_cros_snapshot_version(version)
113 if is_cros_snapshot_version(version):
114 return snapshot_version_split(version)[0:2]
115 milestone, short_version = version.split('-')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800116 return milestone[1:], short_version
117
118
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800119def snapshot_version_split(snapshot_version):
120 """Splits snapshot_version into milestone, short_version and snapshot_id"""
121 assert is_cros_snapshot_version(snapshot_version)
122 milestone, shot_version, snapshot_id = snapshot_version.split('-')
123 return milestone[1:], shot_version, snapshot_id
124
125
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800126def argtype_cros_version(s):
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800127 if (not is_cros_version(s)) and (not is_cros_snapshot_version(s)):
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800128 msg = 'invalid cros version'
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800129 raise cli.ArgTypeError(msg,
130 '9876.0.0, R62-9876.0.0 or R77-12369.0.0-11681')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800131 return s
132
133
134def query_dut_lsb_release(host):
135 """Query /etc/lsb-release of given DUT
136
137 Args:
138 host: the DUT address
139
140 Returns:
Kuang-che Wu3eb6b502018-06-06 16:15:18 +0800141 dict for keys and values of /etc/lsb-release.
142
143 Raises:
Kuang-che Wu44278142019-03-04 11:33:57 +0800144 errors.SshConnectionError: cannot connect to host
145 errors.ExternalError: lsb-release file doesn't exist
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800146 """
147 try:
Kuang-che Wu44278142019-03-04 11:33:57 +0800148 output = util.ssh_cmd(host, 'cat', '/etc/lsb-release')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800149 except subprocess.CalledProcessError:
Kuang-che Wu44278142019-03-04 11:33:57 +0800150 raise errors.ExternalError('unable to read /etc/lsb-release; not a DUT')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800151 return dict(re.findall(r'^(\w+)=(.*)$', output, re.M))
152
153
154def is_dut(host):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800155 """Determines whether a host is a chromeos device.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800156
157 Args:
158 host: the DUT address
159
160 Returns:
161 True if the host is a chromeos device.
162 """
Kuang-che Wu44278142019-03-04 11:33:57 +0800163 try:
164 return query_dut_lsb_release(host).get('DEVICETYPE') in [
165 'CHROMEBASE',
166 'CHROMEBIT',
167 'CHROMEBOOK',
168 'CHROMEBOX',
169 'REFERENCE',
170 ]
171 except (errors.ExternalError, errors.SshConnectionError):
172 return False
173
174
175def is_good_dut(host):
176 if not is_dut(host):
177 return False
178
179 # Sometimes python is broken after 'cros flash'.
180 try:
181 util.ssh_cmd(host, 'python', '-c', '1')
182 return True
183 except (subprocess.CalledProcessError, errors.SshConnectionError):
184 return False
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800185
186
187def query_dut_board(host):
188 """Query board name of a given DUT"""
189 return query_dut_lsb_release(host).get('CHROMEOS_RELEASE_BOARD')
190
191
192def query_dut_short_version(host):
Kuang-che Wuacb6efd2018-04-25 18:52:58 +0800193 """Query short version of a given DUT.
194
195 This function may return version of local build, which
196 is_cros_short_version() is false.
197 """
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800198 return query_dut_lsb_release(host).get('CHROMEOS_RELEASE_VERSION')
199
200
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800201def query_dut_is_snapshot(host):
202 """Query if given DUT is a snapshot version."""
203 path = query_dut_lsb_release(host).get('CHROMEOS_RELEASE_BUILDER_PATH', '')
204 return '-postsubmit' in path
205
206
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800207def query_dut_boot_id(host, connect_timeout=None):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800208 """Query boot id.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800209
210 Args:
211 host: DUT address
212 connect_timeout: connection timeout
213
214 Returns:
215 boot uuid
216 """
Kuang-che Wu44278142019-03-04 11:33:57 +0800217 return util.ssh_cmd(
218 host,
219 'cat',
220 '/proc/sys/kernel/random/boot_id',
221 connect_timeout=connect_timeout).strip()
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800222
223
224def reboot(host):
225 """Reboot a DUT and verify"""
226 logger.debug('reboot %s', host)
227 boot_id = query_dut_boot_id(host)
228
Kuang-che Wu44278142019-03-04 11:33:57 +0800229 try:
230 util.ssh_cmd(host, 'reboot')
Kuang-che Wu5f662e82019-03-05 11:49:56 +0800231 except errors.SshConnectionError:
232 # Depends on timing, ssh may return failure due to broken pipe, which is
233 # working as intended. Ignore such kind of errors.
Kuang-che Wu44278142019-03-04 11:33:57 +0800234 pass
Kuang-che Wu708310b2018-03-28 17:24:34 +0800235 wait_reboot_done(host, boot_id)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800236
Kuang-che Wu708310b2018-03-28 17:24:34 +0800237
238def wait_reboot_done(host, boot_id):
Kuang-che Wu4fe945b2018-03-31 16:46:38 +0800239 # For dev-mode test image, the reboot time is roughly at least 16 seconds
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800240 # (dev screen short delay) or more (long delay).
241 time.sleep(15)
242 for _ in range(100):
243 try:
244 # During boot, DUT does not response and thus ssh may hang a while. So
245 # set a connect timeout. 3 seconds are enough and 2 are not. It's okay to
246 # set tight limit because it's inside retry loop.
247 assert boot_id != query_dut_boot_id(host, connect_timeout=3)
248 return
Kuang-che Wu5f662e82019-03-05 11:49:56 +0800249 except errors.SshConnectionError:
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800250 logger.debug('reboot not ready? sleep wait 1 sec')
251 time.sleep(1)
252
Kuang-che Wue121fae2018-11-09 16:18:39 +0800253 raise errors.ExternalError('reboot failed?')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800254
255
Kuang-che Wu80bf6a52019-05-31 12:48:06 +0800256def gs_release_boardpath(board):
257 """Normalizes board name for gs://chromeos-releases/
258
259 This follows behavior of PushImage() in chromite/scripts/pushimage.py
260 Note, only gs://chromeos-releases/ needs normalization,
261 gs://chromeos-image-archive does not.
262
263 Args:
264 board: ChromeOS board name
265
266 Returns:
267 normalized board name
268 """
269 return board.replace('_', '-')
270
271
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800272def gsutil(*args, **kwargs):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800273 """gsutil command line wrapper.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800274
275 Args:
276 args: command line arguments passed to gsutil
277 kwargs:
278 ignore_errors: if true, return '' for failures, for example 'gsutil ls'
279 but the path not found.
280
281 Returns:
282 stdout of gsutil
283
284 Raises:
Kuang-che Wue121fae2018-11-09 16:18:39 +0800285 errors.InternalError: gsutil failed to run
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800286 subprocess.CalledProcessError: command failed
287 """
288 stderr_lines = []
289 try:
290 return util.check_output(
291 gsutil_bin, *args, stderr_callback=stderr_lines.append)
292 except subprocess.CalledProcessError as e:
293 stderr = ''.join(stderr_lines)
294 if re.search(r'ServiceException:.* does not have .*access', stderr):
Kuang-che Wue121fae2018-11-09 16:18:39 +0800295 raise errors.ExternalError(
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800296 'gsutil failed due to permission. ' +
297 'Run "%s config" and follow its instruction. ' % gsutil_bin +
298 'Fill any string if it asks for project-id')
299 if kwargs.get('ignore_errors'):
300 return ''
301 raise
302 except OSError as e:
303 if e.errno == errno.ENOENT:
Kuang-che Wue121fae2018-11-09 16:18:39 +0800304 raise errors.ExternalError(
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800305 'Unable to run %s. gsutil is not installed or not in PATH?' %
306 gsutil_bin)
307 raise
308
309
310def gsutil_ls(*args, **kwargs):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800311 """gsutil ls.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800312
313 Args:
314 args: arguments passed to 'gsutil ls'
315 kwargs: extra parameters, where
Kuang-che Wu4fe945b2018-03-31 16:46:38 +0800316 ignore_errors: if true, return empty list instead of raising
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800317 exception, ex. path not found.
318
319 Returns:
320 list of 'gsutil ls' result. One element for one line of gsutil output.
321
322 Raises:
323 subprocess.CalledProcessError: gsutil failed, usually means path not found
324 """
325 return gsutil('ls', *args, **kwargs).splitlines()
326
327
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800328def gsutil_stat_update_time(*args, **kwargs):
329 """Returns the last modified time of a file or multiple files.
330
331 Args:
332 args: arguments passed to 'gsutil stat'.
333 kwargs: extra parameters for gsutil.
334
335 Returns:
336 A integer indicates the last modified timestamp.
337
338 Raises:
339 subprocess.CalledProcessError: gsutil failed, usually means path not found
340 errors.ExternalError: update time is not found
341 """
342 result = -1
343 # Currently we believe stat always returns a UTC time, and strptime also
344 # parses a UTC time by default.
345 time_format = '%a, %d %b %Y %H:%M:%S GMT'
346
347 for line in gsutil('stat', *args, **kwargs).splitlines():
348 if ':' not in line:
349 continue
350 key, value = map(str.strip, line.split(':', 1))
351 if key != 'Update time':
352 continue
353 dt = datetime.datetime.strptime(value, time_format)
354 unixtime = int(time.mktime(dt.utctimetuple()))
355 result = max(result, unixtime)
356
357 if result == -1:
358 raise errors.ExternalError("didn't find update time")
359 return result
360
361
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800362def query_milestone_by_version(board, short_version):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800363 """Query milestone by ChromeOS version number.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800364
365 Args:
366 board: ChromeOS board name
367 short_version: ChromeOS version number in short format, ex. 9300.0.0
368
369 Returns:
370 ChromeOS milestone number (string). For example, '58' for '9300.0.0'.
371 None if failed.
372 """
373 path = gs_archive_path.format(board=board) + '/R*-' + short_version
374 for line in gsutil_ls('-d', path, ignore_errors=True):
375 m = re.search(r'/R(\d+)-', line)
376 if not m:
377 continue
378 return m.group(1)
379
380 for channel in ['canary', 'dev', 'beta', 'stable']:
381 path = gs_release_path.format(
Kuang-che Wu80bf6a52019-05-31 12:48:06 +0800382 channel=channel,
383 boardpath=gs_release_boardpath(board),
384 short_version=short_version)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800385 for line in gsutil_ls(path, ignore_errors=True):
386 m = re.search(r'\bR(\d+)-' + short_version, line)
387 if not m:
388 continue
389 return m.group(1)
390
391 logger.error('unable to query milestone of %s for %s', short_version, board)
392 return None
393
394
Kuang-che Wu80bf6a52019-05-31 12:48:06 +0800395def list_board_names(chromeos_root):
396 """List board names.
397
398 Args:
399 chromeos_root: chromeos tree root
400
401 Returns:
402 list of board names
403 """
404 # Following logic is simplified from chromite/lib/portage_util.py
405 cros_list_overlays = os.path.join(chromeos_root,
406 'chromite/bin/cros_list_overlays')
407 overlays = util.check_output(cros_list_overlays).splitlines()
408 result = set()
409 for overlay in overlays:
410 conf_file = os.path.join(overlay, 'metadata', 'layout.conf')
411 name = None
412 if os.path.exists(conf_file):
413 for line in open(conf_file):
414 m = re.match(r'^repo-name\s*=\s*(\S+)\s*$', line)
415 if m:
416 name = m.group(1)
417 break
418
419 if not name:
420 name_file = os.path.join(overlay, 'profiles', 'repo_name')
421 if os.path.exists(name_file):
422 name = open(name_file).read().strip()
423
424 if name:
425 name = re.sub(r'-private$', '', name)
426 result.add(name)
427
428 return list(result)
429
430
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800431def recognize_version(board, version):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800432 """Recognize ChromeOS version.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800433
434 Args:
435 board: ChromeOS board name
436 version: ChromeOS version number in short or full format
437
438 Returns:
439 (milestone, version in short format)
440 """
441 if is_cros_short_version(version):
442 milestone = query_milestone_by_version(board, version)
443 short_version = version
444 else:
445 milestone, short_version = version_split(version)
446 return milestone, short_version
447
448
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800449def extract_major_version(version):
450 """Converts a version to its major version.
451
452 Args:
453 version: ChromsOS version number or snapshot version
454
455 Returns:
456 major version number in string format
457 """
458 version = version_to_short(version)
459 m = re.match(r'^(\d+)\.\d+\.\d+$', version)
460 return m.group(1)
461
462
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800463def version_to_short(version):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800464 """Convert ChromeOS version number to short format.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800465
466 Args:
467 version: ChromeOS version number in short or full format
468
469 Returns:
470 version number in short format
471 """
472 if is_cros_short_version(version):
473 return version
474 _, short_version = version_split(version)
475 return short_version
476
477
478def version_to_full(board, version):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800479 """Convert ChromeOS version number to full format.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800480
481 Args:
482 board: ChromeOS board name
483 version: ChromeOS version number in short or full format
484
485 Returns:
486 version number in full format
487 """
488 if is_cros_full_version(version):
489 return version
490 milestone = query_milestone_by_version(board, version)
Kuang-che Wu0205f052019-05-23 12:48:37 +0800491 assert milestone, 'incorrect board=%s or version=%s ?' % (board, version)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800492 return make_cros_full_version(milestone, version)
493
494
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800495def list_snapshots_from_image_archive(board, major_version):
496 """List ChromeOS snapshot image avaliable from gs://chromeos-image-archive.
497
498 Args:
499 board: ChromeOS board
500 major_version: ChromeOS major version
501
502 Returns:
503 list of (version, gs_path):
504 version: Chrome OS snapshot version
505 gs_path: gs path of test image
506 """
507
508 path = (
509 'gs://chromeos-image-archive/{board}-postsubmit/R*-{major_version}.0.0-*')
510 result = []
511 output = gsutil_ls(
512 '-d',
513 path.format(board=board, major_version=major_version),
514 ignore_errors=True)
515
516 for path in output:
517 if not path.endswith('/'):
518 continue
519 m = re.match(r'^gs:\S+(R\d+-\d+\.\d+\.\d+-\d+)', path)
520 if m:
521 snapshot_version = m.group(1)
522 test_image = 'image.zip'
523 gs_path = path + test_image
524 result.append((snapshot_version, gs_path))
525 return result
526
527
Kuang-che Wu575dc442019-03-05 10:30:55 +0800528def list_prebuilt_from_image_archive(board):
529 """Lists ChromeOS prebuilt image available from gs://chromeos-image-archive.
530
531 gs://chromeos-image-archive contains only recent builds (in two years).
532 We prefer this function to list_prebuilt_from_chromeos_releases() because
533 - this is what "cros flash" supports directly.
534 - the paths have milestone information, so we don't need to do slow query
535 by ourselves.
536
537 Args:
538 board: ChromeOS board name
539
540 Returns:
541 list of (version, gs_path):
542 version: Chrome OS version in full format
543 gs_path: gs path of test image
544 """
545 result = []
546 for line in gsutil_ls(gs_archive_path.format(board=board)):
547 m = re.match(r'^gs:\S+(R\d+-\d+\.\d+\.\d+)', line)
548 if m:
549 full_version = m.group(1)
550 test_image = 'chromiumos_test_image.tar.xz'
551 assert line.endswith('/')
552 gs_path = line + test_image
553 result.append((full_version, gs_path))
554 return result
555
556
557def list_prebuilt_from_chromeos_releases(board):
558 """Lists ChromeOS versions available from gs://chromeos-releases.
559
560 gs://chromeos-releases contains more builds. However, 'cros flash' doesn't
561 support it.
562
563 Args:
564 board: ChromeOS board name
565
566 Returns:
567 list of (version, gs_path):
568 version: Chrome OS version in short format
569 gs_path: gs path of test image (with wildcard)
570 """
571 result = []
572 for line in gsutil_ls(
Kuang-che Wu80bf6a52019-05-31 12:48:06 +0800573 gs_release_path.format(
574 channel='*', boardpath=gs_release_boardpath(board), short_version=''),
Kuang-che Wu575dc442019-03-05 10:30:55 +0800575 ignore_errors=True):
576 m = re.match(r'gs:\S+/(\d+\.\d+\.\d+)/$', line)
577 if m:
578 short_version = m.group(1)
579 test_image = 'ChromeOS-test-R*-{short_version}-{board}.tar.xz'.format(
580 short_version=short_version, board=board)
581 gs_path = line + test_image
582 result.append((short_version, gs_path))
583 return result
584
585
586def list_chromeos_prebuilt_versions(board,
587 old,
588 new,
589 only_good_build=True,
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800590 include_older_build=True,
591 use_snapshot=False):
Kuang-che Wu575dc442019-03-05 10:30:55 +0800592 """Lists ChromeOS version numbers with prebuilt between given range
593
594 Args:
595 board: ChromeOS board name
596 old: start version (inclusive)
597 new: end version (inclusive)
598 only_good_build: only if test image is available
599 include_older_build: include prebuilt in gs://chromeos-releases
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800600 use_snapshot: return snapshot versions if found
Kuang-che Wu575dc442019-03-05 10:30:55 +0800601
602 Returns:
603 list of sorted version numbers (in full format) between [old, new] range
604 (inclusive).
605 """
606 old = version_to_short(old)
607 new = version_to_short(new)
608
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800609 rev_map = {
610 } # dict: short version -> list of (short/full or snapshot version, gs path)
Kuang-che Wu575dc442019-03-05 10:30:55 +0800611 for full_version, gs_path in list_prebuilt_from_image_archive(board):
612 short_version = version_to_short(full_version)
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800613 rev_map[short_version] = [(full_version, gs_path)]
Kuang-che Wu575dc442019-03-05 10:30:55 +0800614
615 if include_older_build and old not in rev_map:
616 for short_version, gs_path in list_prebuilt_from_chromeos_releases(board):
617 if short_version not in rev_map:
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800618 rev_map[short_version] = [(short_version, gs_path)]
619
620 if use_snapshot:
621 for major_version in range(
622 int(extract_major_version(old)),
623 int(extract_major_version(new)) + 1):
624 short_version = '%s.0.0' % major_version
625 if not util.is_direct_relative_version(short_version, old):
626 continue
627 if not util.is_direct_relative_version(short_version, new):
628 continue
629 snapshots = list_snapshots_from_image_archive(board, str(major_version))
630 if snapshots:
631 # if snapshots found, we can append them after the release version,
632 # so the prebuilt image list of this version will be
633 # release_image, snapshot1, snapshot2,...
634 rev_map[short_version] += snapshots
Kuang-che Wu575dc442019-03-05 10:30:55 +0800635
636 result = []
637 for rev in sorted(rev_map, key=util.version_key_func):
638 if not util.is_direct_relative_version(new, rev):
639 continue
640 if not util.is_version_lesseq(old, rev):
641 continue
642 if not util.is_version_lesseq(rev, new):
643 continue
644
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800645 for version, gs_path in rev_map[rev]:
Kuang-che Wu575dc442019-03-05 10:30:55 +0800646
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800647 # version_to_full() and gsutil_ls() may take long time if versions are a
648 # lot. This is acceptable because we usually bisect only short range.
Kuang-che Wu575dc442019-03-05 10:30:55 +0800649
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800650 if only_good_build:
651 gs_result = gsutil_ls(gs_path, ignore_errors=True)
652 if not gs_result:
653 logger.warning('%s is not a good build, ignore', version)
654 continue
655 assert len(gs_result) == 1
656 m = re.search(r'(R\d+-\d+\.\d+\.\d+)', gs_result[0])
657 if not m:
658 logger.warning('format of image path is unexpected: %s', gs_result[0])
659 continue
660 if not is_cros_snapshot_version(version):
661 version = m.group(1)
662 elif is_cros_short_version(version):
663 version = version_to_full(board, version)
Kuang-che Wu575dc442019-03-05 10:30:55 +0800664
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800665 result.append(version)
Kuang-che Wu575dc442019-03-05 10:30:55 +0800666
667 return result
668
669
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800670def prepare_snapshot_image(chromeos_root, board, snapshot_version):
671 """Prepare chromeos snapshot image.
672
673 Args:
674 chromeos_root: chromeos tree root
675 board: ChromeOS board name
676 snapshot_version: ChromeOS snapshot version number
677
678 Returns:
679 local file path of test image relative to chromeos_root
680 """
681 assert is_cros_snapshot_version(snapshot_version)
682 milestone, short_version, snapshot_id = snapshot_version_split(
683 snapshot_version)
684 full_version = make_cros_full_version(milestone, short_version)
685 tmp_dir = os.path.join(
686 chromeos_root, 'tmp',
687 'ChromeOS-test-%s-%s-%s' % (full_version, board, snapshot_id))
688 if not os.path.exists(tmp_dir):
689 os.makedirs(tmp_dir)
690
691 gs_path = ('gs://chromeos-image-archive/{board}-postsubmit/' +
692 '{snapshot_version}-*/image.zip')
693 gs_path = gs_path.format(board=board, snapshot_version=snapshot_version)
694
695 files = gsutil_ls(gs_path, ignore_errors=True)
696 if len(files) == 1:
697 gs_path = files[0]
698 gsutil('cp', gs_path, tmp_dir)
699 image_path = os.path.relpath(
700 os.path.join(tmp_dir, test_image_filename), chromeos_root)
701 util.check_call(
702 'unzip', '-j', 'image.zip', test_image_filename, cwd=tmp_dir)
703 os.remove(os.path.join(tmp_dir, 'image.zip'))
704
705 assert image_path
706 return image_path
707
708
Kuang-che Wu28980b22019-07-31 19:51:45 +0800709def prepare_prebuilt_image(chromeos_root, board, version):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800710 """Prepare chromeos prebuilt image.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800711
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800712 It searches for xbuddy image which "cros flash" can use, or fetch image to
713 local disk.
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800714
715 Args:
Kuang-che Wu28980b22019-07-31 19:51:45 +0800716 chromeos_root: chromeos tree root
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800717 board: ChromeOS board name
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800718 version: ChromeOS version number in short or full format
719
720 Returns:
Kuang-che Wu28980b22019-07-31 19:51:45 +0800721 xbuddy path or file path (relative to chromeos_root)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800722 """
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800723 assert is_cros_version(version)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800724 full_version = version_to_full(board, version)
725 short_version = version_to_short(full_version)
726
727 image_path = None
728 gs_path = gs_archive_path.format(board=board) + '/' + full_version
729 if gsutil_ls('-d', gs_path, ignore_errors=True):
730 image_path = 'xbuddy://remote/{board}/{full_version}/test'.format(
731 board=board, full_version=full_version)
732 else:
Kuang-che Wu28980b22019-07-31 19:51:45 +0800733 tmp_dir = os.path.join(chromeos_root, 'tmp',
734 'ChromeOS-test-%s-%s' % (full_version, board))
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800735 if not os.path.exists(tmp_dir):
736 os.makedirs(tmp_dir)
737 # gs://chromeos-releases may have more old images than
Kuang-che Wu4fe945b2018-03-31 16:46:38 +0800738 # gs://chromeos-image-archive, but 'cros flash' doesn't support it. We have
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800739 # to fetch the image by ourselves
740 for channel in ['canary', 'dev', 'beta', 'stable']:
741 fn = 'ChromeOS-test-{full_version}-{board}.tar.xz'.format(
742 full_version=full_version, board=board)
743 gs_path = gs_release_path.format(
Kuang-che Wu80bf6a52019-05-31 12:48:06 +0800744 channel=channel,
745 boardpath=gs_release_boardpath(board),
746 short_version=short_version)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800747 gs_path += '/' + fn
748 if gsutil_ls(gs_path, ignore_errors=True):
749 # TODO(kcwu): delete tmp
750 gsutil('cp', gs_path, tmp_dir)
751 util.check_call('tar', 'Jxvf', fn, cwd=tmp_dir)
Kuang-che Wu28980b22019-07-31 19:51:45 +0800752 image_path = os.path.relpath(
753 os.path.join(tmp_dir, test_image_filename), chromeos_root)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800754 break
755
756 assert image_path
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800757 return image_path
758
759
760def cros_flash(chromeos_root,
761 host,
762 board,
763 image_path,
764 version=None,
765 clobber_stateful=False,
Kuang-che Wu155fb6e2018-11-29 16:00:41 +0800766 disable_rootfs_verification=True):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800767 """Flash a DUT with given ChromeOS image.
768
769 This is implemented by 'cros flash' command line.
770
771 Args:
772 chromeos_root: use 'cros flash' of which chromeos tree
773 host: DUT address
774 board: ChromeOS board name
Kuang-che Wu28980b22019-07-31 19:51:45 +0800775 image_path: chromeos image xbuddy path or file path. For relative
776 path, it should be relative to chromeos_root.
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800777 version: ChromeOS version in short or full format
778 clobber_stateful: Clobber stateful partition when performing update
779 disable_rootfs_verification: Disable rootfs verification after update
780 is completed
Kuang-che Wu414d67f2019-05-28 11:28:57 +0800781
782 Raises:
783 errors.ExternalError: cros flash failed
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800784 """
785 logger.info('cros_flash %s %s %s %s', host, board, version, image_path)
786
787 # Reboot is necessary because sometimes previous 'cros flash' failed and
788 # entered a bad state.
789 reboot(host)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800790
Kuang-che Wu28980b22019-07-31 19:51:45 +0800791 # Handle relative path.
792 if '://' not in image_path and not os.path.isabs(image_path):
793 assert os.path.exists(os.path.join(chromeos_root, image_path))
794 image_path = os.path.join(chromeos_root_inside_chroot, image_path)
795
Kuang-che Wuf3d03ca2019-03-11 17:31:40 +0800796 args = [
797 '--debug', '--no-ping', '--send-payload-in-parallel', host, image_path
798 ]
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800799 if clobber_stateful:
800 args.append('--clobber-stateful')
801 if disable_rootfs_verification:
802 args.append('--disable-rootfs-verification')
803
Kuang-che Wu414d67f2019-05-28 11:28:57 +0800804 try:
805 cros_sdk(chromeos_root, 'cros', 'flash', *args)
806 except subprocess.CalledProcessError:
807 raise errors.ExternalError('cros flash failed')
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800808
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800809 if version:
810 # In the past, cros flash may fail with returncode=0
811 # So let's have an extra check.
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800812 if is_cros_snapshot_version(version):
813 builder_path = query_dut_lsb_release(host).get(
814 'CHROMEOS_RELEASE_BUILDER_PATH', '')
815 expect_prefix = '%s-postsubmit/%s-' % (board, version)
816 if not builder_path.startswith(expect_prefix):
817 raise errors.ExternalError(
818 'although cros flash succeeded, the OS builder path is '
819 'unexpected: actual=%s expect=%s' % (builder_path, expect_prefix))
820 else:
821 expect_version = version_to_short(version)
822 dut_version = query_dut_short_version(host)
823 if dut_version != expect_version:
824 raise errors.ExternalError(
825 'although cros flash succeeded, the OS version is unexpected: '
826 'actual=%s expect=%s' % (dut_version, expect_version))
Kuang-che Wu414d67f2019-05-28 11:28:57 +0800827
Kuang-che Wu4a81ea72019-10-05 15:35:17 +0800828 # "cros flash" may terminate successfully but the DUT starts self-repairing
Kuang-che Wu414d67f2019-05-28 11:28:57 +0800829 # (b/130786578), so it's necessary to do sanity check.
830 if not is_good_dut(host):
831 raise errors.ExternalError(
832 'although cros flash succeeded, the DUT is in bad state')
833
834
835def cros_flash_with_retry(chromeos_root,
836 host,
837 board,
838 image_path,
839 version=None,
840 clobber_stateful=False,
841 disable_rootfs_verification=True,
842 repair_callback=None):
843 # 'cros flash' is not 100% reliable, retry if necessary.
844 for attempt in range(2):
845 if attempt > 0:
846 logger.info('will retry 60 seconds later')
847 time.sleep(60)
848
849 try:
850 cros_flash(
851 chromeos_root,
852 host,
853 board,
854 image_path,
855 version=version,
856 clobber_stateful=clobber_stateful,
857 disable_rootfs_verification=disable_rootfs_verification)
858 return True
859 except errors.ExternalError:
860 logger.exception('cros flash failed')
861 if repair_callback and not repair_callback(host):
862 logger.warning('not repaired, assume it is harmless')
863 continue
864 return False
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800865
866
867def version_info(board, version):
868 """Query subcomponents version info of given version of ChromeOS
869
870 Args:
871 board: ChromeOS board name
872 version: ChromeOS version number in short or full format
873
874 Returns:
875 dict of component and version info, including (if available):
876 cros_short_version: ChromeOS version
877 cros_full_version: ChromeOS version
878 milestone: milestone of ChromeOS
879 cr_version: Chrome version
Kuang-che Wu708310b2018-03-28 17:24:34 +0800880 android_build_id: Android build id
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800881 android_branch: Android branch, in format like 'git_nyc-mr1-arc'
882 """
Zheng-Jie Chang127c3302019-09-10 17:17:04 +0800883 # TODO(zjchang): add implementation
884 if is_cros_snapshot_version(version):
885 logger.warning(
886 'The version_info function of a snapshot is not implemented ' +
887 'completely. Currently we do not provide enough information ' +
888 'for continuing Android and Chrome bisection, so we will ' +
889 'skip Android and Chrome relatead bisections.')
890 milestone, _, _ = snapshot_version_split(version)
891 return {
892 'milestone': milestone,
893 'cros_full_version': version,
894 'cros_short_version': version_to_short(version)
895 }
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800896 info = {}
897 full_version = version_to_full(board, version)
898
899 # Some boards may have only partial-metadata.json but no metadata.json.
900 # e.g. caroline R60-9462.0.0
901 # Let's try both.
902 metadata = None
903 for metadata_filename in ['metadata.json', 'partial-metadata.json']:
Kuang-che Wu0768b972019-10-05 15:18:59 +0800904 path = gs_archive_path.format(
905 board=board) + '/%s/%s' % (full_version, metadata_filename)
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800906 metadata = gsutil('cat', path, ignore_errors=True)
907 if metadata:
908 o = json.loads(metadata)
909 v = o['version']
910 board_metadata = o['board-metadata'][board]
911 info.update({
912 VERSION_KEY_CROS_SHORT_VERSION: v['platform'],
913 VERSION_KEY_CROS_FULL_VERSION: v['full'],
914 VERSION_KEY_MILESTONE: v['milestone'],
915 VERSION_KEY_CR_VERSION: v['chrome'],
916 })
917
918 if 'android' in v:
Kuang-che Wu708310b2018-03-28 17:24:34 +0800919 info[VERSION_KEY_ANDROID_BUILD_ID] = v['android']
Kuang-che Wu2ea804f2017-11-28 17:11:41 +0800920 if 'android-branch' in v: # this appears since R58-9317.0.0
921 info[VERSION_KEY_ANDROID_BRANCH] = v['android-branch']
922 elif 'android-container-branch' in board_metadata:
923 info[VERSION_KEY_ANDROID_BRANCH] = v['android-container-branch']
924 break
925 else:
926 logger.error('Failed to read metadata from gs://chromeos-image-archive')
927 logger.error(
928 'Note, so far no quick way to look up version info for too old builds')
929
930 return info
Kuang-che Wu848b1af2018-02-01 20:59:36 +0800931
932
933def query_chrome_version(board, version):
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800934 """Queries chrome version of chromeos build.
Kuang-che Wu848b1af2018-02-01 20:59:36 +0800935
936 Args:
937 board: ChromeOS board name
938 version: ChromeOS version number in short or full format
939
940 Returns:
941 Chrome version number
942 """
943 info = version_info(board, version)
944 return info['cr_version']
Kuang-che Wu708310b2018-03-28 17:24:34 +0800945
946
947def query_android_build_id(board, rev):
948 info = version_info(board, rev)
949 rev = info['android_build_id']
950 return rev
951
952
953def query_android_branch(board, rev):
954 info = version_info(board, rev)
955 rev = info['android_branch']
956 return rev
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800957
958
Kuang-che Wu3eb6b502018-06-06 16:15:18 +0800959def guess_chrome_version(board, rev):
960 """Guess chrome version number.
961
962 Args:
963 board: chromeos board name
964 rev: chrome or chromeos version
965
966 Returns:
967 chrome version number
968 """
969 if is_cros_version(rev):
970 assert board, 'need to specify BOARD for cros version'
971 rev = query_chrome_version(board, rev)
972 assert cr_util.is_chrome_version(rev)
973
974 return rev
975
976
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800977def is_inside_chroot():
978 """Returns True if we are inside chroot."""
979 return os.path.exists('/etc/cros_chroot_version')
980
981
982def cros_sdk(chromeos_root, *args, **kwargs):
983 """Run commands inside chromeos chroot.
984
985 Args:
986 chromeos_root: chromeos tree root
987 *args: command to run
988 **kwargs:
Kuang-che Wud4603d72018-11-29 17:51:21 +0800989 chrome_root: pass to cros_sdk; mount this path into the SDK chroot
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800990 env: (dict) environment variables for the command
Kuang-che Wubcafc552019-08-15 15:27:02 +0800991 log_stdout: Whether write the stdout output of the child process to log.
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800992 stdin: standard input file handle for the command
Kuang-che Wu9890ce82018-07-07 15:14:10 +0800993 stderr_callback: Callback function for stderr. Called once per line.
Kuang-che Wua9a20bb2019-09-05 22:24:04 +0800994 goma_dir: Goma installed directory to mount into the chroot
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800995 """
996 envs = []
997 for k, v in kwargs.get('env', {}).items():
998 assert re.match(r'^[A-Za-z_][A-Za-z0-9_]*$', k)
999 envs.append('%s=%s' % (k, v))
1000
1001 # Use --no-ns-pid to prevent cros_sdk change our pgid, otherwise subsequent
1002 # commands would be considered as background process.
Kuang-che Wu399d4662019-06-06 15:23:37 +08001003 prefix = ['chromite/bin/cros_sdk', '--no-ns-pid']
Kuang-che Wud4603d72018-11-29 17:51:21 +08001004
1005 if kwargs.get('chrome_root'):
Kuang-che Wu399d4662019-06-06 15:23:37 +08001006 prefix += ['--chrome_root', kwargs['chrome_root']]
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001007 if kwargs.get('goma_dir'):
1008 prefix += ['--goma_dir', kwargs['goma_dir']]
Kuang-che Wud4603d72018-11-29 17:51:21 +08001009
Kuang-che Wu399d4662019-06-06 15:23:37 +08001010 prefix += envs + ['--']
Kuang-che Wud4603d72018-11-29 17:51:21 +08001011
Kuang-che Wu399d4662019-06-06 15:23:37 +08001012 # In addition to the output of command we are interested, cros_sdk may
1013 # generate its own messages. For example, chroot creation messages if we run
1014 # cros_sdk the first time.
1015 # This is the hack to run dummy command once, so we can get clean output for
1016 # the command we are interested.
1017 cmd = prefix + ['true']
1018 util.check_call(*cmd, cwd=chromeos_root)
1019
1020 cmd = prefix + list(args)
Kuang-che Wu9890ce82018-07-07 15:14:10 +08001021 return util.check_output(
1022 *cmd,
1023 cwd=chromeos_root,
Kuang-che Wubcafc552019-08-15 15:27:02 +08001024 log_stdout=kwargs.get('log_stdout', True),
Kuang-che Wu9890ce82018-07-07 15:14:10 +08001025 stdin=kwargs.get('stdin'),
1026 stderr_callback=kwargs.get('stderr_callback'))
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001027
1028
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001029def create_chroot(chromeos_root):
1030 """Creates ChromeOS chroot.
1031
1032 Args:
1033 chromeos_root: chromeos tree root
1034 """
1035 if os.path.exists(os.path.join(chromeos_root, 'chroot')):
1036 return
1037 if os.path.exists(os.path.join(chromeos_root, 'chroot.img')):
1038 return
1039
1040 util.check_output('chromite/bin/cros_sdk', '--create', cwd=chromeos_root)
1041
1042
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001043def copy_into_chroot(chromeos_root, src, dst):
1044 """Copies file into chromeos chroot.
1045
1046 Args:
1047 chromeos_root: chromeos tree root
1048 src: path outside chroot
1049 dst: path inside chroot
1050 """
1051 # chroot may be an image, so we cannot copy to corresponding path
1052 # directly.
1053 cros_sdk(chromeos_root, 'sh', '-c', 'cat > %s' % dst, stdin=open(src))
1054
1055
1056def exists_in_chroot(chromeos_root, path):
1057 """Determine whether a path exists in the chroot.
1058
1059 Args:
1060 chromeos_root: chromeos tree root
1061 path: path inside chroot, relative to src/scripts
1062
1063 Returns:
1064 True if a path exists
1065 """
1066 try:
Kuang-che Wuacb6efd2018-04-25 18:52:58 +08001067 cros_sdk(chromeos_root, 'test', '-e', path)
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001068 except subprocess.CalledProcessError:
1069 return False
1070 return True
1071
1072
Kuang-che Wu9890ce82018-07-07 15:14:10 +08001073def check_if_need_recreate_chroot(stdout, stderr):
1074 """Analyze build log and determine if chroot should be recreated.
1075
1076 Args:
1077 stdout: stdout output of build
1078 stderr: stderr output of build
1079
1080 Returns:
1081 the reason if chroot needs recreated; None otherwise
1082 """
Kuang-che Wu74768d32018-09-07 12:03:24 +08001083 if re.search(
1084 r"The current version of portage supports EAPI '\d+'. "
Kuang-che Wuae6824b2019-08-27 22:20:01 +08001085 'You must upgrade', stderr):
Kuang-che Wu9890ce82018-07-07 15:14:10 +08001086 return 'EAPI version mismatch'
1087
Kuang-che Wu5ac81322018-11-26 14:04:06 +08001088 if 'Chroot is too new. Consider running:' in stderr:
1089 return 'chroot version is too new'
1090
1091 # old message before Oct 2018
Kuang-che Wu9890ce82018-07-07 15:14:10 +08001092 if 'Chroot version is too new. Consider running cros_sdk --replace' in stderr:
1093 return 'chroot version is too new'
1094
Kuang-che Wu6fe987f2018-08-28 15:24:20 +08001095 # https://groups.google.com/a/chromium.org/forum/#!msg/chromium-os-dev/uzwT5APspB4/NFakFyCIDwAJ
1096 if "undefined reference to 'std::__1::basic_string" in stdout:
1097 return 'might be due to compiler change'
1098
Kuang-che Wu9890ce82018-07-07 15:14:10 +08001099 return None
1100
1101
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001102def build_packages(chromeos_root,
1103 board,
1104 chrome_root=None,
1105 goma_dir=None,
1106 afdo_use=False):
Kuang-che Wu28980b22019-07-31 19:51:45 +08001107 """Build ChromeOS packages.
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001108
1109 Args:
1110 chromeos_root: chromeos tree root
1111 board: ChromeOS board name
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001112 chrome_root: Chrome tree root. If specified, build chrome using the
1113 provided tree
1114 goma_dir: Goma installed directory to mount into the chroot. If specified,
1115 build chrome with goma.
1116 afdo_use: build chrome with AFDO optimization
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001117 """
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001118 common_env = {
1119 'USE': '-cros-debug chrome_internal',
1120 'FEATURES': 'separatedebug',
1121 }
Kuang-che Wu9890ce82018-07-07 15:14:10 +08001122 stderr_lines = []
1123 try:
Kuang-che Wufb553102018-10-02 18:14:29 +08001124 with locking.lock_file(locking.LOCK_FILE_FOR_BUILD):
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001125 env = common_env.copy()
1126 env['FEATURES'] += ' -separatedebug splitdebug'
Kuang-che Wufb553102018-10-02 18:14:29 +08001127 cros_sdk(
1128 chromeos_root,
Kuang-che Wu28980b22019-07-31 19:51:45 +08001129 './update_chroot',
1130 '--toolchain_boards',
Kuang-che Wufb553102018-10-02 18:14:29 +08001131 board,
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001132 env=env,
Kuang-che Wu28980b22019-07-31 19:51:45 +08001133 stderr_callback=stderr_lines.append)
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001134
1135 env = common_env.copy()
1136 cmd = [
Kuang-che Wu28980b22019-07-31 19:51:45 +08001137 './build_packages',
1138 '--board',
1139 board,
1140 '--withdev',
1141 '--noworkon',
1142 '--skip_chroot_upgrade',
1143 '--accept_licenses=@CHROMEOS',
Kuang-che Wua9a20bb2019-09-05 22:24:04 +08001144 ]
1145 if goma_dir:
1146 # Tell build_packages to start and stop goma
1147 cmd.append('--run_goma')
1148 env['USE_GOMA'] = 'true'
1149 if afdo_use:
1150 env['USE'] += ' afdo_use'
1151 cros_sdk(
1152 chromeos_root,
1153 *cmd,
1154 env=env,
1155 chrome_root=chrome_root,
1156 stderr_callback=stderr_lines.append,
1157 goma_dir=goma_dir)
Kuang-che Wu9890ce82018-07-07 15:14:10 +08001158 except subprocess.CalledProcessError as e:
1159 # Detect failures due to incompatibility between chroot and source tree. If
1160 # so, notify the caller to recreate chroot and retry.
1161 reason = check_if_need_recreate_chroot(e.output, ''.join(stderr_lines))
1162 if reason:
1163 raise NeedRecreateChrootException(reason)
1164
1165 # For other failures, don't know how to handle. Just bail out.
1166 raise
1167
Kuang-che Wu28980b22019-07-31 19:51:45 +08001168
1169def build_image(chromeos_root, board):
1170 """Build ChromeOS image.
1171
1172 Args:
1173 chromeos_root: chromeos tree root
1174 board: ChromeOS board name
1175
1176 Returns:
1177 image folder; relative to chromeos_root
1178 """
1179 stderr_lines = []
1180 try:
1181 with locking.lock_file(locking.LOCK_FILE_FOR_BUILD):
1182 cros_sdk(
1183 chromeos_root,
1184 './build_image',
1185 '--board',
1186 board,
1187 '--noenable_rootfs_verification',
1188 'test',
1189 env={
1190 'USE': '-cros-debug chrome_internal',
1191 'FEATURES': 'separatedebug',
1192 },
1193 stderr_callback=stderr_lines.append)
1194 except subprocess.CalledProcessError as e:
1195 # Detect failures due to incompatibility between chroot and source tree. If
1196 # so, notify the caller to recreate chroot and retry.
1197 reason = check_if_need_recreate_chroot(e.output, ''.join(stderr_lines))
1198 if reason:
1199 raise NeedRecreateChrootException(reason)
1200
1201 # For other failures, don't know how to handle. Just bail out.
1202 raise
1203
1204 image_symlink = os.path.join(chromeos_root, cached_images_dir, board,
1205 'latest')
1206 assert os.path.exists(image_symlink)
1207 image_name = os.readlink(image_symlink)
1208 image_folder = os.path.join(cached_images_dir, board, image_name)
1209 assert os.path.exists(
1210 os.path.join(chromeos_root, image_folder, test_image_filename))
1211 return image_folder
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001212
1213
Kuang-che Wub9705bd2018-06-28 17:59:18 +08001214class AutotestControlInfo(object):
1215 """Parsed content of autotest control file.
1216
1217 Attributes:
1218 name: test name
1219 path: control file path
1220 variables: dict of top-level control variables. Sample keys: NAME, AUTHOR,
1221 DOC, ATTRIBUTES, DEPENDENCIES, etc.
1222 """
1223
1224 def __init__(self, path, variables):
1225 self.name = variables['NAME']
1226 self.path = path
1227 self.variables = variables
1228
1229
1230def parse_autotest_control_file(path):
1231 """Parses autotest control file.
1232
1233 This only parses simple top-level string assignments.
1234
1235 Returns:
1236 AutotestControlInfo object
1237 """
1238 variables = {}
1239 code = ast.parse(open(path).read())
1240 for stmt in code.body:
1241 # Skip if not simple "NAME = *" assignment.
1242 if not (isinstance(stmt, ast.Assign) and len(stmt.targets) == 1 and
1243 isinstance(stmt.targets[0], ast.Name)):
1244 continue
1245
1246 # Only support string value.
1247 if isinstance(stmt.value, ast.Str):
1248 variables[stmt.targets[0].id] = stmt.value.s
1249
1250 return AutotestControlInfo(path, variables)
1251
1252
1253def enumerate_autotest_control_files(autotest_dir):
1254 """Enumerate autotest control files.
1255
1256 Args:
1257 autotest_dir: autotest folder
1258
1259 Returns:
1260 list of paths to control files
1261 """
1262 # Where to find control files. Relative to autotest_dir.
1263 subpaths = [
1264 'server/site_tests',
1265 'client/site_tests',
1266 'server/tests',
1267 'client/tests',
1268 ]
1269
1270 blacklist = ['site-packages', 'venv', 'results', 'logs', 'containers']
1271 result = []
1272 for subpath in subpaths:
1273 path = os.path.join(autotest_dir, subpath)
1274 for root, dirs, files in os.walk(path):
1275
1276 for black in blacklist:
1277 if black in dirs:
1278 dirs.remove(black)
1279
1280 for filename in files:
1281 if filename == 'control' or filename.startswith('control.'):
1282 result.append(os.path.join(root, filename))
1283
1284 return result
1285
1286
1287def get_autotest_test_info(autotest_dir, test_name):
1288 """Get metadata of given test.
1289
1290 Args:
1291 autotest_dir: autotest folder
1292 test_name: test name
1293
1294 Returns:
1295 AutotestControlInfo object. None if test not found.
1296 """
1297 for control_file in enumerate_autotest_control_files(autotest_dir):
1298 info = parse_autotest_control_file(control_file)
1299 if info.name == test_name:
1300 return info
1301 return None
1302
1303
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001304class ChromeOSSpecManager(codechange.SpecManager):
1305 """Repo manifest related operations.
1306
1307 This class enumerates chromeos manifest files, parses them,
1308 and sync to disk state according to them.
1309 """
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001310
1311 def __init__(self, config):
1312 self.config = config
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001313 self.manifest_dir = os.path.join(self.config['chromeos_root'], '.repo',
1314 'manifests')
Zheng-Jie Chang127c3302019-09-10 17:17:04 +08001315 self.manifest_internal_dir = os.path.join(self.config['chromeos_mirror'],
1316 'manifest-internal.git')
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001317 self.historical_manifest_git_dir = os.path.join(
Kuang-che Wud8fc9572018-10-03 21:00:41 +08001318 self.config['chromeos_mirror'], 'chromeos/manifest-versions.git')
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001319 if not os.path.exists(self.historical_manifest_git_dir):
Kuang-che Wue121fae2018-11-09 16:18:39 +08001320 raise errors.InternalError('Manifest snapshots should be cloned into %s' %
1321 self.historical_manifest_git_dir)
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001322
Zheng-Jie Chang127c3302019-09-10 17:17:04 +08001323 def lookup_snapshot_manifest_revisions(self, old, new):
1324 """Get manifest commits between snapshot versions.
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001325
Zheng-Jie Chang127c3302019-09-10 17:17:04 +08001326 Returns:
1327 list of (timestamp, commit_id, snapshot_id):
1328 timestamp: integer unix timestamp
1329 commit_id: a string indicates commit hash
1330 snapshot_id: a string indicates snapshot id
1331 """
1332 assert is_cros_snapshot_version(old)
1333 assert is_cros_snapshot_version(new)
1334
1335 gs_path = (
1336 'gs://chromeos-image-archive/{board}-postsubmit/{version}-*/image.zip')
1337 # Try to guess the commit time of a snapshot manifest, it is usually a few
1338 # minutes different between snapshot manifest commit and image.zip
1339 # generate.
1340 try:
1341 old_timestamp = gsutil_stat_update_time(
1342 gs_path.format(board=self.config['board'], version=old)) - 86400
1343 except subprocess.CalledProcessError:
1344 old_timestamp = None
1345 try:
1346 new_timestamp = gsutil_stat_update_time(
1347 gs_path.format(board=self.config['board'], version=new)) + 86400
1348 # 1558657989 is snapshot_id 5982's commit time, this ensures every time
1349 # we can find snapshot 5982
1350 # snapshot_id <= 5982 has different commit message format, so we need
1351 # to identify its id in different ways, see below comment for more info.
1352 new_timestamp = max(new_timestamp, 1558657989 + 1)
1353 except subprocess.CalledProcessError:
1354 new_timestamp = None
1355 result = []
1356 _, _, old_snapshot_id = snapshot_version_split(old)
1357 _, _, new_snapshot_id = snapshot_version_split(new)
1358 repo = self.manifest_internal_dir
1359 path = 'snapshot.xml'
1360 branch = 'snapshot'
1361 commits = git_util.get_history(
1362 repo,
1363 path,
1364 branch,
1365 after=old_timestamp,
1366 before=new_timestamp,
1367 with_subject=True)
1368
1369 # Unfortunately, we can not identify snapshot_id <= 5982 from its commit
1370 # subject, as their subjects are all `Annealing manifest snapshot.`.
1371 # So instead we count the snapshot_id manually.
1372 count = 5982
1373 # There are two snapshot_id = 2633 in commit history, ignore the former
1374 # one.
1375 ignore_list = ['95c8526a7f0798d02f692010669dcbd5a152439a']
1376 # We examine the commits in reverse order as there are some testing
1377 # commits before snapshot_id=2, this method works fine after
1378 # snapshot 2, except snapshot 2633
1379 for commit in reversed(commits):
1380 msg = commit[2]
1381 if commit[1] in ignore_list:
1382 continue
1383
1384 match = re.match(r'^annealing manifest snapshot (\d+)', msg)
1385 if match:
1386 snapshot_id = match.group(1)
1387 elif 'Annealing manifest snapshot' in msg:
1388 snapshot_id = str(count)
1389 count -= 1
1390 else:
1391 continue
1392 if int(old_snapshot_id) <= int(snapshot_id) <= int(new_snapshot_id):
1393 result.append((commit[0], commit[1], snapshot_id))
1394 # We find commits in reversed order, now reverse it again to chronological
1395 # order.
1396 return list(reversed(result))
1397
1398 def lookup_build_timestamp(self, rev):
1399 assert is_cros_full_version(rev) or is_cros_snapshot_version(rev)
1400 if is_cros_full_version(rev):
1401 return self.lookup_release_build_timestamp(rev)
1402 else:
1403 return self.lookup_snapshot_build_timestamp(rev)
1404
1405 def lookup_snapshot_build_timestamp(self, rev):
1406 assert is_cros_snapshot_version(rev)
1407 return int(self.lookup_snapshot_manifest_revisions(rev, rev)[0][0])
1408
1409 def lookup_release_build_timestamp(self, rev):
1410 assert is_cros_full_version(rev)
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001411 milestone, short_version = version_split(rev)
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001412 path = os.path.join('buildspecs', milestone, short_version + '.xml')
1413 try:
1414 timestamp = git_util.get_commit_time(self.historical_manifest_git_dir,
1415 'refs/heads/master', path)
1416 except ValueError:
Zheng-Jie Chang127c3302019-09-10 17:17:04 +08001417 raise errors.InternalError('%s does not have %s' %
1418 (self.historical_manifest_git_dir, path))
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001419 return timestamp
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001420
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001421 def collect_float_spec(self, old, new):
1422 old_timestamp = self.lookup_build_timestamp(old)
1423 new_timestamp = self.lookup_build_timestamp(new)
Zheng-Jie Chang127c3302019-09-10 17:17:04 +08001424 # snapshot time is different from commit time
1425 # usually it's a few minutes different
1426 # 30 minutes should be safe in most cases
1427 if is_cros_snapshot_version(old):
1428 old_timestamp = old_timestamp - 1800
1429 if is_cros_snapshot_version(new):
1430 new_timestamp = new_timestamp + 1800
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001431
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001432 path = os.path.join(self.manifest_dir, 'default.xml')
1433 if not os.path.islink(path) or os.readlink(path) != 'full.xml':
Kuang-che Wue121fae2018-11-09 16:18:39 +08001434 raise errors.InternalError(
1435 'default.xml not symlink to full.xml is not supported')
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001436
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001437 result = []
1438 path = 'full.xml'
1439 parser = repo_util.ManifestParser(self.manifest_dir)
1440 for timestamp, git_rev in parser.enumerate_manifest_commits(
1441 old_timestamp, new_timestamp, path):
1442 result.append(
1443 codechange.Spec(codechange.SPEC_FLOAT, git_rev, timestamp, path))
1444 return result
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001445
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001446 def collect_fixed_spec(self, old, new):
Zheng-Jie Chang127c3302019-09-10 17:17:04 +08001447 assert is_cros_full_version(old) or is_cros_snapshot_version(old)
1448 assert is_cros_full_version(new) or is_cros_snapshot_version(new)
1449
1450 # case 1: if both are snapshot, return a list of snapshot
1451 if is_cros_snapshot_version(old) and is_cros_snapshot_version(new):
1452 return self.collect_snapshot_specs(old, new)
1453
1454 # case 2: if both are release version
1455 # return a list of release version
1456 if is_cros_full_version(old) and is_cros_full_version(new):
1457 return self.collect_release_specs(old, new)
1458
1459 # case 3: return a list of release version and append a snapshot
1460 # before or at the end
1461 result = self.collect_release_specs(old, new)
1462 if is_cros_snapshot_version(old):
1463 result = self.collect_release_specs(old, old) + result[1:]
1464 elif is_cros_snapshot_version(new):
1465 result = result[:-1] + self.collect_release_specs(new, new)
1466 return result
1467
1468 def collect_snapshot_specs(self, old, new):
1469 assert is_cros_snapshot_version(old)
1470 assert is_cros_snapshot_version(new)
1471
1472 def guess_snapshot_version(board, snapshot_id, old, new):
1473 if old.endswith('-' + snapshot_id):
1474 return old
1475 if new.endswith('-' + snapshot_id):
1476 return new
1477 gs_path = (
1478 'gs://chromeos-image-archive/{board}-postsubmit/' +
1479 'R*-{snapshot_id}-*'.format(board=board, snapshot_id=snapshot_id))
1480 for line in gsutil_ls(gs_path, ignore_errors=True):
1481 m = re.match(r'^gs:\S+(R\d+-\d+\.\d+\.\d+-\d+)\S+', line)
1482 if m:
1483 return m.group(1)
1484 raise errors.ExternalError(
1485 'guess_snapshot_version failed, board=%s snapshot_id=%s ' +
1486 'old=%s new=%s', board, snapshot_id, old, new)
1487
1488 result = []
1489 path = 'snapshot.xml'
1490 revisions = self.lookup_snapshot_manifest_revisions(old, new)
1491 for timestamp, git_rev, snapshot_id in revisions:
1492 snapshot_version = guess_snapshot_version(self.config['board'],
1493 snapshot_id, old, new)
1494 result.append(
1495 codechange.Spec(codechange.SPEC_FIXED, snapshot_version, timestamp,
1496 path))
1497 return result
1498
1499 def collect_release_specs(self, old, new):
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001500 assert is_cros_full_version(old)
1501 assert is_cros_full_version(new)
1502 old_milestone, old_short_version = version_split(old)
1503 new_milestone, new_short_version = version_split(new)
1504
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001505 result = []
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001506 for milestone in git_util.list_dir_from_revision(
1507 self.historical_manifest_git_dir, 'refs/heads/master', 'buildspecs'):
1508 if not milestone.isdigit():
1509 continue
1510 if not int(old_milestone) <= int(milestone) <= int(new_milestone):
1511 continue
1512
Kuang-che Wu74768d32018-09-07 12:03:24 +08001513 files = git_util.list_dir_from_revision(
1514 self.historical_manifest_git_dir, 'refs/heads/master',
1515 os.path.join('buildspecs', milestone))
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001516
1517 for fn in files:
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001518 path = os.path.join('buildspecs', milestone, fn)
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001519 short_version, ext = os.path.splitext(fn)
1520 if ext != '.xml':
1521 continue
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001522 if (util.is_version_lesseq(old_short_version, short_version) and
1523 util.is_version_lesseq(short_version, new_short_version) and
1524 util.is_direct_relative_version(short_version, new_short_version)):
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001525 rev = make_cros_full_version(milestone, short_version)
1526 timestamp = git_util.get_commit_time(self.historical_manifest_git_dir,
1527 'refs/heads/master', path)
1528 result.append(
1529 codechange.Spec(codechange.SPEC_FIXED, rev, timestamp, path))
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001530
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001531 def version_key_func(spec):
1532 _milestone, short_version = version_split(spec.name)
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001533 return util.version_key_func(short_version)
1534
1535 result.sort(key=version_key_func)
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001536 assert result[0].name == old
1537 assert result[-1].name == new
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001538 return result
1539
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001540 def get_manifest(self, rev):
Zheng-Jie Chang127c3302019-09-10 17:17:04 +08001541 assert is_cros_full_version(rev) or is_cros_snapshot_version(rev)
1542 if is_cros_full_version(rev):
1543 milestone, short_version = version_split(rev)
1544 path = os.path.join('buildspecs', milestone, '%s.xml' % short_version)
1545 manifest = git_util.get_file_from_revision(
1546 self.historical_manifest_git_dir, 'refs/heads/master', path)
1547 else:
1548 revisions = self.lookup_snapshot_manifest_revisions(rev, rev)
1549 commit_id = revisions[0][1]
1550 manifest = git_util.get_file_from_revision(self.manifest_internal_dir,
1551 commit_id, 'snapshot.xml')
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001552 manifest_name = 'manifest_%s.xml' % rev
1553 manifest_path = os.path.join(self.manifest_dir, manifest_name)
1554 with open(manifest_path, 'w') as f:
1555 f.write(manifest)
1556
1557 return manifest_name
1558
1559 def parse_spec(self, spec):
1560 parser = repo_util.ManifestParser(self.manifest_dir)
1561 if spec.spec_type == codechange.SPEC_FIXED:
1562 manifest_name = self.get_manifest(spec.name)
1563 manifest_path = os.path.join(self.manifest_dir, manifest_name)
1564 content = open(manifest_path).read()
1565 root = parser.parse_single_xml(content, allow_include=False)
1566 else:
1567 root = parser.parse_xml_recursive(spec.name, spec.path)
1568
1569 spec.entries = parser.process_parsed_result(root)
1570 if spec.spec_type == codechange.SPEC_FIXED:
Kuang-che Wufe1e88a2019-09-10 21:52:25 +08001571 if not spec.is_static():
1572 raise ValueError(
1573 'fixed spec %r has unexpected floating entries' % spec.name)
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001574
1575 def sync_disk_state(self, rev):
1576 manifest_name = self.get_manifest(rev)
1577
1578 # For ChromeOS, mark_as_stable step requires 'repo init -m', which sticks
1579 # manifest. 'repo sync -m' is not enough
1580 repo_util.init(
1581 self.config['chromeos_root'],
1582 'https://chrome-internal.googlesource.com/chromeos/manifest-internal',
1583 manifest_name=manifest_name,
1584 repo_url='https://chromium.googlesource.com/external/repo.git',
Kuang-che Wud8fc9572018-10-03 21:00:41 +08001585 reference=self.config['chromeos_mirror'],
Kuang-che Wue4bae0b2018-07-19 12:10:14 +08001586 )
1587
1588 # Note, don't sync with current_branch=True for chromeos. One of its
1589 # build steps (inside mark_as_stable) executes "git describe" which
1590 # needs git tag information.
1591 repo_util.sync(self.config['chromeos_root'])