blob: ffcb660b851b9cdcb125107251c96fc716e2ff7b [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_MODELS = 'CHROMEOS_RELEASE_MODELS'
45LSB_KEY_UNIBUILD = 'CHROMEOS_RELEASE_UNIBUILD'
Steve Fung67ef9462015-05-21 03:37:06 -070046LSB_KEY_BRANCH_NUMBER = 'CHROMEOS_RELEASE_BRANCH_NUMBER'
47LSB_KEY_BUILD_NUMBER = 'CHROMEOS_RELEASE_BUILD_NUMBER'
48LSB_KEY_CHROME_MILESTONE = 'CHROMEOS_RELEASE_CHROME_MILESTONE'
49LSB_KEY_PATCH_NUMBER = 'CHROMEOS_RELEASE_PATCH_NUMBER'
50LSB_KEY_VERSION = 'CHROMEOS_RELEASE_VERSION'
xixuan745999f2016-08-03 19:20:30 -070051LSB_KEY_BUILDER_PATH = 'CHROMEOS_RELEASE_BUILDER_PATH'
Steve Fung67ef9462015-05-21 03:37:06 -070052LSB_KEY_GOOGLE_RELEASE = 'GOOGLE_RELEASE'
Steve Fung977460a2015-05-31 23:25:33 -070053LSB_KEY_APPID_RELEASE = 'CHROMEOS_RELEASE_APPID'
54LSB_KEY_APPID_BOARD = 'CHROMEOS_BOARD_APPID'
55LSB_KEY_APPID_CANARY = 'CHROMEOS_CANARY_APPID'
Elijah Taylore9e3a822016-03-29 16:55:16 -070056LSB_KEY_ARC_VERSION = 'CHROMEOS_ARC_VERSION'
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090057LSB_KEY_ARC_ANDROID_SDK_VERSION = 'CHROMEOS_ARC_ANDROID_SDK_VERSION'
Steve Fung67ef9462015-05-21 03:37:06 -070058
Steve Fung977460a2015-05-31 23:25:33 -070059CANARY_APP_ID = "{90F229CE-83E2-4FAF-8479-E368A34938B1}"
Steve Fung67ef9462015-05-21 03:37:06 -070060
61def _ParseArguments(argv):
62 parser = commandline.ArgumentParser(description=__doc__)
63
Steve Fung977460a2015-05-31 23:25:33 -070064 parser.add_argument('--app_id', default=None,
65 help='The APP_ID to install.')
Steve Fung67ef9462015-05-21 03:37:06 -070066 parser.add_argument('--board', help='The board name.', required=True)
Simon Glass8d8e38b2017-03-02 15:03:35 -070067 parser.add_argument('--models',
68 help='Models supported by this board, space-separated')
Steve Fung67ef9462015-05-21 03:37:06 -070069 parser.add_argument('--sysroot', required=True, type='path',
70 help='The sysroot to install the lsb-release file into.')
71 parser.add_argument('--version_string', required=True,
72 help='The image\'s version string.')
xixuan745999f2016-08-03 19:20:30 -070073 parser.add_argument('--builder_path', default=None,
74 help='The image\'s builder path.')
Steve Fung67ef9462015-05-21 03:37:06 -070075 parser.add_argument('--auserver', default=None,
76 help='The auserver url to use.')
77 parser.add_argument('--devserver', default=None,
78 help='The devserver url to use.')
79 parser.add_argument('--official', action='store_true',
80 help='Whether or not to populate with fields for an '
81 'official image.')
Mike Frysingera0736352018-09-10 16:34:37 -040082 parser.add_argument('--keyset',
83 help='The keyset name used to sign this image.')
Steve Fung67ef9462015-05-21 03:37:06 -070084 parser.add_argument('--buildbot_build', default='N/A',
85 help='The build number, for use with the continuous '
86 'builder.')
87 parser.add_argument('--track', default='developer-build',
88 help='The type of release track.')
89 parser.add_argument('--branch_number', default='0',
90 help='The branch number.')
91 parser.add_argument('--build_number', default='0',
92 help='The build number.')
93 parser.add_argument('--chrome_milestone', default='0',
94 help='The Chrome milestone.')
95 parser.add_argument('--patch_number', default='0',
96 help='The patch number for the given branch.')
Elijah Taylore9e3a822016-03-29 16:55:16 -070097 parser.add_argument('--arc_version', default=None,
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090098 help='Android revision number of ARC.')
99 parser.add_argument('--arc_android_sdk_version', default=None,
100 help='Android SDK version of ARC.')
Steve Fung67ef9462015-05-21 03:37:06 -0700101
102 opts = parser.parse_args(argv)
103
104 # If the auserver or devserver isn't specified or is set to blank, set it
105 # to the host's hostname.
106 hostname = cros_build_lib.GetHostName(fully_qualified=True)
107
108 if not opts.auserver:
109 opts.auserver = 'http://%s:8080/update' % hostname
110
111 if not opts.devserver:
112 opts.devserver = 'http://%s:8080' % hostname
113
114 opts.Freeze()
115
116 if not os.path.isdir(opts.sysroot):
117 cros_build_lib.Die('The target sysroot does not exist: %s' % opts.sysroot)
118
119 if not opts.version_string:
120 cros_build_lib.Die('version_string must not be empty. Was '
121 'chromeos_version.sh sourced correctly in the calling '
122 'script?')
123
124 return opts
125
126
127def main(argv):
128 opts = _ParseArguments(argv)
129
130 fields = {
131 LSB_KEY_NAME: 'Chromium OS',
132 LSB_KEY_AUSERVER: opts.auserver,
133 LSB_KEY_DEVSERVER: opts.devserver,
134 }
135
Steve Fung977460a2015-05-31 23:25:33 -0700136 if opts.app_id is not None:
137 fields.update({
138 LSB_KEY_APPID_RELEASE: opts.app_id,
139 LSB_KEY_APPID_BOARD: opts.app_id,
140 LSB_KEY_APPID_CANARY: CANARY_APP_ID,
141 })
142
Elijah Taylore9e3a822016-03-29 16:55:16 -0700143 if opts.arc_version is not None:
144 fields.update({
145 LSB_KEY_ARC_VERSION: opts.arc_version,
146 })
147
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +0900148 if opts.arc_android_sdk_version is not None:
149 fields.update({
150 LSB_KEY_ARC_ANDROID_SDK_VERSION: opts.arc_android_sdk_version,
151 })
152
xixuan745999f2016-08-03 19:20:30 -0700153 if opts.builder_path is not None:
154 fields.update({
155 LSB_KEY_BUILDER_PATH: opts.builder_path,
156 })
157
Mike Frysingera0736352018-09-10 16:34:37 -0400158 if opts.keyset is not None:
159 fields.update({
160 LSB_KEY_BOARD: opts.keyset,
161 })
162
Simon Glass8d8e38b2017-03-02 15:03:35 -0700163 board_and_models = opts.board
164 if opts.models:
165 board_and_models += '-unibuild (%s)' % opts.models
Steve Fung67ef9462015-05-21 03:37:06 -0700166 if opts.official:
167 # Official builds (i.e. buildbot).
168 track = 'dev-channel'
169 build_type = 'Official Build'
170 fields.update({
171 LSB_KEY_TRACK: track,
172 LSB_KEY_NAME: 'Chrome OS',
173 LSB_KEY_BUILD_TYPE: build_type,
174 LSB_KEY_DESCRIPTION: ('%s (%s) %s %s test' %
175 (opts.version_string,
176 build_type,
177 track,
Simon Glass8d8e38b2017-03-02 15:03:35 -0700178 board_and_models)),
Steve Fung67ef9462015-05-21 03:37:06 -0700179 LSB_KEY_AUSERVER: 'https://tools.google.com/service/update2',
180 LSB_KEY_DEVSERVER: '',
181 })
182 elif getpass.getuser() == 'chrome-bot':
183 # Continuous builder.
184 build_type = 'Continuous Builder - Builder: %s' % opts.buildbot_build
185 fields.update({
186 LSB_KEY_TRACK: 'buildbot-build',
187 LSB_KEY_BUILD_TYPE: build_type,
188 LSB_KEY_DESCRIPTION: '%s (%s) %s' % (opts.version_string,
189 build_type,
Simon Glass8d8e38b2017-03-02 15:03:35 -0700190 board_and_models),
Steve Fung67ef9462015-05-21 03:37:06 -0700191 })
192 else:
193 # Developer manual builds.
194 build_type = 'Developer Build - %s' % getpass.getuser()
195 fields.update({
196 LSB_KEY_TRACK: opts.track,
197 LSB_KEY_BUILD_TYPE: build_type,
198 LSB_KEY_DESCRIPTION: '%s (%s) %s %s' % (opts.version_string,
199 build_type,
200 opts.track,
Simon Glass8d8e38b2017-03-02 15:03:35 -0700201 board_and_models),
Steve Fung67ef9462015-05-21 03:37:06 -0700202 })
203
204 fields.update({
205 LSB_KEY_BOARD: opts.board,
206 LSB_KEY_BRANCH_NUMBER: opts.branch_number,
207 LSB_KEY_BUILD_NUMBER: opts.build_number,
208 LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone,
209 LSB_KEY_PATCH_NUMBER: opts.patch_number,
210 LSB_KEY_VERSION: opts.version_string,
211 LSB_KEY_GOOGLE_RELEASE: opts.version_string,
212 })
Simon Glass8d8e38b2017-03-02 15:03:35 -0700213 if opts.models:
214 fields[LSB_KEY_UNIBUILD] = '1'
215 fields[LSB_KEY_MODELS] = opts.models
Steve Fung67ef9462015-05-21 03:37:06 -0700216
217 image_lib.WriteLsbRelease(opts.sysroot, fields)