Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 1 | # Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 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 | |
| 7 | from __future__ import print_function |
| 8 | |
| 9 | import getpass |
| 10 | import os |
| 11 | |
| 12 | from chromite.lib import commandline |
| 13 | from chromite.lib import cros_build_lib |
| 14 | from chromite.lib import image_lib |
| 15 | |
| 16 | |
| 17 | # LSB keys: |
| 18 | # Set google-specific version numbers: |
| 19 | # CHROMEOS_RELEASE_BOARD is the target board identifier. |
| 20 | # CHROMEOS_RELEASE_BRANCH_NUMBER is the Chrome OS branch number |
| 21 | # CHROMEOS_RELEASE_BUILD_NUMBER is the Chrome OS build number |
| 22 | # CHROMEOS_RELEASE_BUILD_TYPE is the type of build (official, from developers, |
| 23 | # etc..) |
| 24 | # CHROMEOS_RELEASE_CHROME_MILESTONE is the Chrome milestone (also named Chrome |
| 25 | # branch). |
| 26 | # CHROMEOS_RELEASE_DESCRIPTION is the version displayed by Chrome; see |
| 27 | # chrome/browser/chromeos/chromeos_version_loader.cc. |
| 28 | # CHROMEOS_RELEASE_NAME is a human readable name for the build. |
| 29 | # CHROMEOS_RELEASE_PATCH_NUMBER is the patch number for the current branch. |
| 30 | # CHROMEOS_RELEASE_TRACK and CHROMEOS_RELEASE_VERSION are used by the software |
| 31 | # update service. |
| 32 | # TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at |
| 33 | # CHROMEOS_RELEASE_VERSION for UserAgent data. |
| 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_BRANCH_NUMBER = 'CHROMEOS_RELEASE_BRANCH_NUMBER' |
| 42 | LSB_KEY_BUILD_NUMBER = 'CHROMEOS_RELEASE_BUILD_NUMBER' |
| 43 | LSB_KEY_CHROME_MILESTONE = 'CHROMEOS_RELEASE_CHROME_MILESTONE' |
| 44 | LSB_KEY_PATCH_NUMBER = 'CHROMEOS_RELEASE_PATCH_NUMBER' |
| 45 | LSB_KEY_VERSION = 'CHROMEOS_RELEASE_VERSION' |
| 46 | LSB_KEY_GOOGLE_RELEASE = 'GOOGLE_RELEASE' |
Steve Fung | 977460a | 2015-05-31 23:25:33 -0700 | [diff] [blame] | 47 | LSB_KEY_APPID_RELEASE = 'CHROMEOS_RELEASE_APPID' |
| 48 | LSB_KEY_APPID_BOARD = 'CHROMEOS_BOARD_APPID' |
| 49 | LSB_KEY_APPID_CANARY = 'CHROMEOS_CANARY_APPID' |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 50 | |
Steve Fung | 977460a | 2015-05-31 23:25:33 -0700 | [diff] [blame] | 51 | CANARY_APP_ID = "{90F229CE-83E2-4FAF-8479-E368A34938B1}" |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 52 | |
| 53 | def _ParseArguments(argv): |
| 54 | parser = commandline.ArgumentParser(description=__doc__) |
| 55 | |
Steve Fung | 977460a | 2015-05-31 23:25:33 -0700 | [diff] [blame] | 56 | parser.add_argument('--app_id', default=None, |
| 57 | help='The APP_ID to install.') |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 58 | parser.add_argument('--board', help='The board name.', required=True) |
| 59 | parser.add_argument('--sysroot', required=True, type='path', |
| 60 | help='The sysroot to install the lsb-release file into.') |
| 61 | parser.add_argument('--version_string', required=True, |
| 62 | help='The image\'s version string.') |
| 63 | parser.add_argument('--auserver', default=None, |
| 64 | help='The auserver url to use.') |
| 65 | parser.add_argument('--devserver', default=None, |
| 66 | help='The devserver url to use.') |
| 67 | parser.add_argument('--official', action='store_true', |
| 68 | help='Whether or not to populate with fields for an ' |
| 69 | 'official image.') |
| 70 | parser.add_argument('--buildbot_build', default='N/A', |
| 71 | help='The build number, for use with the continuous ' |
| 72 | 'builder.') |
| 73 | parser.add_argument('--track', default='developer-build', |
| 74 | help='The type of release track.') |
| 75 | parser.add_argument('--branch_number', default='0', |
| 76 | help='The branch number.') |
| 77 | parser.add_argument('--build_number', default='0', |
| 78 | help='The build number.') |
| 79 | parser.add_argument('--chrome_milestone', default='0', |
| 80 | help='The Chrome milestone.') |
| 81 | parser.add_argument('--patch_number', default='0', |
| 82 | help='The patch number for the given branch.') |
| 83 | |
| 84 | opts = parser.parse_args(argv) |
| 85 | |
| 86 | # If the auserver or devserver isn't specified or is set to blank, set it |
| 87 | # to the host's hostname. |
| 88 | hostname = cros_build_lib.GetHostName(fully_qualified=True) |
| 89 | |
| 90 | if not opts.auserver: |
| 91 | opts.auserver = 'http://%s:8080/update' % hostname |
| 92 | |
| 93 | if not opts.devserver: |
| 94 | opts.devserver = 'http://%s:8080' % hostname |
| 95 | |
| 96 | opts.Freeze() |
| 97 | |
| 98 | if not os.path.isdir(opts.sysroot): |
| 99 | cros_build_lib.Die('The target sysroot does not exist: %s' % opts.sysroot) |
| 100 | |
| 101 | if not opts.version_string: |
| 102 | cros_build_lib.Die('version_string must not be empty. Was ' |
| 103 | 'chromeos_version.sh sourced correctly in the calling ' |
| 104 | 'script?') |
| 105 | |
| 106 | return opts |
| 107 | |
| 108 | |
| 109 | def main(argv): |
| 110 | opts = _ParseArguments(argv) |
| 111 | |
| 112 | fields = { |
| 113 | LSB_KEY_NAME: 'Chromium OS', |
| 114 | LSB_KEY_AUSERVER: opts.auserver, |
| 115 | LSB_KEY_DEVSERVER: opts.devserver, |
| 116 | } |
| 117 | |
Steve Fung | 977460a | 2015-05-31 23:25:33 -0700 | [diff] [blame] | 118 | if opts.app_id is not None: |
| 119 | fields.update({ |
| 120 | LSB_KEY_APPID_RELEASE: opts.app_id, |
| 121 | LSB_KEY_APPID_BOARD: opts.app_id, |
| 122 | LSB_KEY_APPID_CANARY: CANARY_APP_ID, |
| 123 | }) |
| 124 | |
Steve Fung | 67ef946 | 2015-05-21 03:37:06 -0700 | [diff] [blame] | 125 | if opts.official: |
| 126 | # Official builds (i.e. buildbot). |
| 127 | track = 'dev-channel' |
| 128 | build_type = 'Official Build' |
| 129 | fields.update({ |
| 130 | LSB_KEY_TRACK: track, |
| 131 | LSB_KEY_NAME: 'Chrome OS', |
| 132 | LSB_KEY_BUILD_TYPE: build_type, |
| 133 | LSB_KEY_DESCRIPTION: ('%s (%s) %s %s test' % |
| 134 | (opts.version_string, |
| 135 | build_type, |
| 136 | track, |
| 137 | opts.board)), |
| 138 | LSB_KEY_AUSERVER: 'https://tools.google.com/service/update2', |
| 139 | LSB_KEY_DEVSERVER: '', |
| 140 | }) |
| 141 | elif getpass.getuser() == 'chrome-bot': |
| 142 | # Continuous builder. |
| 143 | build_type = 'Continuous Builder - Builder: %s' % opts.buildbot_build |
| 144 | fields.update({ |
| 145 | LSB_KEY_TRACK: 'buildbot-build', |
| 146 | LSB_KEY_BUILD_TYPE: build_type, |
| 147 | LSB_KEY_DESCRIPTION: '%s (%s) %s' % (opts.version_string, |
| 148 | build_type, |
| 149 | opts.board), |
| 150 | }) |
| 151 | else: |
| 152 | # Developer manual builds. |
| 153 | build_type = 'Developer Build - %s' % getpass.getuser() |
| 154 | fields.update({ |
| 155 | LSB_KEY_TRACK: opts.track, |
| 156 | LSB_KEY_BUILD_TYPE: build_type, |
| 157 | LSB_KEY_DESCRIPTION: '%s (%s) %s %s' % (opts.version_string, |
| 158 | build_type, |
| 159 | opts.track, |
| 160 | opts.board), |
| 161 | }) |
| 162 | |
| 163 | fields.update({ |
| 164 | LSB_KEY_BOARD: opts.board, |
| 165 | LSB_KEY_BRANCH_NUMBER: opts.branch_number, |
| 166 | LSB_KEY_BUILD_NUMBER: opts.build_number, |
| 167 | LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone, |
| 168 | LSB_KEY_PATCH_NUMBER: opts.patch_number, |
| 169 | LSB_KEY_VERSION: opts.version_string, |
| 170 | LSB_KEY_GOOGLE_RELEASE: opts.version_string, |
| 171 | }) |
| 172 | |
| 173 | image_lib.WriteLsbRelease(opts.sysroot, fields) |