Tatsuhisa Yamaguchi | d30a969 | 2023-08-17 19:48:43 +0900 | [diff] [blame] | 1 | # Copyright 2023 The ChromiumOS Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Handles ChromeOS LKGM image version detection.""" |
| 6 | |
| 7 | import os |
| 8 | |
| 9 | from chromite.api import faux |
| 10 | from chromite.api import validate |
| 11 | from chromite.lib import chrome_lkgm |
| 12 | from chromite.lib import path_util |
| 13 | |
| 14 | |
| 15 | def _find_lkgm_success(_input_proto, output_proto, _config_proto): |
| 16 | """Mock for a success case.""" |
| 17 | output_proto.config_name = "boardname-release" |
| 18 | output_proto.full_version = "111.0.0.5678" |
| 19 | output_proto.chromeos_lkgm = "111.0.0.5679" |
| 20 | |
| 21 | |
| 22 | def _find_lkgm_error(_input_proto, output_proto, _config_proto): |
| 23 | """Mock for a failed case.""" |
| 24 | output_proto.error = "something went wrong" |
| 25 | |
| 26 | |
| 27 | @faux.success(_find_lkgm_success) |
| 28 | @faux.error(_find_lkgm_error) |
| 29 | @validate.require("build_target") |
| 30 | @validate.require("fallback_versions") |
| 31 | @validate.validation_complete |
| 32 | def FindLkgm(input_proto, output_proto, _config_proto): |
| 33 | """Find LKGM or older version of image for a board.""" |
| 34 | checkout = path_util.DetermineCheckout( |
| 35 | input_proto.chrome_src or os.getcwd() |
| 36 | ) |
| 37 | |
| 38 | f = chrome_lkgm.ChromeOSVersionFinder( |
| 39 | input_proto.cache_dir or None, |
| 40 | input_proto.build_target.name, |
| 41 | fallback_versions=input_proto.fallback_versions, |
| 42 | chrome_src=input_proto.chrome_src, |
| 43 | use_external_config=input_proto.use_external_config, |
| 44 | ) |
| 45 | output_proto.config_name = f.config_name |
| 46 | |
| 47 | try: |
| 48 | lkgm_version = chrome_lkgm.GetChromeLkgm(input_proto.chrome_src) |
| 49 | except FileNotFoundError as e: |
| 50 | output_proto.error = str(e) |
| 51 | return |
| 52 | |
| 53 | if not lkgm_version: |
| 54 | output_proto.error = str( |
| 55 | chrome_lkgm.MissingLkgmFile(checkout.chrome_src_dir) |
| 56 | ) |
| 57 | return |
| 58 | |
| 59 | output_proto.chromeos_lkgm = lkgm_version |
| 60 | full_version = f.GetFullVersionFromLatest(lkgm_version) |
| 61 | if not full_version: |
| 62 | output_proto.error = "failed to get full version" |
| 63 | return |
| 64 | output_proto.full_version = full_version |