blob: 637c1f21fdb7d43436ee317d54555e22b67382a5 [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
7from __future__ import print_function
8
9import getpass
10import os
11
12from chromite.lib import commandline
13from chromite.lib import cros_build_lib
14from chromite.lib import image_lib
15
16
17# LSB keys:
18# Set google-specific version numbers:
19# CHROMEOS_RELEASE_BOARD is the target board identifier.
20# CHROMEOS_RELEASE_BRANCH_NUMBER is the Chrome OS branch number
21# CHROMEOS_RELEASE_BUILD_NUMBER is the Chrome OS build number
22# CHROMEOS_RELEASE_BUILD_TYPE is the type of build (official, from developers,
23# etc..)
24# CHROMEOS_RELEASE_CHROME_MILESTONE is the Chrome milestone (also named Chrome
25# branch).
26# CHROMEOS_RELEASE_DESCRIPTION is the version displayed by Chrome; see
27# chrome/browser/chromeos/chromeos_version_loader.cc.
28# CHROMEOS_RELEASE_NAME is a human readable name for the build.
29# CHROMEOS_RELEASE_PATCH_NUMBER is the patch number for the current branch.
30# CHROMEOS_RELEASE_TRACK and CHROMEOS_RELEASE_VERSION are used by the software
31# update service.
32# TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at
33# CHROMEOS_RELEASE_VERSION for UserAgent data.
34LSB_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_BRANCH_NUMBER = 'CHROMEOS_RELEASE_BRANCH_NUMBER'
42LSB_KEY_BUILD_NUMBER = 'CHROMEOS_RELEASE_BUILD_NUMBER'
43LSB_KEY_CHROME_MILESTONE = 'CHROMEOS_RELEASE_CHROME_MILESTONE'
44LSB_KEY_PATCH_NUMBER = 'CHROMEOS_RELEASE_PATCH_NUMBER'
45LSB_KEY_VERSION = 'CHROMEOS_RELEASE_VERSION'
xixuan745999f2016-08-03 19:20:30 -070046LSB_KEY_BUILDER_PATH = 'CHROMEOS_RELEASE_BUILDER_PATH'
Steve Fung67ef9462015-05-21 03:37:06 -070047LSB_KEY_GOOGLE_RELEASE = 'GOOGLE_RELEASE'
Steve Fung977460a2015-05-31 23:25:33 -070048LSB_KEY_APPID_RELEASE = 'CHROMEOS_RELEASE_APPID'
49LSB_KEY_APPID_BOARD = 'CHROMEOS_BOARD_APPID'
50LSB_KEY_APPID_CANARY = 'CHROMEOS_CANARY_APPID'
Elijah Taylore9e3a822016-03-29 16:55:16 -070051LSB_KEY_ARC_VERSION = 'CHROMEOS_ARC_VERSION'
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090052LSB_KEY_ARC_ANDROID_SDK_VERSION = 'CHROMEOS_ARC_ANDROID_SDK_VERSION'
Steve Fung67ef9462015-05-21 03:37:06 -070053
Steve Fung977460a2015-05-31 23:25:33 -070054CANARY_APP_ID = "{90F229CE-83E2-4FAF-8479-E368A34938B1}"
Steve Fung67ef9462015-05-21 03:37:06 -070055
56def _ParseArguments(argv):
57 parser = commandline.ArgumentParser(description=__doc__)
58
Steve Fung977460a2015-05-31 23:25:33 -070059 parser.add_argument('--app_id', default=None,
60 help='The APP_ID to install.')
Steve Fung67ef9462015-05-21 03:37:06 -070061 parser.add_argument('--board', help='The board name.', required=True)
62 parser.add_argument('--sysroot', required=True, type='path',
63 help='The sysroot to install the lsb-release file into.')
64 parser.add_argument('--version_string', required=True,
65 help='The image\'s version string.')
xixuan745999f2016-08-03 19:20:30 -070066 parser.add_argument('--builder_path', default=None,
67 help='The image\'s builder path.')
Steve Fung67ef9462015-05-21 03:37:06 -070068 parser.add_argument('--auserver', default=None,
69 help='The auserver url to use.')
70 parser.add_argument('--devserver', default=None,
71 help='The devserver url to use.')
72 parser.add_argument('--official', action='store_true',
73 help='Whether or not to populate with fields for an '
74 'official image.')
75 parser.add_argument('--buildbot_build', default='N/A',
76 help='The build number, for use with the continuous '
77 'builder.')
78 parser.add_argument('--track', default='developer-build',
79 help='The type of release track.')
80 parser.add_argument('--branch_number', default='0',
81 help='The branch number.')
82 parser.add_argument('--build_number', default='0',
83 help='The build number.')
84 parser.add_argument('--chrome_milestone', default='0',
85 help='The Chrome milestone.')
86 parser.add_argument('--patch_number', default='0',
87 help='The patch number for the given branch.')
Elijah Taylore9e3a822016-03-29 16:55:16 -070088 parser.add_argument('--arc_version', default=None,
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090089 help='Android revision number of ARC.')
90 parser.add_argument('--arc_android_sdk_version', default=None,
91 help='Android SDK version of ARC.')
Steve Fung67ef9462015-05-21 03:37:06 -070092
93 opts = parser.parse_args(argv)
94
95 # If the auserver or devserver isn't specified or is set to blank, set it
96 # to the host's hostname.
97 hostname = cros_build_lib.GetHostName(fully_qualified=True)
98
99 if not opts.auserver:
100 opts.auserver = 'http://%s:8080/update' % hostname
101
102 if not opts.devserver:
103 opts.devserver = 'http://%s:8080' % hostname
104
105 opts.Freeze()
106
107 if not os.path.isdir(opts.sysroot):
108 cros_build_lib.Die('The target sysroot does not exist: %s' % opts.sysroot)
109
110 if not opts.version_string:
111 cros_build_lib.Die('version_string must not be empty. Was '
112 'chromeos_version.sh sourced correctly in the calling '
113 'script?')
114
115 return opts
116
117
118def main(argv):
119 opts = _ParseArguments(argv)
120
121 fields = {
122 LSB_KEY_NAME: 'Chromium OS',
123 LSB_KEY_AUSERVER: opts.auserver,
124 LSB_KEY_DEVSERVER: opts.devserver,
125 }
126
Steve Fung977460a2015-05-31 23:25:33 -0700127 if opts.app_id is not None:
128 fields.update({
129 LSB_KEY_APPID_RELEASE: opts.app_id,
130 LSB_KEY_APPID_BOARD: opts.app_id,
131 LSB_KEY_APPID_CANARY: CANARY_APP_ID,
132 })
133
Elijah Taylore9e3a822016-03-29 16:55:16 -0700134 if opts.arc_version is not None:
135 fields.update({
136 LSB_KEY_ARC_VERSION: opts.arc_version,
137 })
138
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +0900139 if opts.arc_android_sdk_version is not None:
140 fields.update({
141 LSB_KEY_ARC_ANDROID_SDK_VERSION: opts.arc_android_sdk_version,
142 })
143
xixuan745999f2016-08-03 19:20:30 -0700144 if opts.builder_path is not None:
145 fields.update({
146 LSB_KEY_BUILDER_PATH: opts.builder_path,
147 })
148
Steve Fung67ef9462015-05-21 03:37:06 -0700149 if opts.official:
150 # Official builds (i.e. buildbot).
151 track = 'dev-channel'
152 build_type = 'Official Build'
153 fields.update({
154 LSB_KEY_TRACK: track,
155 LSB_KEY_NAME: 'Chrome OS',
156 LSB_KEY_BUILD_TYPE: build_type,
157 LSB_KEY_DESCRIPTION: ('%s (%s) %s %s test' %
158 (opts.version_string,
159 build_type,
160 track,
161 opts.board)),
162 LSB_KEY_AUSERVER: 'https://tools.google.com/service/update2',
163 LSB_KEY_DEVSERVER: '',
164 })
165 elif getpass.getuser() == 'chrome-bot':
166 # Continuous builder.
167 build_type = 'Continuous Builder - Builder: %s' % opts.buildbot_build
168 fields.update({
169 LSB_KEY_TRACK: 'buildbot-build',
170 LSB_KEY_BUILD_TYPE: build_type,
171 LSB_KEY_DESCRIPTION: '%s (%s) %s' % (opts.version_string,
172 build_type,
173 opts.board),
174 })
175 else:
176 # Developer manual builds.
177 build_type = 'Developer Build - %s' % getpass.getuser()
178 fields.update({
179 LSB_KEY_TRACK: opts.track,
180 LSB_KEY_BUILD_TYPE: build_type,
181 LSB_KEY_DESCRIPTION: '%s (%s) %s %s' % (opts.version_string,
182 build_type,
183 opts.track,
184 opts.board),
185 })
186
187 fields.update({
188 LSB_KEY_BOARD: opts.board,
189 LSB_KEY_BRANCH_NUMBER: opts.branch_number,
190 LSB_KEY_BUILD_NUMBER: opts.build_number,
191 LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone,
192 LSB_KEY_PATCH_NUMBER: opts.patch_number,
193 LSB_KEY_VERSION: opts.version_string,
194 LSB_KEY_GOOGLE_RELEASE: opts.version_string,
195 })
196
197 image_lib.WriteLsbRelease(opts.sysroot, fields)