blob: 2edaefa6127997485bcb1f4f441bca6aa46ece10 [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2015 The ChromiumOS Authors
Steve Fung67ef9462015-05-21 03:37:06 -07002# 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
Anuj Jamwal258529f2023-09-08 17:32:55 +000013from chromite.utils import hostname_util
Steve Fung67ef9462015-05-21 03:37:06 -070014
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 Frysingera0736352018-09-10 16:34:37 -040031# CHROMEOS_RELEASE_KEYSET is the named of the keyset used to sign this build.
Steve Fung67ef9462015-05-21 03:37:06 -070032# TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at
33# CHROMEOS_RELEASE_VERSION for UserAgent data.
Alex Klein1699fab2022-09-08 08:46:06 -060034LSB_KEY_NAME = "CHROMEOS_RELEASE_NAME"
35LSB_KEY_AUSERVER = "CHROMEOS_AUSERVER"
36LSB_KEY_DEVSERVER = "CHROMEOS_DEVSERVER"
37LSB_KEY_TRACK = "CHROMEOS_RELEASE_TRACK"
38LSB_KEY_BUILD_TYPE = "CHROMEOS_RELEASE_BUILD_TYPE"
39LSB_KEY_DESCRIPTION = "CHROMEOS_RELEASE_DESCRIPTION"
40LSB_KEY_BOARD = "CHROMEOS_RELEASE_BOARD"
41LSB_KEY_KEYSET = "CHROMEOS_RELEASE_KEYSET"
42LSB_KEY_UNIBUILD = "CHROMEOS_RELEASE_UNIBUILD"
43LSB_KEY_BRANCH_NUMBER = "CHROMEOS_RELEASE_BRANCH_NUMBER"
44LSB_KEY_BUILD_NUMBER = "CHROMEOS_RELEASE_BUILD_NUMBER"
45LSB_KEY_CHROME_MILESTONE = "CHROMEOS_RELEASE_CHROME_MILESTONE"
46LSB_KEY_PATCH_NUMBER = "CHROMEOS_RELEASE_PATCH_NUMBER"
47LSB_KEY_VERSION = "CHROMEOS_RELEASE_VERSION"
48LSB_KEY_BUILDER_PATH = "CHROMEOS_RELEASE_BUILDER_PATH"
49LSB_KEY_GOOGLE_RELEASE = "GOOGLE_RELEASE"
50LSB_KEY_APPID_RELEASE = "CHROMEOS_RELEASE_APPID"
51LSB_KEY_APPID_BOARD = "CHROMEOS_BOARD_APPID"
52LSB_KEY_APPID_CANARY = "CHROMEOS_CANARY_APPID"
53LSB_KEY_ARC_VERSION = "CHROMEOS_ARC_VERSION"
54LSB_KEY_ARC_ANDROID_SDK_VERSION = "CHROMEOS_ARC_ANDROID_SDK_VERSION"
Steve Fung67ef9462015-05-21 03:37:06 -070055
Alex Klein1699fab2022-09-08 08:46:06 -060056CANARY_APP_ID = "{90F229CE-83E2-4FAF-8479-E368A34938B1}"
57
Steve Fung67ef9462015-05-21 03:37:06 -070058
59def _ParseArguments(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060060 parser = commandline.ArgumentParser(description=__doc__)
Steve Fung67ef9462015-05-21 03:37:06 -070061
Alex Klein1699fab2022-09-08 08:46:06 -060062 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 Fung67ef9462015-05-21 03:37:06 -0700124
Alex Klein1699fab2022-09-08 08:46:06 -0600125 opts = parser.parse_args(argv)
Steve Fung67ef9462015-05-21 03:37:06 -0700126
Alex Klein1699fab2022-09-08 08:46:06 -0600127 # If the auserver or devserver isn't specified or is set to blank, set it
128 # to the host's hostname.
Anuj Jamwal258529f2023-09-08 17:32:55 +0000129 hostname = hostname_util.get_host_name(fully_qualified=True)
Steve Fung67ef9462015-05-21 03:37:06 -0700130
Alex Klein1699fab2022-09-08 08:46:06 -0600131 if not opts.auserver:
132 opts.auserver = "http://%s:8080/update" % hostname
Steve Fung67ef9462015-05-21 03:37:06 -0700133
Alex Klein1699fab2022-09-08 08:46:06 -0600134 if not opts.devserver:
135 opts.devserver = "http://%s:8080" % hostname
Steve Fung67ef9462015-05-21 03:37:06 -0700136
Alex Klein1699fab2022-09-08 08:46:06 -0600137 opts.Freeze()
Steve Fung67ef9462015-05-21 03:37:06 -0700138
Alex Klein1699fab2022-09-08 08:46:06 -0600139 if not os.path.isdir(opts.sysroot):
140 cros_build_lib.Die(
141 "The target sysroot does not exist: %s" % opts.sysroot
142 )
Steve Fung67ef9462015-05-21 03:37:06 -0700143
Alex Klein1699fab2022-09-08 08:46:06 -0600144 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 Fung67ef9462015-05-21 03:37:06 -0700150
Alex Klein1699fab2022-09-08 08:46:06 -0600151 return opts
Steve Fung67ef9462015-05-21 03:37:06 -0700152
153
154def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -0600155 opts = _ParseArguments(argv)
Steve Fung67ef9462015-05-21 03:37:06 -0700156
Alex Klein1699fab2022-09-08 08:46:06 -0600157 fields = {
158 LSB_KEY_NAME: "Chromium OS",
159 LSB_KEY_AUSERVER: opts.auserver,
160 LSB_KEY_DEVSERVER: opts.devserver,
161 }
Steve Fung67ef9462015-05-21 03:37:06 -0700162
Alex Klein1699fab2022-09-08 08:46:06 -0600163 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 Fung977460a2015-05-31 23:25:33 -0700171
Alex Klein1699fab2022-09-08 08:46:06 -0600172 if opts.arc_version is not None:
173 fields.update(
174 {
175 LSB_KEY_ARC_VERSION: opts.arc_version,
176 }
177 )
Elijah Taylore9e3a822016-03-29 16:55:16 -0700178
Alex Klein1699fab2022-09-08 08:46:06 -0600179 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 Takahashi50fd9e72017-01-27 16:00:34 +0900185
Alex Klein1699fab2022-09-08 08:46:06 -0600186 if opts.builder_path is not None:
187 fields.update(
188 {
189 LSB_KEY_BUILDER_PATH: opts.builder_path,
190 }
191 )
xixuan745999f2016-08-03 19:20:30 -0700192
Alex Klein1699fab2022-09-08 08:46:06 -0600193 if opts.keyset is not None:
194 fields.update(
195 {
196 LSB_KEY_KEYSET: opts.keyset,
197 }
198 )
Mike Frysingera0736352018-09-10 16:34:37 -0400199
Alex Klein1699fab2022-09-08 08:46:06 -0600200 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 Fung67ef9462015-05-21 03:37:06 -0700240
Alex Klein1699fab2022-09-08 08:46:06 -0600241 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 Fung67ef9462015-05-21 03:37:06 -0700254
Alex Klein1699fab2022-09-08 08:46:06 -0600255 image_lib.WriteLsbRelease(opts.sysroot, fields)