blob: 0fdc9c1d88ad569329d90e31028156c30e2a174f [file] [log] [blame]
Alex Kleineb77ffa2019-05-28 14:47:44 -06001# -*- coding: utf-8 -*-
2# Copyright 2019 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
6"""Package utility functionality."""
7
8from __future__ import print_function
9
Yaakov Shaul730814a2019-09-10 13:58:25 -060010import collections
Yaakov Shaulcb1cfc32019-09-16 13:51:19 -060011import fileinput
Alex Klein87531182019-08-12 15:23:37 -060012import functools
Yaakov Shaul395ae832019-09-09 14:45:32 -060013import json
Evan Hernandezb51f1522019-08-15 11:29:40 -060014import os
Michael Mortensenb70e8a82019-10-10 18:43:41 -060015import re
Yaakov Shaulcb1cfc32019-09-16 13:51:19 -060016import sys
Alex Klein87531182019-08-12 15:23:37 -060017
Yaakov Shaul730814a2019-09-10 13:58:25 -060018
Michael Mortensen9fdb14b2019-10-17 11:17:30 -060019from chromite.cbuildbot import manifest_version
Alex Kleineb77ffa2019-05-28 14:47:44 -060020from chromite.lib import constants
Evan Hernandezb51f1522019-08-15 11:29:40 -060021from chromite.lib import cros_build_lib
Alex Klein4de25e82019-08-05 15:58:39 -060022from chromite.lib import cros_logging as logging
Alex Kleineb77ffa2019-05-28 14:47:44 -060023from chromite.lib import git
Michael Mortensenb70e8a82019-10-10 18:43:41 -060024from chromite.lib import osutils
Alex Kleineb77ffa2019-05-28 14:47:44 -060025from chromite.lib import portage_util
Alex Kleind6195b62019-08-06 16:01:16 -060026from chromite.lib import uprev_lib
Alex Kleineb77ffa2019-05-28 14:47:44 -060027
Alex Klein36b117f2019-09-30 15:13:46 -060028if cros_build_lib.IsInsideChroot():
29 from chromite.service import dependency
30
Alex Klein87531182019-08-12 15:23:37 -060031# Registered handlers for uprevving versioned packages.
32_UPREV_FUNCS = {}
33
Alex Kleineb77ffa2019-05-28 14:47:44 -060034
35class Error(Exception):
36 """Module's base error class."""
37
38
Alex Klein4de25e82019-08-05 15:58:39 -060039class UnknownPackageError(Error):
40 """Uprev attempted for a package without a registered handler."""
41
42
Alex Kleineb77ffa2019-05-28 14:47:44 -060043class UprevError(Error):
44 """An error occurred while uprevving packages."""
45
46
Michael Mortensenb70e8a82019-10-10 18:43:41 -060047class NoAndroidVersionError(Error):
48 """An error occurred while trying to determine the android version."""
49
50
51class NoAndroidBranchError(Error):
52 """An error occurred while trying to determine the android branch."""
53
54
55class NoAndroidTargetError(Error):
56 """An error occurred while trying to determine the android target."""
57
58
Alex Klein4de25e82019-08-05 15:58:39 -060059class AndroidIsPinnedUprevError(UprevError):
60 """Raised when we try to uprev while Android is pinned."""
61
62 def __init__(self, new_android_atom):
63 """Initialize a AndroidIsPinnedUprevError.
64
65 Args:
66 new_android_atom: The Android atom that we failed to
67 uprev to, due to Android being pinned.
68 """
69 assert new_android_atom
70 msg = ('Failed up uprev to Android version %s as Android was pinned.' %
71 new_android_atom)
72 super(AndroidIsPinnedUprevError, self).__init__(msg)
73 self.new_android_atom = new_android_atom
Alex Klein87531182019-08-12 15:23:37 -060074
75
Yaakov Shaul1eafe832019-09-10 16:50:26 -060076class EbuildManifestError(Error):
77 """Error when running ebuild manifest."""
78
79
Yaakov Shaul730814a2019-09-10 13:58:25 -060080UprevVersionedPackageModifications = collections.namedtuple(
81 'UprevVersionedPackageModifications', ('new_version', 'files'))
Alex Klein34afcbc2019-08-22 16:14:31 -060082
Yaakov Shaul730814a2019-09-10 13:58:25 -060083
84class UprevVersionedPackageResult(object):
85 """Data object for uprev_versioned_package."""
86
87 def __init__(self):
88 self.modified = []
89
90 def add_result(self, new_version, modified_files):
91 """Adds version/ebuilds tuple to result.
92
93 Args:
94 new_version: New version number of package.
95 modified_files: List of files modified for the given version.
96 """
97 result = UprevVersionedPackageModifications(new_version, modified_files)
98 self.modified.append(result)
99 return self
Alex Klein34afcbc2019-08-22 16:14:31 -0600100
101 @property
102 def uprevved(self):
Yaakov Shaul730814a2019-09-10 13:58:25 -0600103 return bool(self.modified)
Alex Klein34afcbc2019-08-22 16:14:31 -0600104
105
Yaakov Shaulcb1cfc32019-09-16 13:51:19 -0600106def patch_ebuild_vars(ebuild_path, variables):
107 """Updates variables in ebuild.
108
109 Use this function rather than portage_util.EBuild.UpdateEBuild when you
110 want to preserve the variable position and quotes within the ebuild.
111
112 Args:
113 ebuild_path: The path of the ebuild.
114 variables: Dictionary of variables to update in ebuild.
115 """
116 try:
117 for line in fileinput.input(ebuild_path, inplace=1):
118 varname, eq, _ = line.partition('=')
119 if eq == '=' and varname.strip() in variables:
120 value = variables[varname]
121 sys.stdout.write('%s="%s"\n' % (varname, value))
122 else:
123 sys.stdout.write(line)
124 finally:
125 fileinput.close()
126
127
Alex Klein87531182019-08-12 15:23:37 -0600128def uprevs_versioned_package(package):
129 """Decorator to register package uprev handlers."""
130 assert package
131
132 def register(func):
133 """Registers |func| as a handler for |package|."""
134 _UPREV_FUNCS[package] = func
135
136 @functools.wraps(func)
137 def pass_through(*args, **kwargs):
138 return func(*args, **kwargs)
139
140 return pass_through
141
142 return register
143
144
Alex Klein4de25e82019-08-05 15:58:39 -0600145def uprev_android(tracking_branch, android_package, android_build_branch,
146 chroot, build_targets=None, android_version=None,
147 android_gts_build_branch=None):
148 """Returns the portage atom for the revved Android ebuild - see man emerge."""
149 command = ['cros_mark_android_as_stable',
150 '--tracking_branch=%s' % tracking_branch,
151 '--android_package=%s' % android_package,
152 '--android_build_branch=%s' % android_build_branch]
153 if build_targets:
154 command.append('--boards=%s' % ':'.join(bt.name for bt in build_targets))
155 if android_version:
156 command.append('--force_version=%s' % android_version)
157 if android_gts_build_branch:
158 command.append('--android_gts_build_branch=%s' % android_gts_build_branch)
159
Mike Frysinger45602c72019-09-22 02:15:11 -0400160 result = cros_build_lib.run(command, redirect_stdout=True,
161 enter_chroot=True,
162 chroot_args=chroot.get_enter_args())
Alex Klein4de25e82019-08-05 15:58:39 -0600163
164 android_atom = _parse_android_atom(result)
165 if not android_atom:
166 logging.info('Found nothing to rev.')
167 return None
168
169 for target in build_targets or []:
170 # Sanity check: We should always be able to merge the version of
171 # Android we just unmasked.
172 command = ['emerge-%s' % target.name, '-p', '--quiet',
173 '=%s' % android_atom]
174 try:
Mike Frysinger45602c72019-09-22 02:15:11 -0400175 cros_build_lib.run(command, enter_chroot=True,
176 chroot_args=chroot.get_enter_args())
Alex Klein4de25e82019-08-05 15:58:39 -0600177 except cros_build_lib.RunCommandError:
178 logging.error(
179 'Cannot emerge-%s =%s\nIs Android pinned to an older '
180 'version?', target, android_atom)
181 raise AndroidIsPinnedUprevError(android_atom)
182
183 return android_atom
184
185
186def _parse_android_atom(result):
187 """Helper to parse the atom from the cros_mark_android_as_stable output.
188
189 This function is largely just intended to make testing easier.
190
191 Args:
192 result (cros_build_lib.CommandResult): The cros_mark_android_as_stable
193 command result.
194 """
195 portage_atom_string = result.output.strip()
196
197 android_atom = None
198 if portage_atom_string:
199 android_atom = portage_atom_string.splitlines()[-1].partition('=')[-1]
200
201 return android_atom
202
203
Alex Kleineb77ffa2019-05-28 14:47:44 -0600204def uprev_build_targets(build_targets, overlay_type, chroot=None,
205 output_dir=None):
206 """Uprev the set provided build targets, or all if not specified.
207
208 Args:
209 build_targets (list[build_target_util.BuildTarget]|None): The build targets
210 whose overlays should be uprevved, empty or None for all.
211 overlay_type (str): One of the valid overlay types except None (see
212 constants.VALID_OVERLAYS).
213 chroot (chroot_lib.Chroot|None): The chroot to clean, if desired.
214 output_dir (str|None): The path to optionally dump result files.
215 """
216 # Need a valid overlay, but exclude None.
217 assert overlay_type and overlay_type in constants.VALID_OVERLAYS
218
219 if build_targets:
220 overlays = portage_util.FindOverlaysForBoards(
221 overlay_type, boards=[t.name for t in build_targets])
222 else:
223 overlays = portage_util.FindOverlays(overlay_type)
224
225 return uprev_overlays(overlays, build_targets=build_targets, chroot=chroot,
226 output_dir=output_dir)
227
228
229def uprev_overlays(overlays, build_targets=None, chroot=None, output_dir=None):
230 """Uprev the given overlays.
231
232 Args:
233 overlays (list[str]): The list of overlay paths.
234 build_targets (list[build_target_util.BuildTarget]|None): The build targets
235 to clean in |chroot|, if desired. No effect unless |chroot| is provided.
236 chroot (chroot_lib.Chroot|None): The chroot to clean, if desired.
237 output_dir (str|None): The path to optionally dump result files.
238
239 Returns:
240 list[str] - The paths to all of the modified ebuild files. This includes the
241 new files that were added (i.e. the new versions) and all of the removed
242 files (i.e. the old versions).
243 """
244 assert overlays
245
246 manifest = git.ManifestCheckout.Cached(constants.SOURCE_ROOT)
247
Alex Kleind6195b62019-08-06 16:01:16 -0600248 uprev_manager = uprev_lib.UprevOverlayManager(overlays, manifest,
249 build_targets=build_targets,
250 chroot=chroot,
251 output_dir=output_dir)
Alex Kleineb77ffa2019-05-28 14:47:44 -0600252 uprev_manager.uprev()
253
254 return uprev_manager.modified_ebuilds
255
256
Alex Klein87531182019-08-12 15:23:37 -0600257def uprev_versioned_package(package, build_targets, refs, chroot):
258 """Call registered uprev handler function for the package.
259
260 Args:
261 package (portage_util.CPV): The package being uprevved.
262 build_targets (list[build_target_util.BuildTarget]): The build targets to
263 clean on a successful uprev.
264 refs (list[uprev_lib.GitRef]):
265 chroot (chroot_lib.Chroot): The chroot to enter for cleaning.
266
267 Returns:
Alex Klein34afcbc2019-08-22 16:14:31 -0600268 UprevVersionedPackageResult: The result.
Alex Klein87531182019-08-12 15:23:37 -0600269 """
270 assert package
271
272 if package.cp not in _UPREV_FUNCS:
273 raise UnknownPackageError(
274 'Package "%s" does not have a registered handler.' % package.cp)
275
276 return _UPREV_FUNCS[package.cp](build_targets, refs, chroot)
277
278
Evan Hernandezb51f1522019-08-15 11:29:40 -0600279# TODO(evanhernandez): Remove this. Only a quick hack for testing.
280@uprevs_versioned_package('sample/sample')
281def uprev_sample(*_args, **_kwargs):
282 """Mimics an uprev by changing files in sandbox repos.
283
284 See: uprev_versioned_package.
285 """
286 paths = [
287 os.path.join(constants.SOURCE_ROOT, 'infra/dummies', repo, 'sample.txt')
288 for repo in ('general-sandbox', 'merge-sandbox')
289 ]
290
Yaakov Shaul730814a2019-09-10 13:58:25 -0600291 return UprevVersionedPackageResult().add_result('1.2.3', paths)
Evan Hernandezb51f1522019-08-15 11:29:40 -0600292
293
Yaakov Shaul395ae832019-09-09 14:45:32 -0600294@uprevs_versioned_package('afdo/kernel-profiles')
295def uprev_kernel_afdo(*_args, **_kwargs):
David Burger92485342019-09-10 17:52:45 -0600296 """Updates kernel ebuilds with versions from kernel_afdo.json.
Yaakov Shaul395ae832019-09-09 14:45:32 -0600297
298 See: uprev_versioned_package.
Yaakov Shaul1eafe832019-09-10 16:50:26 -0600299
300 Raises:
301 EbuildManifestError: When ebuild manifest does not complete successfuly.
Yaakov Shaul395ae832019-09-09 14:45:32 -0600302 """
303 path = os.path.join(constants.SOURCE_ROOT, 'src', 'third_party',
304 'toolchain-utils', 'afdo_metadata', 'kernel_afdo.json')
305
David Burger92485342019-09-10 17:52:45 -0600306 with open(path, 'r') as f:
307 versions = json.load(f)
Yaakov Shaul395ae832019-09-09 14:45:32 -0600308
Yaakov Shaul730814a2019-09-10 13:58:25 -0600309 result = UprevVersionedPackageResult()
Yaakov Shaul395ae832019-09-09 14:45:32 -0600310 for version, version_info in versions.items():
Yaakov Shauldd8b4112019-09-11 11:44:03 -0600311 path = os.path.join('src', 'third_party', 'chromiumos-overlay',
312 'sys-kernel', version)
313 ebuild_path = os.path.join(constants.SOURCE_ROOT, path,
314 '%s-9999.ebuild' % version)
Yaakov Shaula187b152019-09-11 12:41:32 -0600315 chroot_ebuild_path = os.path.join(constants.CHROOT_SOURCE_ROOT, path,
316 '%s-9999.ebuild' % version)
Yaakov Shaul730814a2019-09-10 13:58:25 -0600317 afdo_profile_version = version_info['name']
Yaakov Shaulcb1cfc32019-09-16 13:51:19 -0600318 patch_ebuild_vars(ebuild_path,
319 dict(AFDO_PROFILE_VERSION=afdo_profile_version))
Yaakov Shaul1eafe832019-09-10 16:50:26 -0600320
321 try:
Yaakov Shaul730814a2019-09-10 13:58:25 -0600322 cmd = ['ebuild', chroot_ebuild_path, 'manifest', '--force']
Mike Frysinger45602c72019-09-22 02:15:11 -0400323 cros_build_lib.run(cmd, enter_chroot=True)
Yaakov Shaul1eafe832019-09-10 16:50:26 -0600324 except cros_build_lib.RunCommandError as e:
325 raise EbuildManifestError(
326 'Error encountered when regenerating the manifest for ebuild: %s\n%s'
Yaakov Shaula187b152019-09-11 12:41:32 -0600327 % (chroot_ebuild_path, e), e)
Yaakov Shaul1eafe832019-09-10 16:50:26 -0600328
Yaakov Shauldd8b4112019-09-11 11:44:03 -0600329 manifest_path = os.path.join(constants.SOURCE_ROOT, path, 'Manifest')
Yaakov Shaul1eafe832019-09-10 16:50:26 -0600330
Yaakov Shaul730814a2019-09-10 13:58:25 -0600331 result.add_result(afdo_profile_version, [ebuild_path, manifest_path])
332
333 return result
Yaakov Shaul395ae832019-09-09 14:45:32 -0600334
335
Alex Klein87531182019-08-12 15:23:37 -0600336@uprevs_versioned_package(constants.CHROME_CP)
337def uprev_chrome(build_targets, refs, chroot):
338 """Uprev chrome and its related packages.
339
340 See: uprev_versioned_package.
341 """
342 # Determine the version from the refs (tags), i.e. the chrome versions are the
343 # tag names.
344 chrome_version = uprev_lib.get_chrome_version_from_refs(refs)
345
346 uprev_manager = uprev_lib.UprevChromeManager(
347 chrome_version, build_targets=build_targets, chroot=chroot)
David Burger37f48672019-09-18 17:07:56 -0600348 result = UprevVersionedPackageResult()
Alex Klein87531182019-08-12 15:23:37 -0600349 # Start with chrome itself, as we can't do anything else unless chrome
350 # uprevs successfully.
351 if not uprev_manager.uprev(constants.CHROME_CP):
David Burger37f48672019-09-18 17:07:56 -0600352 return result
Alex Klein87531182019-08-12 15:23:37 -0600353
354 # With a successful chrome rev, also uprev related packages.
355 for package in constants.OTHER_CHROME_PACKAGES:
356 uprev_manager.uprev(package)
357
David Burger37f48672019-09-18 17:07:56 -0600358 return result.add_result(chrome_version, uprev_manager.modified_ebuilds)
Alex Klein87531182019-08-12 15:23:37 -0600359
360
Alex Kleinbbef2b32019-08-27 10:38:50 -0600361def get_best_visible(atom, build_target=None):
362 """Returns the best visible CPV for the given atom.
363
364 Args:
365 atom (str): The atom to look up.
366 build_target (build_target_util.BuildTarget): The build target whose
Alex Kleinda39c6d2019-09-16 14:36:36 -0600367 sysroot should be searched, or the SDK if not provided.
Alex Kleinbbef2b32019-08-27 10:38:50 -0600368 """
David Burger1e0fe232019-07-01 14:52:07 -0600369 assert atom
Alex Kleinbbef2b32019-08-27 10:38:50 -0600370
371 board = build_target.name if build_target else None
372 return portage_util.PortageqBestVisible(atom, board=board)
Alex Kleinda39c6d2019-09-16 14:36:36 -0600373
374
375def has_prebuilt(atom, build_target=None):
376 """Check if a prebuilt exists.
377
378 Args:
379 atom (str): The package whose prebuilt is being queried.
380 build_target (build_target_util.BuildTarget): The build target whose
381 sysroot should be searched, or the SDK if not provided.
382 """
383 assert atom
384
385 board = build_target.name if build_target else None
386 return portage_util.HasPrebuilt(atom, board=board)
Alex Klein36b117f2019-09-30 15:13:46 -0600387
388
David Burger0f9dd4e2019-10-08 12:33:42 -0600389def builds(atom, build_target, packages=None):
Alex Klein36b117f2019-09-30 15:13:46 -0600390 """Check if |build_target| builds |atom| (has it in its depgraph)."""
391 cros_build_lib.AssertInsideChroot()
392
David Burger0f9dd4e2019-10-08 12:33:42 -0600393 graph = dependency.GetBuildDependency(build_target.name, packages)
Alex Klein36b117f2019-09-30 15:13:46 -0600394 return any(atom in package for package in graph['package_deps'])
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600395
396
Michael Mortensenb51a1f02019-10-16 13:28:20 -0600397def determine_chrome_version(build_target):
Michael Mortensenc2615b72019-10-15 08:12:24 -0600398 """Returns the current Chrome version for the board (or in buildroot).
399
400 Args:
Michael Mortensenb51a1f02019-10-16 13:28:20 -0600401 build_target (build_target_util.BuildTarget): The board build target.
Michael Mortensenc2615b72019-10-15 08:12:24 -0600402 """
Michael Mortensen9fe740c2019-10-29 14:42:48 -0600403 # TODO(crbug/1019770): Long term we should not need the try/catch here once
404 # the builds function above only returns True for chrome when
405 # determine_chrome_version will succeed.
406 try:
407 cpv = portage_util.PortageqBestVisible(constants.CHROME_CP,
408 build_target.name,
409 cwd=constants.SOURCE_ROOT)
410 except cros_build_lib.RunCommandError as e:
411 # Return None because portage failed when trying to determine the chrome
412 # version.
413 logging.warning('Caught exception in determine_chrome_package: %s', e)
414 return None
Michael Mortensenc2615b72019-10-15 08:12:24 -0600415 # Something like 78.0.3877.4_rc -> 78.0.3877.4
416 return cpv.version_no_rev.partition('_')[0]
417
418
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600419def determine_android_package(board):
420 """Returns the active Android container package in use by the board.
421
422 Args:
423 board: The board name this is specific to.
424 """
Michael Mortensene0f4b542019-10-24 15:30:23 -0600425 try:
426 packages = portage_util.GetPackageDependencies(board, 'virtual/target-os')
427 # We assume there is only one Android package in the depgraph.
428 for package in packages:
429 if package.startswith('chromeos-base/android-container-') or \
430 package.startswith('chromeos-base/android-vm-'):
431 return package
432 return None
433 except cros_build_lib.RunCommandError as e:
434 # Return None because a command (likely portage) failed when trying to
435 # determine the package.
436 logging.warning('Caught exception in determine_android_package: %s', e)
437 return None
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600438
439
440def determine_android_version(boards=None):
441 """Determine the current Android version in buildroot now and return it.
442
443 This uses the typical portage logic to determine which version of Android
444 is active right now in the buildroot.
445
446 Args:
447 boards: List of boards to check version of.
448
449 Returns:
450 The Android build ID of the container for the boards.
451
452 Raises:
453 NoAndroidVersionError: if no unique Android version can be determined.
454 """
455 if not boards:
456 return None
457 # Verify that all boards have the same version.
458 version = None
459 for board in boards:
460 package = determine_android_package(board)
461 if not package:
Michael Mortensenedf76532019-10-16 14:22:37 -0600462 return None
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600463 cpv = portage_util.SplitCPV(package)
464 if not cpv:
465 raise NoAndroidVersionError(
466 'Android version could not be determined for %s' % board)
467 if not version:
468 version = cpv.version_no_rev
469 elif version != cpv.version_no_rev:
470 raise NoAndroidVersionError(
471 'Different Android versions (%s vs %s) for %s' %
472 (version, cpv.version_no_rev, boards))
473 return version
474
475def determine_android_branch(board):
476 """Returns the Android branch in use by the active container ebuild."""
477 try:
478 android_package = determine_android_package(board)
479 except cros_build_lib.RunCommandError:
480 raise NoAndroidBranchError(
481 'Android branch could not be determined for %s' % board)
482 if not android_package:
Michael Mortensenedf76532019-10-16 14:22:37 -0600483 return None
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600484 ebuild_path = portage_util.FindEbuildForBoardPackage(android_package, board)
485 # We assume all targets pull from the same branch and that we always
486 # have an ARM_TARGET, ARM_USERDEBUG_TARGET, or an X86_USERDEBUG_TARGET.
487 targets = ['ARM_TARGET', 'ARM_USERDEBUG_TARGET', 'X86_USERDEBUG_TARGET']
488 ebuild_content = osutils.SourceEnvironment(ebuild_path, targets)
489 for target in targets:
490 if target in ebuild_content:
491 branch = re.search(r'(.*?)-linux-', ebuild_content[target])
492 if branch is not None:
493 return branch.group(1)
494 raise NoAndroidBranchError(
495 'Android branch could not be determined for %s (ebuild empty?)' % board)
496
497
498def determine_android_target(board):
Michael Mortensen14960d02019-10-18 07:53:59 -0600499 """Returns the Android target in use by the active container ebuild."""
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600500 try:
501 android_package = determine_android_package(board)
502 except cros_build_lib.RunCommandError:
503 raise NoAndroidTargetError(
504 'Android Target could not be determined for %s' % board)
505 if not android_package:
Michael Mortensenedf76532019-10-16 14:22:37 -0600506 return None
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600507 if android_package.startswith('chromeos-base/android-vm-'):
508 return 'bertha'
509 elif android_package.startswith('chromeos-base/android-container-'):
510 return 'cheets'
511
512 raise NoAndroidTargetError(
513 'Android Target cannot be determined for the package: %s' %
514 android_package)
Michael Mortensen9fdb14b2019-10-17 11:17:30 -0600515
516
517def determine_platform_version():
518 """Returns the platform version from the source root."""
Michael Mortensen009cb662019-10-21 11:38:43 -0600519 # Platform version is something like '12575.0.0'.
Michael Mortensen9fdb14b2019-10-17 11:17:30 -0600520 version = manifest_version.VersionInfo.from_repo(constants.SOURCE_ROOT)
521 return version.VersionString()
Michael Mortensen009cb662019-10-21 11:38:43 -0600522
523
524def determine_milestone_version():
525 """Returns the platform version from the source root."""
526 # Milestone version is something like '79'.
527 version = manifest_version.VersionInfo.from_repo(constants.SOURCE_ROOT)
528 return version.chrome_branch
529
530def determine_full_version():
531 """Returns the full version from the source root."""
532 # Full version is something like 'R79-12575.0.0'.
533 milestone_version = determine_milestone_version()
534 platform_version = determine_platform_version()
535 full_version = ('R%s-%s' % (milestone_version, platform_version))
536 return full_version