blob: 2151b224b78d04de2c5610a278cb0e2d71d7fa18 [file] [log] [blame]
Steve Fung67ef9462015-05-21 03:37:06 -07001# 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
Steve Fung67ef9462015-05-21 03:37:06 -07007import getpass
8import os
9
10from chromite.lib import commandline
11from chromite.lib import cros_build_lib
12from chromite.lib import image_lib
13
14
15# LSB keys:
16# Set google-specific version numbers:
17# CHROMEOS_RELEASE_BOARD is the target board identifier.
18# CHROMEOS_RELEASE_BRANCH_NUMBER is the Chrome OS branch number
19# CHROMEOS_RELEASE_BUILD_NUMBER is the Chrome OS build number
20# CHROMEOS_RELEASE_BUILD_TYPE is the type of build (official, from developers,
21# etc..)
22# CHROMEOS_RELEASE_CHROME_MILESTONE is the Chrome milestone (also named Chrome
23# branch).
24# CHROMEOS_RELEASE_DESCRIPTION is the version displayed by Chrome; see
25# chrome/browser/chromeos/chromeos_version_loader.cc.
26# CHROMEOS_RELEASE_NAME is a human readable name for the build.
27# CHROMEOS_RELEASE_PATCH_NUMBER is the patch number for the current branch.
28# CHROMEOS_RELEASE_TRACK and CHROMEOS_RELEASE_VERSION are used by the software
29# update service.
Mike Frysingera0736352018-09-10 16:34:37 -040030# CHROMEOS_RELEASE_KEYSET is the named of the keyset used to sign this build.
Steve Fung67ef9462015-05-21 03:37:06 -070031# TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at
32# CHROMEOS_RELEASE_VERSION for UserAgent data.
33LSB_KEY_NAME = 'CHROMEOS_RELEASE_NAME'
34LSB_KEY_AUSERVER = 'CHROMEOS_AUSERVER'
35LSB_KEY_DEVSERVER = 'CHROMEOS_DEVSERVER'
36LSB_KEY_TRACK = 'CHROMEOS_RELEASE_TRACK'
37LSB_KEY_BUILD_TYPE = 'CHROMEOS_RELEASE_BUILD_TYPE'
38LSB_KEY_DESCRIPTION = 'CHROMEOS_RELEASE_DESCRIPTION'
39LSB_KEY_BOARD = 'CHROMEOS_RELEASE_BOARD'
Mike Frysingera0736352018-09-10 16:34:37 -040040LSB_KEY_KEYSET = 'CHROMEOS_RELEASE_KEYSET'
Simon Glass8d8e38b2017-03-02 15:03:35 -070041LSB_KEY_UNIBUILD = 'CHROMEOS_RELEASE_UNIBUILD'
Steve Fung67ef9462015-05-21 03:37:06 -070042LSB_KEY_BRANCH_NUMBER = 'CHROMEOS_RELEASE_BRANCH_NUMBER'
43LSB_KEY_BUILD_NUMBER = 'CHROMEOS_RELEASE_BUILD_NUMBER'
44LSB_KEY_CHROME_MILESTONE = 'CHROMEOS_RELEASE_CHROME_MILESTONE'
45LSB_KEY_PATCH_NUMBER = 'CHROMEOS_RELEASE_PATCH_NUMBER'
46LSB_KEY_VERSION = 'CHROMEOS_RELEASE_VERSION'
xixuan745999f2016-08-03 19:20:30 -070047LSB_KEY_BUILDER_PATH = 'CHROMEOS_RELEASE_BUILDER_PATH'
Steve Fung67ef9462015-05-21 03:37:06 -070048LSB_KEY_GOOGLE_RELEASE = 'GOOGLE_RELEASE'
Steve Fung977460a2015-05-31 23:25:33 -070049LSB_KEY_APPID_RELEASE = 'CHROMEOS_RELEASE_APPID'
50LSB_KEY_APPID_BOARD = 'CHROMEOS_BOARD_APPID'
51LSB_KEY_APPID_CANARY = 'CHROMEOS_CANARY_APPID'
Elijah Taylore9e3a822016-03-29 16:55:16 -070052LSB_KEY_ARC_VERSION = 'CHROMEOS_ARC_VERSION'
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090053LSB_KEY_ARC_ANDROID_SDK_VERSION = 'CHROMEOS_ARC_ANDROID_SDK_VERSION'
Steve Fung67ef9462015-05-21 03:37:06 -070054
Mike Frysinger80de5012019-08-01 14:10:53 -040055CANARY_APP_ID = '{90F229CE-83E2-4FAF-8479-E368A34938B1}'
Steve Fung67ef9462015-05-21 03:37:06 -070056
57def _ParseArguments(argv):
58 parser = commandline.ArgumentParser(description=__doc__)
59
Steve Fung977460a2015-05-31 23:25:33 -070060 parser.add_argument('--app_id', default=None,
61 help='The APP_ID to install.')
Steve Fung67ef9462015-05-21 03:37:06 -070062 parser.add_argument('--board', help='The board name.', required=True)
Jack Rosenthal58d14d72020-02-27 11:01:48 -070063 parser.add_argument('--unibuild', action='store_true', default=False,
64 help='Set if board has chromeos-config.')
Steve Fung67ef9462015-05-21 03:37:06 -070065 parser.add_argument('--sysroot', required=True, type='path',
66 help='The sysroot to install the lsb-release file into.')
67 parser.add_argument('--version_string', required=True,
Mike Frysinger80de5012019-08-01 14:10:53 -040068 help="The image's version string.")
xixuan745999f2016-08-03 19:20:30 -070069 parser.add_argument('--builder_path', default=None,
Mike Frysinger80de5012019-08-01 14:10:53 -040070 help="The image's builder path.")
Steve Fung67ef9462015-05-21 03:37:06 -070071 parser.add_argument('--auserver', default=None,
72 help='The auserver url to use.')
73 parser.add_argument('--devserver', default=None,
74 help='The devserver url to use.')
75 parser.add_argument('--official', action='store_true',
76 help='Whether or not to populate with fields for an '
77 'official image.')
Mike Frysingera0736352018-09-10 16:34:37 -040078 parser.add_argument('--keyset',
79 help='The keyset name used to sign this image.')
Steve Fung67ef9462015-05-21 03:37:06 -070080 parser.add_argument('--buildbot_build', default='N/A',
81 help='The build number, for use with the continuous '
82 'builder.')
83 parser.add_argument('--track', default='developer-build',
84 help='The type of release track.')
85 parser.add_argument('--branch_number', default='0',
86 help='The branch number.')
87 parser.add_argument('--build_number', default='0',
88 help='The build number.')
89 parser.add_argument('--chrome_milestone', default='0',
90 help='The Chrome milestone.')
91 parser.add_argument('--patch_number', default='0',
92 help='The patch number for the given branch.')
Elijah Taylore9e3a822016-03-29 16:55:16 -070093 parser.add_argument('--arc_version', default=None,
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090094 help='Android revision number of ARC.')
95 parser.add_argument('--arc_android_sdk_version', default=None,
96 help='Android SDK version of ARC.')
Steve Fung67ef9462015-05-21 03:37:06 -070097
98 opts = parser.parse_args(argv)
99
100 # If the auserver or devserver isn't specified or is set to blank, set it
101 # to the host's hostname.
102 hostname = cros_build_lib.GetHostName(fully_qualified=True)
103
104 if not opts.auserver:
105 opts.auserver = 'http://%s:8080/update' % hostname
106
107 if not opts.devserver:
108 opts.devserver = 'http://%s:8080' % hostname
109
110 opts.Freeze()
111
112 if not os.path.isdir(opts.sysroot):
113 cros_build_lib.Die('The target sysroot does not exist: %s' % opts.sysroot)
114
115 if not opts.version_string:
116 cros_build_lib.Die('version_string must not be empty. Was '
117 'chromeos_version.sh sourced correctly in the calling '
118 'script?')
119
120 return opts
121
122
123def main(argv):
124 opts = _ParseArguments(argv)
125
126 fields = {
127 LSB_KEY_NAME: 'Chromium OS',
128 LSB_KEY_AUSERVER: opts.auserver,
129 LSB_KEY_DEVSERVER: opts.devserver,
130 }
131
Steve Fung977460a2015-05-31 23:25:33 -0700132 if opts.app_id is not None:
133 fields.update({
134 LSB_KEY_APPID_RELEASE: opts.app_id,
135 LSB_KEY_APPID_BOARD: opts.app_id,
136 LSB_KEY_APPID_CANARY: CANARY_APP_ID,
137 })
138
Elijah Taylore9e3a822016-03-29 16:55:16 -0700139 if opts.arc_version is not None:
140 fields.update({
141 LSB_KEY_ARC_VERSION: opts.arc_version,
142 })
143
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +0900144 if opts.arc_android_sdk_version is not None:
145 fields.update({
146 LSB_KEY_ARC_ANDROID_SDK_VERSION: opts.arc_android_sdk_version,
147 })
148
xixuan745999f2016-08-03 19:20:30 -0700149 if opts.builder_path is not None:
150 fields.update({
151 LSB_KEY_BUILDER_PATH: opts.builder_path,
152 })
153
Mike Frysingera0736352018-09-10 16:34:37 -0400154 if opts.keyset is not None:
155 fields.update({
Alex Kleinc414a6e2019-04-15 16:37:48 -0600156 LSB_KEY_KEYSET: opts.keyset,
Mike Frysingera0736352018-09-10 16:34:37 -0400157 })
158
C Shapiroc2c8ab32018-10-05 11:02:40 -0600159 board = opts.board
Steve Fung67ef9462015-05-21 03:37:06 -0700160 if opts.official:
161 # Official builds (i.e. buildbot).
162 track = 'dev-channel'
163 build_type = 'Official Build'
164 fields.update({
165 LSB_KEY_TRACK: track,
166 LSB_KEY_NAME: 'Chrome OS',
167 LSB_KEY_BUILD_TYPE: build_type,
168 LSB_KEY_DESCRIPTION: ('%s (%s) %s %s test' %
169 (opts.version_string,
170 build_type,
171 track,
C Shapiroc2c8ab32018-10-05 11:02:40 -0600172 board)),
Steve Fung67ef9462015-05-21 03:37:06 -0700173 LSB_KEY_AUSERVER: 'https://tools.google.com/service/update2',
174 LSB_KEY_DEVSERVER: '',
175 })
176 elif getpass.getuser() == 'chrome-bot':
177 # Continuous builder.
178 build_type = 'Continuous Builder - Builder: %s' % opts.buildbot_build
179 fields.update({
180 LSB_KEY_TRACK: 'buildbot-build',
181 LSB_KEY_BUILD_TYPE: build_type,
182 LSB_KEY_DESCRIPTION: '%s (%s) %s' % (opts.version_string,
183 build_type,
C Shapiroc2c8ab32018-10-05 11:02:40 -0600184 board),
Steve Fung67ef9462015-05-21 03:37:06 -0700185 })
186 else:
187 # Developer manual builds.
188 build_type = 'Developer Build - %s' % getpass.getuser()
189 fields.update({
190 LSB_KEY_TRACK: opts.track,
191 LSB_KEY_BUILD_TYPE: build_type,
192 LSB_KEY_DESCRIPTION: '%s (%s) %s %s' % (opts.version_string,
193 build_type,
194 opts.track,
C Shapiroc2c8ab32018-10-05 11:02:40 -0600195 board),
Steve Fung67ef9462015-05-21 03:37:06 -0700196 })
197
198 fields.update({
199 LSB_KEY_BOARD: opts.board,
200 LSB_KEY_BRANCH_NUMBER: opts.branch_number,
201 LSB_KEY_BUILD_NUMBER: opts.build_number,
202 LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone,
203 LSB_KEY_PATCH_NUMBER: opts.patch_number,
204 LSB_KEY_VERSION: opts.version_string,
205 LSB_KEY_GOOGLE_RELEASE: opts.version_string,
206 })
Jack Rosenthal58d14d72020-02-27 11:01:48 -0700207 if opts.unibuild:
Simon Glass8d8e38b2017-03-02 15:03:35 -0700208 fields[LSB_KEY_UNIBUILD] = '1'
Steve Fung67ef9462015-05-21 03:37:06 -0700209
210 image_lib.WriteLsbRelease(opts.sysroot, fields)