blob: 31cf98c8ddd3ecca097dd96b9b7f91040a324935 [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'
Steve Fung67ef9462015-05-21 03:37:06 -070052
Steve Fung977460a2015-05-31 23:25:33 -070053CANARY_APP_ID = "{90F229CE-83E2-4FAF-8479-E368A34938B1}"
Steve Fung67ef9462015-05-21 03:37:06 -070054
55def _ParseArguments(argv):
56 parser = commandline.ArgumentParser(description=__doc__)
57
Steve Fung977460a2015-05-31 23:25:33 -070058 parser.add_argument('--app_id', default=None,
59 help='The APP_ID to install.')
Steve Fung67ef9462015-05-21 03:37:06 -070060 parser.add_argument('--board', help='The board name.', required=True)
61 parser.add_argument('--sysroot', required=True, type='path',
62 help='The sysroot to install the lsb-release file into.')
63 parser.add_argument('--version_string', required=True,
64 help='The image\'s version string.')
xixuan745999f2016-08-03 19:20:30 -070065 parser.add_argument('--builder_path', default=None,
66 help='The image\'s builder path.')
Steve Fung67ef9462015-05-21 03:37:06 -070067 parser.add_argument('--auserver', default=None,
68 help='The auserver url to use.')
69 parser.add_argument('--devserver', default=None,
70 help='The devserver url to use.')
71 parser.add_argument('--official', action='store_true',
72 help='Whether or not to populate with fields for an '
73 'official image.')
74 parser.add_argument('--buildbot_build', default='N/A',
75 help='The build number, for use with the continuous '
76 'builder.')
77 parser.add_argument('--track', default='developer-build',
78 help='The type of release track.')
79 parser.add_argument('--branch_number', default='0',
80 help='The branch number.')
81 parser.add_argument('--build_number', default='0',
82 help='The build number.')
83 parser.add_argument('--chrome_milestone', default='0',
84 help='The Chrome milestone.')
85 parser.add_argument('--patch_number', default='0',
86 help='The patch number for the given branch.')
Elijah Taylore9e3a822016-03-29 16:55:16 -070087 parser.add_argument('--arc_version', default=None,
88 help='The ARC version.')
Steve Fung67ef9462015-05-21 03:37:06 -070089
90 opts = parser.parse_args(argv)
91
92 # If the auserver or devserver isn't specified or is set to blank, set it
93 # to the host's hostname.
94 hostname = cros_build_lib.GetHostName(fully_qualified=True)
95
96 if not opts.auserver:
97 opts.auserver = 'http://%s:8080/update' % hostname
98
99 if not opts.devserver:
100 opts.devserver = 'http://%s:8080' % hostname
101
102 opts.Freeze()
103
104 if not os.path.isdir(opts.sysroot):
105 cros_build_lib.Die('The target sysroot does not exist: %s' % opts.sysroot)
106
107 if not opts.version_string:
108 cros_build_lib.Die('version_string must not be empty. Was '
109 'chromeos_version.sh sourced correctly in the calling '
110 'script?')
111
112 return opts
113
114
115def main(argv):
116 opts = _ParseArguments(argv)
117
118 fields = {
119 LSB_KEY_NAME: 'Chromium OS',
120 LSB_KEY_AUSERVER: opts.auserver,
121 LSB_KEY_DEVSERVER: opts.devserver,
122 }
123
Steve Fung977460a2015-05-31 23:25:33 -0700124 if opts.app_id is not None:
125 fields.update({
126 LSB_KEY_APPID_RELEASE: opts.app_id,
127 LSB_KEY_APPID_BOARD: opts.app_id,
128 LSB_KEY_APPID_CANARY: CANARY_APP_ID,
129 })
130
Elijah Taylore9e3a822016-03-29 16:55:16 -0700131 if opts.arc_version is not None:
132 fields.update({
133 LSB_KEY_ARC_VERSION: opts.arc_version,
134 })
135
xixuan745999f2016-08-03 19:20:30 -0700136 if opts.builder_path is not None:
137 fields.update({
138 LSB_KEY_BUILDER_PATH: opts.builder_path,
139 })
140
Steve Fung67ef9462015-05-21 03:37:06 -0700141 if opts.official:
142 # Official builds (i.e. buildbot).
143 track = 'dev-channel'
144 build_type = 'Official Build'
145 fields.update({
146 LSB_KEY_TRACK: track,
147 LSB_KEY_NAME: 'Chrome OS',
148 LSB_KEY_BUILD_TYPE: build_type,
149 LSB_KEY_DESCRIPTION: ('%s (%s) %s %s test' %
150 (opts.version_string,
151 build_type,
152 track,
153 opts.board)),
154 LSB_KEY_AUSERVER: 'https://tools.google.com/service/update2',
155 LSB_KEY_DEVSERVER: '',
156 })
157 elif getpass.getuser() == 'chrome-bot':
158 # Continuous builder.
159 build_type = 'Continuous Builder - Builder: %s' % opts.buildbot_build
160 fields.update({
161 LSB_KEY_TRACK: 'buildbot-build',
162 LSB_KEY_BUILD_TYPE: build_type,
163 LSB_KEY_DESCRIPTION: '%s (%s) %s' % (opts.version_string,
164 build_type,
165 opts.board),
166 })
167 else:
168 # Developer manual builds.
169 build_type = 'Developer Build - %s' % getpass.getuser()
170 fields.update({
171 LSB_KEY_TRACK: opts.track,
172 LSB_KEY_BUILD_TYPE: build_type,
173 LSB_KEY_DESCRIPTION: '%s (%s) %s %s' % (opts.version_string,
174 build_type,
175 opts.track,
176 opts.board),
177 })
178
179 fields.update({
180 LSB_KEY_BOARD: opts.board,
181 LSB_KEY_BRANCH_NUMBER: opts.branch_number,
182 LSB_KEY_BUILD_NUMBER: opts.build_number,
183 LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone,
184 LSB_KEY_PATCH_NUMBER: opts.patch_number,
185 LSB_KEY_VERSION: opts.version_string,
186 LSB_KEY_GOOGLE_RELEASE: opts.version_string,
187 })
188
189 image_lib.WriteLsbRelease(opts.sysroot, fields)