Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2015 The ChromiumOS Authors |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Utility for setting the /etc/lsb-release file of an image.""" |
| 6 | |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 7 | import getpass |
| 8 | import os |
| 9 | |
| 10 | from chromite.lib import commandline |
| 11 | from chromite.lib import cros_build_lib |
| 12 | from chromite.lib import image_lib |
Anuj Jamwal | 258529f | 2023-09-08 17:32:55 +0000 | [diff] [blame^] | 13 | from chromite.utils import hostname_util |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 14 | |
| 15 | |
| 16 | # LSB keys: |
| 17 | # Set google-specific version numbers: |
| 18 | # CHROMEOS_RELEASE_BOARD is the target board identifier. |
| 19 | # CHROMEOS_RELEASE_BRANCH_NUMBER is the Chrome OS branch number |
| 20 | # CHROMEOS_RELEASE_BUILD_NUMBER is the Chrome OS build number |
| 21 | # CHROMEOS_RELEASE_BUILD_TYPE is the type of build (official, from developers, |
| 22 | # etc..) |
| 23 | # CHROMEOS_RELEASE_CHROME_MILESTONE is the Chrome milestone (also named Chrome |
| 24 | # branch). |
| 25 | # CHROMEOS_RELEASE_DESCRIPTION is the version displayed by Chrome; see |
| 26 | # chrome/browser/chromeos/chromeos_version_loader.cc. |
| 27 | # CHROMEOS_RELEASE_NAME is a human readable name for the build. |
| 28 | # CHROMEOS_RELEASE_PATCH_NUMBER is the patch number for the current branch. |
| 29 | # CHROMEOS_RELEASE_TRACK and CHROMEOS_RELEASE_VERSION are used by the software |
| 30 | # update service. |
Mike Frysinger | a073635 | 2018-09-10 16:34:37 -0400 | [diff] [blame] | 31 | # CHROMEOS_RELEASE_KEYSET is the named of the keyset used to sign this build. |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 32 | # TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at |
| 33 | # CHROMEOS_RELEASE_VERSION for UserAgent data. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 34 | LSB_KEY_NAME = "CHROMEOS_RELEASE_NAME" |
| 35 | LSB_KEY_AUSERVER = "CHROMEOS_AUSERVER" |
| 36 | LSB_KEY_DEVSERVER = "CHROMEOS_DEVSERVER" |
| 37 | LSB_KEY_TRACK = "CHROMEOS_RELEASE_TRACK" |
| 38 | LSB_KEY_BUILD_TYPE = "CHROMEOS_RELEASE_BUILD_TYPE" |
| 39 | LSB_KEY_DESCRIPTION = "CHROMEOS_RELEASE_DESCRIPTION" |
| 40 | LSB_KEY_BOARD = "CHROMEOS_RELEASE_BOARD" |
| 41 | LSB_KEY_KEYSET = "CHROMEOS_RELEASE_KEYSET" |
| 42 | LSB_KEY_UNIBUILD = "CHROMEOS_RELEASE_UNIBUILD" |
| 43 | LSB_KEY_BRANCH_NUMBER = "CHROMEOS_RELEASE_BRANCH_NUMBER" |
| 44 | LSB_KEY_BUILD_NUMBER = "CHROMEOS_RELEASE_BUILD_NUMBER" |
| 45 | LSB_KEY_CHROME_MILESTONE = "CHROMEOS_RELEASE_CHROME_MILESTONE" |
| 46 | LSB_KEY_PATCH_NUMBER = "CHROMEOS_RELEASE_PATCH_NUMBER" |
| 47 | LSB_KEY_VERSION = "CHROMEOS_RELEASE_VERSION" |
| 48 | LSB_KEY_BUILDER_PATH = "CHROMEOS_RELEASE_BUILDER_PATH" |
| 49 | LSB_KEY_GOOGLE_RELEASE = "GOOGLE_RELEASE" |
| 50 | LSB_KEY_APPID_RELEASE = "CHROMEOS_RELEASE_APPID" |
| 51 | LSB_KEY_APPID_BOARD = "CHROMEOS_BOARD_APPID" |
| 52 | LSB_KEY_APPID_CANARY = "CHROMEOS_CANARY_APPID" |
| 53 | LSB_KEY_ARC_VERSION = "CHROMEOS_ARC_VERSION" |
| 54 | LSB_KEY_ARC_ANDROID_SDK_VERSION = "CHROMEOS_ARC_ANDROID_SDK_VERSION" |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 55 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 56 | CANARY_APP_ID = "{90F229CE-83E2-4FAF-8479-E368A34938B1}" |
| 57 | |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 58 | |
| 59 | def _ParseArguments(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 60 | parser = commandline.ArgumentParser(description=__doc__) |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 61 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 62 | parser.add_argument("--app_id", default=None, help="The APP_ID to install.") |
| 63 | parser.add_argument("--board", help="The board name.", required=True) |
| 64 | parser.add_argument( |
| 65 | "--unibuild", |
| 66 | action="store_true", |
| 67 | default=False, |
| 68 | help="Set if board has chromeos-config.", |
| 69 | ) |
| 70 | parser.add_argument( |
| 71 | "--sysroot", |
| 72 | required=True, |
| 73 | type="path", |
| 74 | help="The sysroot to install the lsb-release file into.", |
| 75 | ) |
| 76 | parser.add_argument( |
| 77 | "--version_string", required=True, help="The image's version string." |
| 78 | ) |
| 79 | parser.add_argument( |
| 80 | "--builder_path", default=None, help="The image's builder path." |
| 81 | ) |
| 82 | parser.add_argument( |
| 83 | "--auserver", default=None, help="The auserver url to use." |
| 84 | ) |
| 85 | parser.add_argument( |
| 86 | "--devserver", default=None, help="The devserver url to use." |
| 87 | ) |
| 88 | parser.add_argument( |
| 89 | "--official", |
| 90 | action="store_true", |
| 91 | help="Whether or not to populate with fields for an " "official image.", |
| 92 | ) |
| 93 | parser.add_argument( |
| 94 | "--keyset", help="The keyset name used to sign this image." |
| 95 | ) |
| 96 | parser.add_argument( |
| 97 | "--buildbot_build", |
| 98 | default="N/A", |
| 99 | help="The build number, for use with the continuous " "builder.", |
| 100 | ) |
| 101 | parser.add_argument( |
| 102 | "--track", default="developer-build", help="The type of release track." |
| 103 | ) |
| 104 | parser.add_argument( |
| 105 | "--branch_number", default="0", help="The branch number." |
| 106 | ) |
| 107 | parser.add_argument("--build_number", default="0", help="The build number.") |
| 108 | parser.add_argument( |
| 109 | "--chrome_milestone", default="0", help="The Chrome milestone." |
| 110 | ) |
| 111 | parser.add_argument( |
| 112 | "--patch_number", |
| 113 | default="0", |
| 114 | help="The patch number for the given branch.", |
| 115 | ) |
| 116 | parser.add_argument( |
| 117 | "--arc_version", default=None, help="Android revision number of ARC." |
| 118 | ) |
| 119 | parser.add_argument( |
| 120 | "--arc_android_sdk_version", |
| 121 | default=None, |
| 122 | help="Android SDK version of ARC.", |
| 123 | ) |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 124 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 125 | opts = parser.parse_args(argv) |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 126 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 127 | # If the auserver or devserver isn't specified or is set to blank, set it |
| 128 | # to the host's hostname. |
Anuj Jamwal | 258529f | 2023-09-08 17:32:55 +0000 | [diff] [blame^] | 129 | hostname = hostname_util.get_host_name(fully_qualified=True) |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 130 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 131 | if not opts.auserver: |
| 132 | opts.auserver = "http://%s:8080/update" % hostname |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 133 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 134 | if not opts.devserver: |
| 135 | opts.devserver = "http://%s:8080" % hostname |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 136 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 137 | opts.Freeze() |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 138 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 139 | if not os.path.isdir(opts.sysroot): |
| 140 | cros_build_lib.Die( |
| 141 | "The target sysroot does not exist: %s" % opts.sysroot |
| 142 | ) |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 143 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 144 | if not opts.version_string: |
| 145 | cros_build_lib.Die( |
| 146 | "version_string must not be empty. Was " |
| 147 | "chromeos_version.sh sourced correctly in the calling " |
| 148 | "script?" |
| 149 | ) |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 150 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 151 | return opts |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 152 | |
| 153 | |
| 154 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 155 | opts = _ParseArguments(argv) |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 156 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 157 | fields = { |
| 158 | LSB_KEY_NAME: "Chromium OS", |
| 159 | LSB_KEY_AUSERVER: opts.auserver, |
| 160 | LSB_KEY_DEVSERVER: opts.devserver, |
| 161 | } |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 162 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 163 | if opts.app_id is not None: |
| 164 | fields.update( |
| 165 | { |
| 166 | LSB_KEY_APPID_RELEASE: opts.app_id, |
| 167 | LSB_KEY_APPID_BOARD: opts.app_id, |
| 168 | LSB_KEY_APPID_CANARY: CANARY_APP_ID, |
| 169 | } |
| 170 | ) |
Steve Fung | 977460a | 2015-05-31 23:25:33 -0700 | [diff] [blame] | 171 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 172 | if opts.arc_version is not None: |
| 173 | fields.update( |
| 174 | { |
| 175 | LSB_KEY_ARC_VERSION: opts.arc_version, |
| 176 | } |
| 177 | ) |
Elijah Taylor | e9e3a82 | 2016-03-29 16:55:16 -0700 | [diff] [blame] | 178 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 179 | if opts.arc_android_sdk_version is not None: |
| 180 | fields.update( |
| 181 | { |
| 182 | LSB_KEY_ARC_ANDROID_SDK_VERSION: opts.arc_android_sdk_version, |
| 183 | } |
| 184 | ) |
Shuhei Takahashi | 50fd9e7 | 2017-01-27 16:00:34 +0900 | [diff] [blame] | 185 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 186 | if opts.builder_path is not None: |
| 187 | fields.update( |
| 188 | { |
| 189 | LSB_KEY_BUILDER_PATH: opts.builder_path, |
| 190 | } |
| 191 | ) |
xixuan | 745999f | 2016-08-03 19:20:30 -0700 | [diff] [blame] | 192 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 193 | if opts.keyset is not None: |
| 194 | fields.update( |
| 195 | { |
| 196 | LSB_KEY_KEYSET: opts.keyset, |
| 197 | } |
| 198 | ) |
Mike Frysinger | a073635 | 2018-09-10 16:34:37 -0400 | [diff] [blame] | 199 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 200 | board = opts.board |
| 201 | if opts.official: |
| 202 | # Official builds (i.e. buildbot). |
| 203 | track = "dev-channel" |
| 204 | build_type = "Official Build" |
| 205 | fields.update( |
| 206 | { |
| 207 | LSB_KEY_TRACK: track, |
| 208 | LSB_KEY_NAME: "Chrome OS", |
| 209 | LSB_KEY_BUILD_TYPE: build_type, |
| 210 | LSB_KEY_DESCRIPTION: ( |
| 211 | "%s (%s) %s %s test" |
| 212 | % (opts.version_string, build_type, track, board) |
| 213 | ), |
| 214 | LSB_KEY_AUSERVER: "https://tools.google.com/service/update2", |
| 215 | LSB_KEY_DEVSERVER: "", |
| 216 | } |
| 217 | ) |
| 218 | elif getpass.getuser() == "chrome-bot": |
| 219 | # Continuous builder. |
| 220 | build_type = "Continuous Builder - Builder: %s" % opts.buildbot_build |
| 221 | fields.update( |
| 222 | { |
| 223 | LSB_KEY_TRACK: "buildbot-build", |
| 224 | LSB_KEY_BUILD_TYPE: build_type, |
| 225 | LSB_KEY_DESCRIPTION: "%s (%s) %s" |
| 226 | % (opts.version_string, build_type, board), |
| 227 | } |
| 228 | ) |
| 229 | else: |
| 230 | # Developer manual builds. |
| 231 | build_type = "Developer Build - %s" % getpass.getuser() |
| 232 | fields.update( |
| 233 | { |
| 234 | LSB_KEY_TRACK: opts.track, |
| 235 | LSB_KEY_BUILD_TYPE: build_type, |
| 236 | LSB_KEY_DESCRIPTION: "%s (%s) %s %s" |
| 237 | % (opts.version_string, build_type, opts.track, board), |
| 238 | } |
| 239 | ) |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 240 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 241 | fields.update( |
| 242 | { |
| 243 | LSB_KEY_BOARD: opts.board, |
| 244 | LSB_KEY_BRANCH_NUMBER: opts.branch_number, |
| 245 | LSB_KEY_BUILD_NUMBER: opts.build_number, |
| 246 | LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone, |
| 247 | LSB_KEY_PATCH_NUMBER: opts.patch_number, |
| 248 | LSB_KEY_VERSION: opts.version_string, |
| 249 | LSB_KEY_GOOGLE_RELEASE: opts.version_string, |
| 250 | } |
| 251 | ) |
| 252 | if opts.unibuild: |
| 253 | fields[LSB_KEY_UNIBUILD] = "1" |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 254 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 255 | image_lib.WriteLsbRelease(opts.sysroot, fields) |