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