blob: ba20cf61c29d050823f3228542010a0444a7fc5d [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.
33# TODO(skrul): Remove GOOGLE_RELEASE once Chromium is updated to look at
34# CHROMEOS_RELEASE_VERSION for UserAgent data.
35LSB_KEY_NAME = 'CHROMEOS_RELEASE_NAME'
36LSB_KEY_AUSERVER = 'CHROMEOS_AUSERVER'
37LSB_KEY_DEVSERVER = 'CHROMEOS_DEVSERVER'
38LSB_KEY_TRACK = 'CHROMEOS_RELEASE_TRACK'
39LSB_KEY_BUILD_TYPE = 'CHROMEOS_RELEASE_BUILD_TYPE'
40LSB_KEY_DESCRIPTION = 'CHROMEOS_RELEASE_DESCRIPTION'
41LSB_KEY_BOARD = 'CHROMEOS_RELEASE_BOARD'
Simon Glass8d8e38b2017-03-02 15:03:35 -070042LSB_KEY_MODELS = 'CHROMEOS_RELEASE_MODELS'
43LSB_KEY_UNIBUILD = 'CHROMEOS_RELEASE_UNIBUILD'
Steve Fung67ef9462015-05-21 03:37:06 -070044LSB_KEY_BRANCH_NUMBER = 'CHROMEOS_RELEASE_BRANCH_NUMBER'
45LSB_KEY_BUILD_NUMBER = 'CHROMEOS_RELEASE_BUILD_NUMBER'
46LSB_KEY_CHROME_MILESTONE = 'CHROMEOS_RELEASE_CHROME_MILESTONE'
47LSB_KEY_PATCH_NUMBER = 'CHROMEOS_RELEASE_PATCH_NUMBER'
48LSB_KEY_VERSION = 'CHROMEOS_RELEASE_VERSION'
xixuan745999f2016-08-03 19:20:30 -070049LSB_KEY_BUILDER_PATH = 'CHROMEOS_RELEASE_BUILDER_PATH'
Steve Fung67ef9462015-05-21 03:37:06 -070050LSB_KEY_GOOGLE_RELEASE = 'GOOGLE_RELEASE'
Steve Fung977460a2015-05-31 23:25:33 -070051LSB_KEY_APPID_RELEASE = 'CHROMEOS_RELEASE_APPID'
52LSB_KEY_APPID_BOARD = 'CHROMEOS_BOARD_APPID'
53LSB_KEY_APPID_CANARY = 'CHROMEOS_CANARY_APPID'
Elijah Taylore9e3a822016-03-29 16:55:16 -070054LSB_KEY_ARC_VERSION = 'CHROMEOS_ARC_VERSION'
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090055LSB_KEY_ARC_ANDROID_SDK_VERSION = 'CHROMEOS_ARC_ANDROID_SDK_VERSION'
Steve Fung67ef9462015-05-21 03:37:06 -070056
Steve Fung977460a2015-05-31 23:25:33 -070057CANARY_APP_ID = "{90F229CE-83E2-4FAF-8479-E368A34938B1}"
Steve Fung67ef9462015-05-21 03:37:06 -070058
59def _ParseArguments(argv):
60 parser = commandline.ArgumentParser(description=__doc__)
61
Steve Fung977460a2015-05-31 23:25:33 -070062 parser.add_argument('--app_id', default=None,
63 help='The APP_ID to install.')
Steve Fung67ef9462015-05-21 03:37:06 -070064 parser.add_argument('--board', help='The board name.', required=True)
Simon Glass8d8e38b2017-03-02 15:03:35 -070065 parser.add_argument('--models',
66 help='Models supported by this board, space-separated')
Steve Fung67ef9462015-05-21 03:37:06 -070067 parser.add_argument('--sysroot', required=True, type='path',
68 help='The sysroot to install the lsb-release file into.')
69 parser.add_argument('--version_string', required=True,
70 help='The image\'s version string.')
xixuan745999f2016-08-03 19:20:30 -070071 parser.add_argument('--builder_path', default=None,
72 help='The image\'s builder path.')
Steve Fung67ef9462015-05-21 03:37:06 -070073 parser.add_argument('--auserver', default=None,
74 help='The auserver url to use.')
75 parser.add_argument('--devserver', default=None,
76 help='The devserver url to use.')
77 parser.add_argument('--official', action='store_true',
78 help='Whether or not to populate with fields for an '
79 'official image.')
80 parser.add_argument('--buildbot_build', default='N/A',
81 help='The build number, for use with the continuous '
82 'builder.')
83 parser.add_argument('--track', default='developer-build',
84 help='The type of release track.')
85 parser.add_argument('--branch_number', default='0',
86 help='The branch number.')
87 parser.add_argument('--build_number', default='0',
88 help='The build number.')
89 parser.add_argument('--chrome_milestone', default='0',
90 help='The Chrome milestone.')
91 parser.add_argument('--patch_number', default='0',
92 help='The patch number for the given branch.')
Elijah Taylore9e3a822016-03-29 16:55:16 -070093 parser.add_argument('--arc_version', default=None,
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +090094 help='Android revision number of ARC.')
95 parser.add_argument('--arc_android_sdk_version', default=None,
96 help='Android SDK version of ARC.')
Steve Fung67ef9462015-05-21 03:37:06 -070097
98 opts = parser.parse_args(argv)
99
100 # If the auserver or devserver isn't specified or is set to blank, set it
101 # to the host's hostname.
102 hostname = cros_build_lib.GetHostName(fully_qualified=True)
103
104 if not opts.auserver:
105 opts.auserver = 'http://%s:8080/update' % hostname
106
107 if not opts.devserver:
108 opts.devserver = 'http://%s:8080' % hostname
109
110 opts.Freeze()
111
112 if not os.path.isdir(opts.sysroot):
113 cros_build_lib.Die('The target sysroot does not exist: %s' % opts.sysroot)
114
115 if not opts.version_string:
116 cros_build_lib.Die('version_string must not be empty. Was '
117 'chromeos_version.sh sourced correctly in the calling '
118 'script?')
119
120 return opts
121
122
123def main(argv):
124 opts = _ParseArguments(argv)
125
126 fields = {
127 LSB_KEY_NAME: 'Chromium OS',
128 LSB_KEY_AUSERVER: opts.auserver,
129 LSB_KEY_DEVSERVER: opts.devserver,
130 }
131
Steve Fung977460a2015-05-31 23:25:33 -0700132 if opts.app_id is not None:
133 fields.update({
134 LSB_KEY_APPID_RELEASE: opts.app_id,
135 LSB_KEY_APPID_BOARD: opts.app_id,
136 LSB_KEY_APPID_CANARY: CANARY_APP_ID,
137 })
138
Elijah Taylore9e3a822016-03-29 16:55:16 -0700139 if opts.arc_version is not None:
140 fields.update({
141 LSB_KEY_ARC_VERSION: opts.arc_version,
142 })
143
Shuhei Takahashi50fd9e72017-01-27 16:00:34 +0900144 if opts.arc_android_sdk_version is not None:
145 fields.update({
146 LSB_KEY_ARC_ANDROID_SDK_VERSION: opts.arc_android_sdk_version,
147 })
148
xixuan745999f2016-08-03 19:20:30 -0700149 if opts.builder_path is not None:
150 fields.update({
151 LSB_KEY_BUILDER_PATH: opts.builder_path,
152 })
153
Simon Glass8d8e38b2017-03-02 15:03:35 -0700154 board_and_models = opts.board
155 if opts.models:
156 board_and_models += '-unibuild (%s)' % opts.models
Steve Fung67ef9462015-05-21 03:37:06 -0700157 if opts.official:
158 # Official builds (i.e. buildbot).
159 track = 'dev-channel'
160 build_type = 'Official Build'
161 fields.update({
162 LSB_KEY_TRACK: track,
163 LSB_KEY_NAME: 'Chrome OS',
164 LSB_KEY_BUILD_TYPE: build_type,
165 LSB_KEY_DESCRIPTION: ('%s (%s) %s %s test' %
166 (opts.version_string,
167 build_type,
168 track,
Simon Glass8d8e38b2017-03-02 15:03:35 -0700169 board_and_models)),
Steve Fung67ef9462015-05-21 03:37:06 -0700170 LSB_KEY_AUSERVER: 'https://tools.google.com/service/update2',
171 LSB_KEY_DEVSERVER: '',
172 })
173 elif getpass.getuser() == 'chrome-bot':
174 # Continuous builder.
175 build_type = 'Continuous Builder - Builder: %s' % opts.buildbot_build
176 fields.update({
177 LSB_KEY_TRACK: 'buildbot-build',
178 LSB_KEY_BUILD_TYPE: build_type,
179 LSB_KEY_DESCRIPTION: '%s (%s) %s' % (opts.version_string,
180 build_type,
Simon Glass8d8e38b2017-03-02 15:03:35 -0700181 board_and_models),
Steve Fung67ef9462015-05-21 03:37:06 -0700182 })
183 else:
184 # Developer manual builds.
185 build_type = 'Developer Build - %s' % getpass.getuser()
186 fields.update({
187 LSB_KEY_TRACK: opts.track,
188 LSB_KEY_BUILD_TYPE: build_type,
189 LSB_KEY_DESCRIPTION: '%s (%s) %s %s' % (opts.version_string,
190 build_type,
191 opts.track,
Simon Glass8d8e38b2017-03-02 15:03:35 -0700192 board_and_models),
Steve Fung67ef9462015-05-21 03:37:06 -0700193 })
194
195 fields.update({
196 LSB_KEY_BOARD: opts.board,
197 LSB_KEY_BRANCH_NUMBER: opts.branch_number,
198 LSB_KEY_BUILD_NUMBER: opts.build_number,
199 LSB_KEY_CHROME_MILESTONE: opts.chrome_milestone,
200 LSB_KEY_PATCH_NUMBER: opts.patch_number,
201 LSB_KEY_VERSION: opts.version_string,
202 LSB_KEY_GOOGLE_RELEASE: opts.version_string,
203 })
Simon Glass8d8e38b2017-03-02 15:03:35 -0700204 if opts.models:
205 fields[LSB_KEY_UNIBUILD] = '1'
206 fields[LSB_KEY_MODELS] = opts.models
Steve Fung67ef9462015-05-21 03:37:06 -0700207
208 image_lib.WriteLsbRelease(opts.sysroot, fields)