blob: ec0f84c317d5b3115faf63ec9efe1ad3a644415f [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.
Alex Klein1699fab2022-09-08 08:46:06 -060033LSB_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"
40LSB_KEY_KEYSET = "CHROMEOS_RELEASE_KEYSET"
41LSB_KEY_UNIBUILD = "CHROMEOS_RELEASE_UNIBUILD"
42LSB_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"
47LSB_KEY_BUILDER_PATH = "CHROMEOS_RELEASE_BUILDER_PATH"
48LSB_KEY_GOOGLE_RELEASE = "GOOGLE_RELEASE"
49LSB_KEY_APPID_RELEASE = "CHROMEOS_RELEASE_APPID"
50LSB_KEY_APPID_BOARD = "CHROMEOS_BOARD_APPID"
51LSB_KEY_APPID_CANARY = "CHROMEOS_CANARY_APPID"
52LSB_KEY_ARC_VERSION = "CHROMEOS_ARC_VERSION"
53LSB_KEY_ARC_ANDROID_SDK_VERSION = "CHROMEOS_ARC_ANDROID_SDK_VERSION"
Steve Fung67ef9462015-05-21 03:37:06 -070054
Alex Klein1699fab2022-09-08 08:46:06 -060055CANARY_APP_ID = "{90F229CE-83E2-4FAF-8479-E368A34938B1}"
56
Steve Fung67ef9462015-05-21 03:37:06 -070057
58def _ParseArguments(argv):
Alex Klein1699fab2022-09-08 08:46:06 -060059 parser = commandline.ArgumentParser(description=__doc__)
Steve Fung67ef9462015-05-21 03:37:06 -070060
Alex Klein1699fab2022-09-08 08:46:06 -060061 parser.add_argument("--app_id", default=None, help="The APP_ID to install.")
62 parser.add_argument("--board", help="The board name.", required=True)
63 parser.add_argument(
64 "--unibuild",
65 action="store_true",
66 default=False,
67 help="Set if board has chromeos-config.",
68 )
69 parser.add_argument(
70 "--sysroot",
71 required=True,
72 type="path",
73 help="The sysroot to install the lsb-release file into.",
74 )
75 parser.add_argument(
76 "--version_string", required=True, help="The image's version string."
77 )
78 parser.add_argument(
79 "--builder_path", default=None, help="The image's builder path."
80 )
81 parser.add_argument(
82 "--auserver", default=None, help="The auserver url to use."
83 )
84 parser.add_argument(
85 "--devserver", default=None, help="The devserver url to use."
86 )
87 parser.add_argument(
88 "--official",
89 action="store_true",
90 help="Whether or not to populate with fields for an " "official image.",
91 )
92 parser.add_argument(
93 "--keyset", help="The keyset name used to sign this image."
94 )
95 parser.add_argument(
96 "--buildbot_build",
97 default="N/A",
98 help="The build number, for use with the continuous " "builder.",
99 )
100 parser.add_argument(
101 "--track", default="developer-build", help="The type of release track."
102 )
103 parser.add_argument(
104 "--branch_number", default="0", help="The branch number."
105 )
106 parser.add_argument("--build_number", default="0", help="The build number.")
107 parser.add_argument(
108 "--chrome_milestone", default="0", help="The Chrome milestone."
109 )
110 parser.add_argument(
111 "--patch_number",
112 default="0",
113 help="The patch number for the given branch.",
114 )
115 parser.add_argument(
116 "--arc_version", default=None, help="Android revision number of ARC."
117 )
118 parser.add_argument(
119 "--arc_android_sdk_version",
120 default=None,
121 help="Android SDK version of ARC.",
122 )
Steve Fung67ef9462015-05-21 03:37:06 -0700123
Alex Klein1699fab2022-09-08 08:46:06 -0600124 opts = parser.parse_args(argv)
Steve Fung67ef9462015-05-21 03:37:06 -0700125
Alex Klein1699fab2022-09-08 08:46:06 -0600126 # If the auserver or devserver isn't specified or is set to blank, set it
127 # to the host's hostname.
128 hostname = cros_build_lib.GetHostName(fully_qualified=True)
Steve Fung67ef9462015-05-21 03:37:06 -0700129
Alex Klein1699fab2022-09-08 08:46:06 -0600130 if not opts.auserver:
131 opts.auserver = "http://%s:8080/update" % hostname
Steve Fung67ef9462015-05-21 03:37:06 -0700132
Alex Klein1699fab2022-09-08 08:46:06 -0600133 if not opts.devserver:
134 opts.devserver = "http://%s:8080" % hostname
Steve Fung67ef9462015-05-21 03:37:06 -0700135
Alex Klein1699fab2022-09-08 08:46:06 -0600136 opts.Freeze()
Steve Fung67ef9462015-05-21 03:37:06 -0700137
Alex Klein1699fab2022-09-08 08:46:06 -0600138 if not os.path.isdir(opts.sysroot):
139 cros_build_lib.Die(
140 "The target sysroot does not exist: %s" % opts.sysroot
141 )
Steve Fung67ef9462015-05-21 03:37:06 -0700142
Alex Klein1699fab2022-09-08 08:46:06 -0600143 if not opts.version_string:
144 cros_build_lib.Die(
145 "version_string must not be empty. Was "
146 "chromeos_version.sh sourced correctly in the calling "
147 "script?"
148 )
Steve Fung67ef9462015-05-21 03:37:06 -0700149
Alex Klein1699fab2022-09-08 08:46:06 -0600150 return opts
Steve Fung67ef9462015-05-21 03:37:06 -0700151
152
153def main(argv):
Alex Klein1699fab2022-09-08 08:46:06 -0600154 opts = _ParseArguments(argv)
Steve Fung67ef9462015-05-21 03:37:06 -0700155
Alex Klein1699fab2022-09-08 08:46:06 -0600156 fields = {
157 LSB_KEY_NAME: "Chromium OS",
158 LSB_KEY_AUSERVER: opts.auserver,
159 LSB_KEY_DEVSERVER: opts.devserver,
160 }
Steve Fung67ef9462015-05-21 03:37:06 -0700161
Alex Klein1699fab2022-09-08 08:46:06 -0600162 if opts.app_id is not None:
163 fields.update(
164 {
165 LSB_KEY_APPID_RELEASE: opts.app_id,
166 LSB_KEY_APPID_BOARD: opts.app_id,
167 LSB_KEY_APPID_CANARY: CANARY_APP_ID,
168 }
169 )
Steve Fung977460a2015-05-31 23:25:33 -0700170
Alex Klein1699fab2022-09-08 08:46:06 -0600171 if opts.arc_version is not None:
172 fields.update(
173 {
174 LSB_KEY_ARC_VERSION: opts.arc_version,
175 }
176 )
Elijah Taylore9e3a822016-03-29 16:55:16 -0700177
Alex Klein1699fab2022-09-08 08:46:06 -0600178 if opts.arc_android_sdk_version is not None:
179 fields.update(
180 {
181 LSB_KEY_ARC_ANDROID_SDK_VERSION: opts.arc_android_sdk_version,
182 }
183 )
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +0900184
Alex Klein1699fab2022-09-08 08:46:06 -0600185 if opts.builder_path is not None:
186 fields.update(
187 {
188 LSB_KEY_BUILDER_PATH: opts.builder_path,
189 }
190 )
xixuan745999f2016-08-03 19:20:30 -0700191
Alex Klein1699fab2022-09-08 08:46:06 -0600192 if opts.keyset is not None:
193 fields.update(
194 {
195 LSB_KEY_KEYSET: opts.keyset,
196 }
197 )
Mike Frysingera0736352018-09-10 16:34:37 -0400198
Alex Klein1699fab2022-09-08 08:46:06 -0600199 board = opts.board
200 if opts.official:
201 # Official builds (i.e. buildbot).
202 track = "dev-channel"
203 build_type = "Official Build"
204 fields.update(
205 {
206 LSB_KEY_TRACK: track,
207 LSB_KEY_NAME: "Chrome OS",
208 LSB_KEY_BUILD_TYPE: build_type,
209 LSB_KEY_DESCRIPTION: (
210 "%s (%s) %s %s test"
211 % (opts.version_string, build_type, track, board)
212 ),
213 LSB_KEY_AUSERVER: "https://tools.google.com/service/update2",
214 LSB_KEY_DEVSERVER: "",
215 }
216 )
217 elif getpass.getuser() == "chrome-bot":
218 # Continuous builder.
219 build_type = "Continuous Builder - Builder: %s" % opts.buildbot_build
220 fields.update(
221 {
222 LSB_KEY_TRACK: "buildbot-build",
223 LSB_KEY_BUILD_TYPE: build_type,
224 LSB_KEY_DESCRIPTION: "%s (%s) %s"
225 % (opts.version_string, build_type, board),
226 }
227 )
228 else:
229 # Developer manual builds.
230 build_type = "Developer Build - %s" % getpass.getuser()
231 fields.update(
232 {
233 LSB_KEY_TRACK: opts.track,
234 LSB_KEY_BUILD_TYPE: build_type,
235 LSB_KEY_DESCRIPTION: "%s (%s) %s %s"
236 % (opts.version_string, build_type, opts.track, board),
237 }
238 )
Steve Fung67ef9462015-05-21 03:37:06 -0700239
Alex Klein1699fab2022-09-08 08:46:06 -0600240 fields.update(
241 {
242 LSB_KEY_BOARD: opts.board,
243 LSB_KEY_BRANCH_NUMBER: opts.branch_number,
244 LSB_KEY_BUILD_NUMBER: opts.build_number,
245 LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone,
246 LSB_KEY_PATCH_NUMBER: opts.patch_number,
247 LSB_KEY_VERSION: opts.version_string,
248 LSB_KEY_GOOGLE_RELEASE: opts.version_string,
249 }
250 )
251 if opts.unibuild:
252 fields[LSB_KEY_UNIBUILD] = "1"
Steve Fung67ef9462015-05-21 03:37:06 -0700253
Alex Klein1699fab2022-09-08 08:46:06 -0600254 image_lib.WriteLsbRelease(opts.sysroot, fields)