blob: d2a11ff3bced68037e9a68fa95811884f0f07b57 [file] [log] [blame]
Mike Frysingere58c0e22017-10-04 15:43:30 -04001# -*- coding: utf-8 -*-
Steve Fung67ef9462015-05-21 03:37:06 -07002# Copyright 2015 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Utility for setting the /etc/lsb-release file of an image."""
7
8from __future__ import print_function
9
10import getpass
11import os
12
13from chromite.lib import commandline
14from chromite.lib import cros_build_lib
15from chromite.lib import image_lib
16
17
18# LSB keys:
19# Set google-specific version numbers:
20# CHROMEOS_RELEASE_BOARD is the target board identifier.
21# CHROMEOS_RELEASE_BRANCH_NUMBER is the Chrome OS branch number
22# CHROMEOS_RELEASE_BUILD_NUMBER is the Chrome OS build number
23# CHROMEOS_RELEASE_BUILD_TYPE is the type of build (official, from developers,
24# etc..)
25# CHROMEOS_RELEASE_CHROME_MILESTONE is the Chrome milestone (also named Chrome
26# branch).
27# CHROMEOS_RELEASE_DESCRIPTION is the version displayed by Chrome; see
28# chrome/browser/chromeos/chromeos_version_loader.cc.
29# CHROMEOS_RELEASE_NAME is a human readable name for the build.
30# CHROMEOS_RELEASE_PATCH_NUMBER is the patch number for the current branch.
31# CHROMEOS_RELEASE_TRACK and CHROMEOS_RELEASE_VERSION are used by the software
32# update service.
Mike Frysingera0736352018-09-10 16:34:37 -040033# CHROMEOS_RELEASE_KEYSET is the named of the keyset used to sign this build.
Steve Fung67ef9462015-05-21 03:37:06 -070034# TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at
35# CHROMEOS_RELEASE_VERSION for UserAgent data.
36LSB_KEY_NAME = 'CHROMEOS_RELEASE_NAME'
37LSB_KEY_AUSERVER = 'CHROMEOS_AUSERVER'
38LSB_KEY_DEVSERVER = 'CHROMEOS_DEVSERVER'
39LSB_KEY_TRACK = 'CHROMEOS_RELEASE_TRACK'
40LSB_KEY_BUILD_TYPE = 'CHROMEOS_RELEASE_BUILD_TYPE'
41LSB_KEY_DESCRIPTION = 'CHROMEOS_RELEASE_DESCRIPTION'
42LSB_KEY_BOARD = 'CHROMEOS_RELEASE_BOARD'
Mike Frysingera0736352018-09-10 16:34:37 -040043LSB_KEY_KEYSET = 'CHROMEOS_RELEASE_KEYSET'
Simon Glass8d8e38b2017-03-02 15:03:35 -070044LSB_KEY_UNIBUILD = 'CHROMEOS_RELEASE_UNIBUILD'
Steve Fung67ef9462015-05-21 03:37:06 -070045LSB_KEY_BRANCH_NUMBER = 'CHROMEOS_RELEASE_BRANCH_NUMBER'
46LSB_KEY_BUILD_NUMBER = 'CHROMEOS_RELEASE_BUILD_NUMBER'
47LSB_KEY_CHROME_MILESTONE = 'CHROMEOS_RELEASE_CHROME_MILESTONE'
48LSB_KEY_PATCH_NUMBER = 'CHROMEOS_RELEASE_PATCH_NUMBER'
49LSB_KEY_VERSION = 'CHROMEOS_RELEASE_VERSION'
xixuan745999f2016-08-03 19:20:30 -070050LSB_KEY_BUILDER_PATH = 'CHROMEOS_RELEASE_BUILDER_PATH'
Steve Fung67ef9462015-05-21 03:37:06 -070051LSB_KEY_GOOGLE_RELEASE = 'GOOGLE_RELEASE'
Steve Fung977460a2015-05-31 23:25:33 -070052LSB_KEY_APPID_RELEASE = 'CHROMEOS_RELEASE_APPID'
53LSB_KEY_APPID_BOARD = 'CHROMEOS_BOARD_APPID'
54LSB_KEY_APPID_CANARY = 'CHROMEOS_CANARY_APPID'
Elijah Taylore9e3a822016-03-29 16:55:16 -070055LSB_KEY_ARC_VERSION = 'CHROMEOS_ARC_VERSION'
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090056LSB_KEY_ARC_ANDROID_SDK_VERSION = 'CHROMEOS_ARC_ANDROID_SDK_VERSION'
Steve Fung67ef9462015-05-21 03:37:06 -070057
Mike Frysinger80de5012019-08-01 14:10:53 -040058CANARY_APP_ID = '{90F229CE-83E2-4FAF-8479-E368A34938B1}'
Steve Fung67ef9462015-05-21 03:37:06 -070059
60def _ParseArguments(argv):
61 parser = commandline.ArgumentParser(description=__doc__)
62
Steve Fung977460a2015-05-31 23:25:33 -070063 parser.add_argument('--app_id', default=None,
64 help='The APP_ID to install.')
Steve Fung67ef9462015-05-21 03:37:06 -070065 parser.add_argument('--board', help='The board name.', required=True)
Simon Glass8d8e38b2017-03-02 15:03:35 -070066 parser.add_argument('--models',
67 help='Models supported by this board, space-separated')
Steve Fung67ef9462015-05-21 03:37:06 -070068 parser.add_argument('--sysroot', required=True, type='path',
69 help='The sysroot to install the lsb-release file into.')
70 parser.add_argument('--version_string', required=True,
Mike Frysinger80de5012019-08-01 14:10:53 -040071 help="The image's version string.")
xixuan745999f2016-08-03 19:20:30 -070072 parser.add_argument('--builder_path', default=None,
Mike Frysinger80de5012019-08-01 14:10:53 -040073 help="The image's builder path.")
Steve Fung67ef9462015-05-21 03:37:06 -070074 parser.add_argument('--auserver', default=None,
75 help='The auserver url to use.')
76 parser.add_argument('--devserver', default=None,
77 help='The devserver url to use.')
78 parser.add_argument('--official', action='store_true',
79 help='Whether or not to populate with fields for an '
80 'official image.')
Mike Frysingera0736352018-09-10 16:34:37 -040081 parser.add_argument('--keyset',
82 help='The keyset name used to sign this image.')
Steve Fung67ef9462015-05-21 03:37:06 -070083 parser.add_argument('--buildbot_build', default='N/A',
84 help='The build number, for use with the continuous '
85 'builder.')
86 parser.add_argument('--track', default='developer-build',
87 help='The type of release track.')
88 parser.add_argument('--branch_number', default='0',
89 help='The branch number.')
90 parser.add_argument('--build_number', default='0',
91 help='The build number.')
92 parser.add_argument('--chrome_milestone', default='0',
93 help='The Chrome milestone.')
94 parser.add_argument('--patch_number', default='0',
95 help='The patch number for the given branch.')
Elijah Taylore9e3a822016-03-29 16:55:16 -070096 parser.add_argument('--arc_version', default=None,
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090097 help='Android revision number of ARC.')
98 parser.add_argument('--arc_android_sdk_version', default=None,
99 help='Android SDK version of ARC.')
Steve Fung67ef9462015-05-21 03:37:06 -0700100
101 opts = parser.parse_args(argv)
102
103 # If the auserver or devserver isn't specified or is set to blank, set it
104 # to the host's hostname.
105 hostname = cros_build_lib.GetHostName(fully_qualified=True)
106
107 if not opts.auserver:
108 opts.auserver = 'http://%s:8080/update' % hostname
109
110 if not opts.devserver:
111 opts.devserver = 'http://%s:8080' % hostname
112
113 opts.Freeze()
114
115 if not os.path.isdir(opts.sysroot):
116 cros_build_lib.Die('The target sysroot does not exist: %s' % opts.sysroot)
117
118 if not opts.version_string:
119 cros_build_lib.Die('version_string must not be empty. Was '
120 'chromeos_version.sh sourced correctly in the calling '
121 'script?')
122
123 return opts
124
125
126def main(argv):
127 opts = _ParseArguments(argv)
128
129 fields = {
130 LSB_KEY_NAME: 'Chromium OS',
131 LSB_KEY_AUSERVER: opts.auserver,
132 LSB_KEY_DEVSERVER: opts.devserver,
133 }
134
Steve Fung977460a2015-05-31 23:25:33 -0700135 if opts.app_id is not None:
136 fields.update({
137 LSB_KEY_APPID_RELEASE: opts.app_id,
138 LSB_KEY_APPID_BOARD: opts.app_id,
139 LSB_KEY_APPID_CANARY: CANARY_APP_ID,
140 })
141
Elijah Taylore9e3a822016-03-29 16:55:16 -0700142 if opts.arc_version is not None:
143 fields.update({
144 LSB_KEY_ARC_VERSION: opts.arc_version,
145 })
146
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +0900147 if opts.arc_android_sdk_version is not None:
148 fields.update({
149 LSB_KEY_ARC_ANDROID_SDK_VERSION: opts.arc_android_sdk_version,
150 })
151
xixuan745999f2016-08-03 19:20:30 -0700152 if opts.builder_path is not None:
153 fields.update({
154 LSB_KEY_BUILDER_PATH: opts.builder_path,
155 })
156
Mike Frysingera0736352018-09-10 16:34:37 -0400157 if opts.keyset is not None:
158 fields.update({
Alex Kleinc414a6e2019-04-15 16:37:48 -0600159 LSB_KEY_KEYSET: opts.keyset,
Mike Frysingera0736352018-09-10 16:34:37 -0400160 })
161
C Shapiroc2c8ab32018-10-05 11:02:40 -0600162 board = opts.board
Steve Fung67ef9462015-05-21 03:37:06 -0700163 if opts.official:
164 # Official builds (i.e. buildbot).
165 track = 'dev-channel'
166 build_type = 'Official Build'
167 fields.update({
168 LSB_KEY_TRACK: track,
169 LSB_KEY_NAME: 'Chrome OS',
170 LSB_KEY_BUILD_TYPE: build_type,
171 LSB_KEY_DESCRIPTION: ('%s (%s) %s %s test' %
172 (opts.version_string,
173 build_type,
174 track,
C Shapiroc2c8ab32018-10-05 11:02:40 -0600175 board)),
Steve Fung67ef9462015-05-21 03:37:06 -0700176 LSB_KEY_AUSERVER: 'https://tools.google.com/service/update2',
177 LSB_KEY_DEVSERVER: '',
178 })
179 elif getpass.getuser() == 'chrome-bot':
180 # Continuous builder.
181 build_type = 'Continuous Builder - Builder: %s' % opts.buildbot_build
182 fields.update({
183 LSB_KEY_TRACK: 'buildbot-build',
184 LSB_KEY_BUILD_TYPE: build_type,
185 LSB_KEY_DESCRIPTION: '%s (%s) %s' % (opts.version_string,
186 build_type,
C Shapiroc2c8ab32018-10-05 11:02:40 -0600187 board),
Steve Fung67ef9462015-05-21 03:37:06 -0700188 })
189 else:
190 # Developer manual builds.
191 build_type = 'Developer Build - %s' % getpass.getuser()
192 fields.update({
193 LSB_KEY_TRACK: opts.track,
194 LSB_KEY_BUILD_TYPE: build_type,
195 LSB_KEY_DESCRIPTION: '%s (%s) %s %s' % (opts.version_string,
196 build_type,
197 opts.track,
C Shapiroc2c8ab32018-10-05 11:02:40 -0600198 board),
Steve Fung67ef9462015-05-21 03:37:06 -0700199 })
200
201 fields.update({
202 LSB_KEY_BOARD: opts.board,
203 LSB_KEY_BRANCH_NUMBER: opts.branch_number,
204 LSB_KEY_BUILD_NUMBER: opts.build_number,
205 LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone,
206 LSB_KEY_PATCH_NUMBER: opts.patch_number,
207 LSB_KEY_VERSION: opts.version_string,
208 LSB_KEY_GOOGLE_RELEASE: opts.version_string,
209 })
Simon Glass8d8e38b2017-03-02 15:03:35 -0700210 if opts.models:
211 fields[LSB_KEY_UNIBUILD] = '1'
Steve Fung67ef9462015-05-21 03:37:06 -0700212
213 image_lib.WriteLsbRelease(opts.sysroot, fields)