Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2012 The ChromiumOS Authors |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Brian Harring | af019fb | 2012-05-10 15:06:13 -0700 | [diff] [blame] | 5 | """This script is used to upload host prebuilts as well as board BINHOSTS. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 6 | |
David James | 015af87 | 2012-06-19 15:24:36 -0700 | [diff] [blame] | 7 | Prebuilts are uploaded using gsutil to Google Storage. After these prebuilts |
| 8 | are successfully uploaded, a file is updated with the proper BINHOST version. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 9 | |
| 10 | To read more about prebuilts/binhost binary packages please refer to: |
David James | 015af87 | 2012-06-19 15:24:36 -0700 | [diff] [blame] | 11 | http://goto/chromeos-prebuilts |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 12 | |
| 13 | Example of uploading prebuilt amd64 host files to Google Storage: |
Mike Nichols | d0acc7f | 2021-05-21 17:18:24 +0000 | [diff] [blame] | 14 | upload_prebuilts -p /b/cbuild/build -s -u gs://chromeos-prebuilt |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 15 | |
| 16 | Example of uploading x86-dogfood binhosts to Google Storage: |
Mike Nichols | d0acc7f | 2021-05-21 17:18:24 +0000 | [diff] [blame] | 17 | upload_prebuilts -b x86-dogfood -p /b/cbuild/build/ -u gs://chromeos-prebuilt -g |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 18 | """ |
| 19 | |
Mike Frysinger | b87bb78 | 2015-06-04 02:46:50 -0400 | [diff] [blame] | 20 | import argparse |
Chris Sosa | 1dc9613 | 2012-05-11 15:40:50 -0700 | [diff] [blame] | 21 | import datetime |
Mike Frysinger | 540883b | 2014-05-24 13:46:16 -0400 | [diff] [blame] | 22 | import functools |
David James | b26b931 | 2014-12-15 11:26:46 -0800 | [diff] [blame] | 23 | import glob |
Chris McDonald | b55b703 | 2021-06-17 16:41:32 -0600 | [diff] [blame] | 24 | import logging |
Chris Sosa | 1dc9613 | 2012-05-11 15:40:50 -0700 | [diff] [blame] | 25 | import multiprocessing |
Chris Sosa | 1dc9613 | 2012-05-11 15:40:50 -0700 | [diff] [blame] | 26 | import os |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 27 | from pathlib import Path |
Mike Frysinger | 212e429 | 2014-05-24 15:15:44 -0400 | [diff] [blame] | 28 | import tempfile |
Greg Edelston | 325e441 | 2023-05-04 16:22:10 -0600 | [diff] [blame] | 29 | from typing import Optional, Tuple |
Chris Sosa | 1dc9613 | 2012-05-11 15:40:50 -0700 | [diff] [blame] | 30 | |
Chris McDonald | b55b703 | 2021-06-17 16:41:32 -0600 | [diff] [blame] | 31 | from chromite.cbuildbot import cbuildbot_alerts |
David James | 14e9777 | 2014-06-04 18:44:49 -0700 | [diff] [blame] | 32 | from chromite.cbuildbot import commands |
David James | 6450a0a | 2012-12-04 07:59:53 -0800 | [diff] [blame] | 33 | from chromite.lib import binpkg |
Mike Frysinger | 8650923 | 2014-05-24 13:18:37 -0400 | [diff] [blame] | 34 | from chromite.lib import commandline |
Chris McDonald | b55b703 | 2021-06-17 16:41:32 -0600 | [diff] [blame] | 35 | from chromite.lib import constants |
Chris Sosa | 1dc9613 | 2012-05-11 15:40:50 -0700 | [diff] [blame] | 36 | from chromite.lib import cros_build_lib |
Mike Frysinger | 807d828 | 2022-04-28 22:45:17 -0400 | [diff] [blame] | 37 | from chromite.lib import git |
Brian Harring | 7904b48 | 2012-08-08 02:54:12 -0700 | [diff] [blame] | 38 | from chromite.lib import gs |
Brian Harring | af019fb | 2012-05-10 15:06:13 -0700 | [diff] [blame] | 39 | from chromite.lib import osutils |
David James | 6450a0a | 2012-12-04 07:59:53 -0800 | [diff] [blame] | 40 | from chromite.lib import parallel |
Alex Deymo | 075c229 | 2014-09-04 18:31:50 -0700 | [diff] [blame] | 41 | from chromite.lib import portage_util |
Mike Frysinger | 8e727a3 | 2013-01-16 16:57:53 -0500 | [diff] [blame] | 42 | from chromite.lib import toolchain |
Alex Klein | 18a60af | 2020-06-11 12:08:47 -0600 | [diff] [blame] | 43 | from chromite.lib.parser import package_info |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 44 | from chromite.utils import pformat |
Chris Sosa | 1dc9613 | 2012-05-11 15:40:50 -0700 | [diff] [blame] | 45 | |
Mike Frysinger | 72b7cf9 | 2020-04-19 06:00:51 -0400 | [diff] [blame] | 46 | |
David James | 015af87 | 2012-06-19 15:24:36 -0700 | [diff] [blame] | 47 | # How many times to retry uploads. |
| 48 | _RETRIES = 10 |
| 49 | |
| 50 | # Multiplier for how long to sleep (in seconds) between retries; will delay |
| 51 | # (1*sleep) the first time, then (2*sleep), continuing via attempt * sleep. |
| 52 | _SLEEP_TIME = 60 |
| 53 | |
David James | 5ab67e3 | 2014-10-24 08:19:59 -0700 | [diff] [blame] | 54 | # The length of time (in seconds) that Portage should wait before refetching |
| 55 | # binpkgs from the same binhost. We don't ever modify binhosts, so this should |
| 56 | # be something big. |
| 57 | _BINPKG_TTL = 60 * 60 * 24 * 365 |
| 58 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 59 | _HOST_PACKAGES_PATH = "var/lib/portage/pkgs" |
| 60 | _CATEGORIES_PATH = "chroot/etc/portage/categories" |
| 61 | _PYM_PATH = "chroot/usr/lib/portage/pym" |
| 62 | _HOST_ARCH = "amd64" |
| 63 | _BOARD_PATH = "chroot/build/%(board)s" |
| 64 | _REL_BOARD_PATH = "board/%(target)s/%(version)s" |
| 65 | _REL_HOST_PATH = "host/%(host_arch)s/%(target)s/%(version)s" |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 66 | # Private overlays to look at for builds to filter |
| 67 | # relative to build path |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 68 | _PRIVATE_OVERLAY_DIR = "src/private-overlays" |
| 69 | _GOOGLESTORAGE_GSUTIL_FILE = "googlestorage_acl.txt" |
| 70 | _BINHOST_BASE_URL = "gs://chromeos-prebuilt" |
| 71 | _PREBUILT_BASE_DIR = "src/third_party/chromiumos-overlay/chromeos/config/" |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 72 | # Created in the event of new host targets becoming available |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 73 | _PREBUILT_MAKE_CONF = { |
| 74 | "amd64": os.path.join(_PREBUILT_BASE_DIR, "make.conf.amd64-host") |
| 75 | } |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 76 | |
| 77 | |
David James | 4058b0d | 2011-12-08 21:24:50 -0800 | [diff] [blame] | 78 | class BuildTarget(object): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 79 | """A board/variant/profile tuple.""" |
David James | 4058b0d | 2011-12-08 21:24:50 -0800 | [diff] [blame] | 80 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 81 | def __init__(self, board_variant, profile=None): |
| 82 | self.board_variant = board_variant |
| 83 | self.board, _, self.variant = board_variant.partition("_") |
| 84 | self.profile = profile |
David James | 4058b0d | 2011-12-08 21:24:50 -0800 | [diff] [blame] | 85 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 86 | def __str__(self): |
| 87 | if self.profile: |
| 88 | return "%s_%s" % (self.board_variant, self.profile) |
| 89 | else: |
| 90 | return self.board_variant |
David James | 4058b0d | 2011-12-08 21:24:50 -0800 | [diff] [blame] | 91 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 92 | def __eq__(self, other): |
| 93 | return str(other) == str(self) |
David James | 4058b0d | 2011-12-08 21:24:50 -0800 | [diff] [blame] | 94 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 95 | def __hash__(self): |
| 96 | return hash(str(self)) |
David James | 4058b0d | 2011-12-08 21:24:50 -0800 | [diff] [blame] | 97 | |
| 98 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 99 | def GetVersion(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 100 | """Get the version to put in LATEST and update the git version with.""" |
| 101 | return datetime.datetime.now().strftime("%Y.%m.%d.%H%M%S") |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 102 | |
| 103 | |
Mike Frysinger | 540883b | 2014-05-24 13:46:16 -0400 | [diff] [blame] | 104 | def _GsUpload(gs_context, acl, local_file, remote_file): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 105 | """Upload to GS bucket. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 106 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 107 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 108 | gs_context: A lib.gs.GSContext instance. |
| 109 | acl: The ACL to use for uploading the file. |
| 110 | local_file: The local file to be uploaded. |
| 111 | remote_file: The remote location to upload to. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 112 | """ |
| 113 | CANNED_ACLS = [ |
| 114 | "public-read", |
| 115 | "private", |
| 116 | "bucket-owner-read", |
| 117 | "authenticated-read", |
| 118 | "bucket-owner-full-control", |
| 119 | "public-read-write", |
| 120 | ] |
| 121 | if acl in CANNED_ACLS: |
| 122 | gs_context.Copy(local_file, remote_file, acl=acl) |
Gabe Black | 40169e6 | 2014-06-17 15:23:47 -0700 | [diff] [blame] | 123 | else: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 124 | # For private uploads we assume that the overlay board is set up |
| 125 | # properly and a googlestore_acl.xml is present. Otherwise, this script |
| 126 | # errors. We set version=0 here to ensure that the ACL is set only once |
| 127 | # (see http://b/15883752#comment54). |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 128 | try: |
| 129 | gs_context.Copy(local_file, remote_file, version=0) |
| 130 | except gs.GSContextPreconditionFailed as ex: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 131 | # If we received a GSContextPreconditionFailed error, we know that |
| 132 | # the file exists now, but we don't know whether our specific update |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 133 | # succeeded. See http://b/15883752#comment62 |
| 134 | logging.warning( |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 135 | "Assuming upload succeeded despite PreconditionFailed errors: " |
| 136 | "%s", |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 137 | ex, |
| 138 | ) |
| 139 | |
| 140 | if acl.endswith(".xml"): |
| 141 | # Apply the passed in ACL xml file to the uploaded object. |
| 142 | gs_context.SetACL(remote_file, acl=acl) |
| 143 | else: |
| 144 | gs_context.ChangeACL(remote_file, acl_args_file=acl) |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 145 | |
Mike Frysinger | cc83883 | 2014-05-24 13:10:30 -0400 | [diff] [blame] | 146 | |
Mike Frysinger | 540883b | 2014-05-24 13:46:16 -0400 | [diff] [blame] | 147 | def RemoteUpload(gs_context, acl, files, pool=10): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 148 | """Upload to google storage. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 149 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 150 | Create a pool of process and call _GsUpload with the proper arguments. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 151 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 152 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 153 | gs_context: A lib.gs.GSContext instance. |
| 154 | acl: The canned acl used for uploading. acl can be one of: |
| 155 | "public-read", "public-read-write", "authenticated-read", |
| 156 | "bucket-owner-read", "bucket-owner-full-control", or "private". |
| 157 | files: dictionary with keys to local files and values to remote path. |
| 158 | pool: integer of maximum processes to have at the same time. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 159 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 160 | Returns: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 161 | Return a set of tuple arguments of the failed uploads |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 162 | """ |
| 163 | upload = functools.partial(_GsUpload, gs_context, acl) |
| 164 | tasks = [[key, value] for key, value in files.items()] |
| 165 | parallel.RunTasksInProcessPool(upload, tasks, pool) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 166 | |
| 167 | |
| 168 | def GenerateUploadDict(base_local_path, base_remote_path, pkgs): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 169 | """Build a dictionary of local remote file key pairs to upload. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 170 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 171 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 172 | base_local_path: The base path to the files on the local hard drive. |
| 173 | base_remote_path: The base path to the remote paths. |
| 174 | pkgs: The packages to upload. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 175 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 176 | Returns: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 177 | Returns a dictionary of local_path/remote_path pairs |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 178 | """ |
| 179 | upload_files = {} |
| 180 | for pkg in pkgs: |
| 181 | suffix = pkg["CPV"] + ".tbz2" |
| 182 | local_path = os.path.join(base_local_path, suffix) |
| 183 | assert os.path.exists(local_path), "%s does not exist" % local_path |
| 184 | upload_files[local_path] = os.path.join(base_remote_path, suffix) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 185 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 186 | if pkg.get("DEBUG_SYMBOLS") == "yes": |
| 187 | debugsuffix = pkg["CPV"] + ".debug.tbz2" |
| 188 | local_path = os.path.join(base_local_path, debugsuffix) |
| 189 | assert os.path.exists(local_path) |
| 190 | upload_files[local_path] = os.path.join( |
| 191 | base_remote_path, debugsuffix |
| 192 | ) |
Bertrand SIMONNET | 22e828b | 2014-11-11 16:27:06 -0800 | [diff] [blame] | 193 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 194 | return upload_files |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 195 | |
Mike Frysinger | cc83883 | 2014-05-24 13:10:30 -0400 | [diff] [blame] | 196 | |
Peter Mayo | 950e41a | 2014-02-06 21:07:33 +0000 | [diff] [blame] | 197 | def GetBoardOverlay(build_path, target): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 198 | """Get the path to the board variant. |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 199 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 200 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 201 | build_path: The path to the root of the build directory. |
| 202 | target: The target board as a BuildTarget object. |
Mike Frysinger | 1a736a8 | 2013-12-12 01:50:59 -0500 | [diff] [blame] | 203 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 204 | Returns: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 205 | The last overlay configured for the given board as a string. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 206 | """ |
| 207 | board = target.board_variant |
| 208 | overlays = portage_util.FindOverlays( |
| 209 | constants.BOTH_OVERLAYS, board, buildroot=build_path |
| 210 | ) |
| 211 | # We only care about the last entry. |
| 212 | return overlays[-1] |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 213 | |
| 214 | |
| 215 | def DeterminePrebuiltConfFile(build_path, target): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 216 | """Determine the prebuilt.conf file that needs to be updated for prebuilts. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 217 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 218 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 219 | build_path: The path to the root of the build directory. |
| 220 | target: String representation of the board. This includes host and board |
| 221 | targets. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 222 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 223 | Returns: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 224 | A string path to a prebuilt.conf file to be updated. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 225 | """ |
| 226 | if _HOST_ARCH == target: |
| 227 | # We are host. |
| 228 | # Without more examples of hosts this is a kludge for now. |
| 229 | # TODO(Scottz): as new host targets come online expand this to |
| 230 | # work more like boards. |
| 231 | make_path = _PREBUILT_MAKE_CONF[target] |
| 232 | else: |
| 233 | # We are a board |
| 234 | board = GetBoardOverlay(build_path, target) |
| 235 | make_path = os.path.join(board, "prebuilt.conf") |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 236 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 237 | return make_path |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 238 | |
| 239 | |
Greg Edelston | adecc1b | 2023-03-22 17:00:42 -0600 | [diff] [blame] | 240 | def UpdateBinhostConfFile(filepath: str, key: str, value: str) -> None: |
| 241 | """Update binhost config file with key=value. |
| 242 | |
| 243 | The updated file will be committed, but not submitted. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 244 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 245 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 246 | filepath: Path to the key-value store file to update. |
| 247 | key: Key to update. |
| 248 | value: New value for key. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 249 | """ |
Greg Edelston | adecc1b | 2023-03-22 17:00:42 -0600 | [diff] [blame] | 250 | dirname, basename = os.path.split(os.path.abspath(filepath)) |
| 251 | osutils.SafeMakedirs(dirname) |
| 252 | if not git.GetCurrentBranch(dirname): |
| 253 | git.CreatePushBranch( |
| 254 | constants.STABLE_EBUILD_BRANCH, dirname, sync=False |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 255 | ) |
Greg Edelston | adecc1b | 2023-03-22 17:00:42 -0600 | [diff] [blame] | 256 | osutils.WriteFile(filepath, "", mode="a") |
| 257 | if binpkg.UpdateKeyInLocalFile(filepath, key, value): |
| 258 | desc = f"{basename}: {'updating' if value else 'clearing'} {key}" |
| 259 | git.AddPath(filepath) |
| 260 | git.Commit(dirname, desc) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 261 | |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 262 | |
Achuith Bhandarkar | 03d924a | 2018-01-02 10:50:44 -0800 | [diff] [blame] | 263 | def GenerateHtmlIndex(files, index, board, version, remote_location): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 264 | """Given the list of |files|, generate an index.html at |index|. |
Mike Frysinger | 212e429 | 2014-05-24 15:15:44 -0400 | [diff] [blame] | 265 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 266 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 267 | files: The list of files to link to. |
| 268 | index: The path to the html index. |
| 269 | board: Name of the board this index is for. |
| 270 | version: Build version this index is for. |
| 271 | remote_location: Remote gs location prebuilts are uploaded to. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 272 | """ |
| 273 | title = "Package Prebuilt Index: %s / %s" % (board, version) |
Mike Frysinger | 212e429 | 2014-05-24 15:15:44 -0400 | [diff] [blame] | 274 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 275 | files = files + [ |
| 276 | ".|Google Storage Index", |
| 277 | "..|", |
| 278 | ] |
| 279 | commands.GenerateHtmlIndex( |
| 280 | index, files, title=title, url_base=gs.GsUrlToHttp(remote_location) |
| 281 | ) |
Mike Frysinger | 212e429 | 2014-05-24 15:15:44 -0400 | [diff] [blame] | 282 | |
| 283 | |
David James | ce093af | 2011-02-23 15:21:58 -0800 | [diff] [blame] | 284 | def _GrabAllRemotePackageIndexes(binhost_urls): |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 285 | """Grab all the packages files associated with a list of binhost_urls. |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 286 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 287 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 288 | binhost_urls: The URLs for the directories containing the Packages files |
| 289 | we want to grab. |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 290 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 291 | Returns: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 292 | A list of PackageIndex objects. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 293 | """ |
| 294 | pkg_indexes = [] |
| 295 | for url in binhost_urls: |
| 296 | pkg_index = binpkg.GrabRemotePackageIndex(url) |
| 297 | if pkg_index: |
| 298 | pkg_indexes.append(pkg_index) |
| 299 | return pkg_indexes |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 300 | |
| 301 | |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 302 | class PrebuiltUploader(object): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 303 | """Synchronize host and board prebuilts.""" |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 304 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 305 | def __init__( |
| 306 | self, |
| 307 | upload_location, |
| 308 | acl, |
| 309 | binhost_base_url, |
| 310 | pkg_indexes, |
| 311 | build_path, |
| 312 | packages, |
| 313 | skip_upload, |
| 314 | binhost_conf_dir, |
| 315 | dryrun, |
| 316 | target, |
| 317 | slave_targets, |
| 318 | version, |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 319 | report, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 320 | chroot=None, |
| 321 | ): |
| 322 | """Constructor for prebuilt uploader object. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 323 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 324 | This object can upload host or prebuilt files to Google Storage. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 325 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 326 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 327 | upload_location: The upload location. |
| 328 | acl: The canned acl used for uploading to Google Storage. acl can be |
| 329 | one of: "public-read", "public-read-write", |
| 330 | "authenticated-read", "bucket-owner-read", |
| 331 | "bucket-owner-full-control", "project-private", or "private" |
| 332 | (see "gsutil help acls"). If we are not uploading to Google |
| 333 | Storage, this parameter is unused. |
| 334 | binhost_base_url: The URL used for downloading the prebuilts. |
| 335 | pkg_indexes: Old uploaded prebuilts to compare against. Instead of |
| 336 | uploading duplicate files, we just link to the old files. |
| 337 | build_path: The path to the directory containing the chroot. |
| 338 | packages: Packages to upload. |
| 339 | skip_upload: Don't actually upload the tarballs. |
| 340 | binhost_conf_dir: Directory where to store binhost.conf files. |
| 341 | dryrun: Don't push or upload prebuilts. |
| 342 | target: BuildTarget managed by this builder. |
| 343 | slave_targets: List of BuildTargets managed by slave builders. |
| 344 | version: A unique string, intended to be included in the upload |
| 345 | path, which identifies the version number of the uploaded |
| 346 | prebuilts. |
| 347 | report: Dict in which to collect information to report to the user. |
| 348 | chroot: Path to the chroot containing the prebuilts. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 349 | """ |
| 350 | self._upload_location = upload_location |
| 351 | self._acl = acl |
| 352 | self._binhost_base_url = binhost_base_url |
| 353 | self._pkg_indexes = pkg_indexes |
| 354 | self._build_path = build_path |
| 355 | self._packages = set(packages) |
| 356 | self._found_packages = set() |
| 357 | self._skip_upload = skip_upload |
| 358 | self._binhost_conf_dir = binhost_conf_dir |
| 359 | self._dryrun = dryrun |
| 360 | self._target = target |
| 361 | self._slave_targets = slave_targets |
| 362 | self._version = version |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 363 | self._report = report |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 364 | self._chroot = chroot or os.path.join( |
| 365 | build_path, constants.DEFAULT_CHROOT_DIR |
| 366 | ) |
| 367 | self._gs_context = gs.GSContext( |
| 368 | retries=_RETRIES, sleep=_SLEEP_TIME, dry_run=self._dryrun |
| 369 | ) |
Mike Frysinger | 540883b | 2014-05-24 13:46:16 -0400 | [diff] [blame] | 370 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 371 | def _Upload(self, local_file, remote_file): |
| 372 | """Wrapper around _GsUpload""" |
| 373 | _GsUpload(self._gs_context, self._acl, local_file, remote_file) |
David James | 615e5b5 | 2011-06-03 11:10:15 -0700 | [diff] [blame] | 374 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 375 | def _ShouldFilterPackage(self, pkg): |
| 376 | if not self._packages: |
| 377 | return False |
| 378 | cpv = package_info.SplitCPV(pkg["CPV"]) |
| 379 | self._found_packages.add(cpv.cp) |
| 380 | return ( |
| 381 | cpv.package not in self._packages and cpv.cp not in self._packages |
| 382 | ) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 383 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 384 | def _UploadPrebuilt(self, package_path, url_suffix): |
| 385 | """Upload host or board prebuilt files to Google Storage space. |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 386 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 387 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 388 | package_path: The path to the packages dir. |
| 389 | url_suffix: The remote subdirectory where we should upload the |
| 390 | packages. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 391 | """ |
| 392 | # Process Packages file, removing duplicates and filtered packages. |
| 393 | pkg_index = binpkg.GrabLocalPackageIndex(package_path) |
| 394 | pkg_index.SetUploadLocation(self._binhost_base_url, url_suffix) |
| 395 | pkg_index.RemoveFilteredPackages(self._ShouldFilterPackage) |
| 396 | uploads = pkg_index.ResolveDuplicateUploads(self._pkg_indexes) |
| 397 | unmatched_pkgs = self._packages - self._found_packages |
| 398 | if unmatched_pkgs: |
| 399 | logging.warning("unable to match packages: %r", unmatched_pkgs) |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 400 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 401 | # Write Packages file. |
| 402 | pkg_index.header["TTL"] = _BINPKG_TTL |
| 403 | tmp_packages_file = pkg_index.WriteToNamedTemporaryFile() |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 404 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 405 | remote_location = "%s/%s" % ( |
| 406 | self._upload_location.rstrip("/"), |
| 407 | url_suffix, |
| 408 | ) |
| 409 | assert remote_location.startswith("gs://") |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 410 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 411 | upload_files = GenerateUploadDict( |
| 412 | package_path, remote_location, uploads |
| 413 | ) |
| 414 | remote_file = "%s/Packages" % remote_location.rstrip("/") |
| 415 | upload_files[tmp_packages_file.name] = remote_file |
David James | 015af87 | 2012-06-19 15:24:36 -0700 | [diff] [blame] | 416 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 417 | # Build list of files to upload. Manually include the dev-only files but |
| 418 | # skip them if not present. |
| 419 | dev_only = os.path.join(package_path, "dev-only-extras.tar.xz") |
| 420 | if os.path.exists(dev_only): |
| 421 | upload_files[dev_only] = "%s/%s" % ( |
| 422 | remote_location.rstrip("/"), |
| 423 | os.path.basename(dev_only), |
| 424 | ) |
Mike Frysinger | 9bb6cd8 | 2020-08-20 03:02:23 -0400 | [diff] [blame] | 425 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 426 | RemoteUpload(self._gs_context, self._acl, upload_files) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 427 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 428 | with tempfile.NamedTemporaryFile( |
| 429 | prefix="chromite.upload_prebuilts.index." |
| 430 | ) as index: |
| 431 | GenerateHtmlIndex( |
| 432 | [x[len(remote_location) + 1 :] for x in upload_files.values()], |
| 433 | index.name, |
| 434 | self._target, |
| 435 | self._version, |
| 436 | remote_location, |
| 437 | ) |
| 438 | self._Upload( |
| 439 | index.name, "%s/index.html" % remote_location.rstrip("/") |
| 440 | ) |
Mike Frysinger | 212e429 | 2014-05-24 15:15:44 -0400 | [diff] [blame] | 441 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 442 | link_name = "Prebuilts[%s]: %s" % (self._target, self._version) |
| 443 | url = "%s%s/index.html" % ( |
| 444 | gs.PUBLIC_BASE_HTTPS_URL, |
| 445 | remote_location[len(gs.BASE_GS_URL) :], |
| 446 | ) |
| 447 | cbuildbot_alerts.PrintBuildbotLink(link_name, url) |
Mike Frysinger | 212e429 | 2014-05-24 15:15:44 -0400 | [diff] [blame] | 448 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 449 | def _UploadSdkTarball( |
| 450 | self, |
| 451 | board_path, |
| 452 | url_suffix, |
| 453 | prepackaged, |
| 454 | toolchains_overlay_tarballs, |
| 455 | toolchains_overlay_upload_path, |
| 456 | toolchain_tarballs, |
| 457 | toolchain_upload_path, |
Greg Edelston | 8da51ce | 2023-03-22 10:40:59 -0600 | [diff] [blame] | 458 | sync_remote_latest_sdk_file: bool, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 459 | ): |
| 460 | """Upload a tarball of the sdk at the specified path to Google Storage. |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 461 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 462 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 463 | board_path: The path to the board dir. |
| 464 | url_suffix: The remote subdirectory where we should upload the |
| 465 | packages. |
| 466 | prepackaged: If given, a tarball that has been packaged outside of |
| 467 | this script and should be used. |
| 468 | toolchains_overlay_tarballs: List of toolchains overlay tarball |
| 469 | specifications to upload. Items take the form |
| 470 | "toolchains_spec:/path/to/tarball". |
| 471 | toolchains_overlay_upload_path: Path template under the bucket to |
| 472 | place toolchains overlay tarballs. |
| 473 | toolchain_tarballs: List of toolchain tarballs to upload. |
| 474 | toolchain_upload_path: Path under the bucket to place toolchain |
| 475 | tarballs. |
| 476 | sync_remote_latest_sdk_file: If True, update the remote latest SDK |
| 477 | file in Google Storage to point to the newly uploaded SDK. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 478 | """ |
| 479 | remote_location = "%s/%s" % ( |
| 480 | self._upload_location.rstrip("/"), |
| 481 | url_suffix, |
| 482 | ) |
| 483 | assert remote_location.startswith("gs://") |
| 484 | boardname = os.path.basename(board_path.rstrip("/")) |
| 485 | # We do not upload non SDK board tarballs, |
| 486 | assert boardname == constants.CHROOT_BUILDER_BOARD |
| 487 | assert prepackaged is not None |
Zdenek Behan | 62a5779 | 2012-08-31 15:09:08 +0200 | [diff] [blame] | 488 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 489 | version_str = self._version[len("chroot-") :] |
| 490 | remote_tarfile = toolchain.GetSdkURL( |
| 491 | for_gsutil=True, suburl="cros-sdk-%s.tar.xz" % (version_str,) |
| 492 | ) |
| 493 | # For SDK, also upload the manifest which is guaranteed to exist |
| 494 | # by the builderstage. |
| 495 | self._Upload(prepackaged + ".Manifest", remote_tarfile + ".Manifest") |
| 496 | self._Upload(prepackaged, remote_tarfile) |
Zdenek Behan | 86c15e9 | 2012-10-13 00:55:47 +0200 | [diff] [blame] | 497 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 498 | # Upload SDK toolchains overlays and toolchain tarballs, if given. |
| 499 | for tarball_list, upload_path, qualifier_name in ( |
| 500 | ( |
| 501 | toolchains_overlay_tarballs, |
| 502 | toolchains_overlay_upload_path, |
| 503 | "toolchains", |
| 504 | ), |
| 505 | (toolchain_tarballs, toolchain_upload_path, "target"), |
| 506 | ): |
| 507 | for tarball_spec in tarball_list: |
| 508 | qualifier_val, local_path = tarball_spec.split(":") |
| 509 | suburl = upload_path % {qualifier_name: qualifier_val} |
| 510 | remote_path = toolchain.GetSdkURL( |
| 511 | for_gsutil=True, suburl=suburl |
| 512 | ) |
| 513 | self._Upload(local_path, remote_path) |
Mike Frysinger | 9e979b9 | 2012-11-29 02:55:09 -0500 | [diff] [blame] | 514 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 515 | # Finally, also update the pointer to the latest SDK on which polling |
| 516 | # scripts rely. |
Greg Edelston | 8da51ce | 2023-03-22 10:40:59 -0600 | [diff] [blame] | 517 | if sync_remote_latest_sdk_file: |
| 518 | self._UpdateRemoteSdkLatestFile(latest_sdk=version_str) |
Greg Edelston | 64620d1 | 2023-02-23 15:29:49 -0700 | [diff] [blame] | 519 | |
| 520 | def _UpdateRemoteSdkLatestFile( |
| 521 | self, |
| 522 | latest_sdk: Optional[str] = None, |
| 523 | latest_sdk_uprev_target: Optional[str] = None, |
| 524 | ) -> None: |
| 525 | """Update the remote SDK pointer file on GS://. |
| 526 | |
| 527 | The remote file contains multiple key-value pairs. This function can |
| 528 | update one or more of them; Nones will retain their existing values. |
| 529 | |
| 530 | Args: |
| 531 | latest_sdk: The latest SDK that is tested and ready to be used. If |
| 532 | None, then the existing value on GS:// will be retained. |
| 533 | latest_sdk_uprev_target: The latest SDK that has been built, which |
| 534 | new PUprs can try to test and uprev. If None, then the existing |
| 535 | value on GS:// will be retained. |
| 536 | """ |
Greg Edelston | 119cbe1 | 2023-03-29 14:26:52 -0600 | [diff] [blame] | 537 | # This would be a noop in dryrun mode -- or worse, it would fail to |
| 538 | # parse the remote key-value store after pretending to download it. |
| 539 | # Instead of side-stepping errors, return early with descriptive logs. |
| 540 | if self._dryrun: |
| 541 | logging.debug("Not updating remote SDK latest file in dryrun mode.") |
| 542 | if latest_sdk is not None: |
| 543 | logging.debug("Would have set LATEST_SDK=%s", latest_sdk) |
| 544 | if latest_sdk_uprev_target is not None: |
| 545 | logging.debug( |
| 546 | "Would have set LATEST_SDK_UPREV_TARGET=%s", |
| 547 | latest_sdk_uprev_target, |
| 548 | ) |
| 549 | return |
| 550 | |
Greg Edelston | 64620d1 | 2023-02-23 15:29:49 -0700 | [diff] [blame] | 551 | # Get existing values from the remote file. |
| 552 | remote_pointerfile = toolchain.GetSdkURL( |
| 553 | for_gsutil=True, suburl="cros-sdk-latest.conf" |
| 554 | ) |
| 555 | existing_keyval = self._gs_context.LoadKeyValueStore( |
| 556 | remote_pointerfile, acl=self._acl |
| 557 | ) |
Greg Edelston | 2469ad3 | 2023-03-20 13:55:21 -0600 | [diff] [blame] | 558 | |
| 559 | # TODO(b/274196697): When LATEST_SDK_UPREV_TARGET is more reliably found |
| 560 | # in the remote latest file, require that key too. |
| 561 | for required_key in ("LATEST_SDK",): |
| 562 | if required_key not in existing_keyval: |
| 563 | raise ValueError( |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 564 | f"Remote pointer file {remote_pointerfile} missing " |
| 565 | f"expected key {required_key}:\n{existing_keyval}" |
Greg Edelston | 2469ad3 | 2023-03-20 13:55:21 -0600 | [diff] [blame] | 566 | ) |
Greg Edelston | 64620d1 | 2023-02-23 15:29:49 -0700 | [diff] [blame] | 567 | |
| 568 | # If any values were not specified in args, use the existing values. |
| 569 | if latest_sdk is None: |
| 570 | latest_sdk = existing_keyval["LATEST_SDK"] |
| 571 | if latest_sdk_uprev_target is None: |
Greg Edelston | 2469ad3 | 2023-03-20 13:55:21 -0600 | [diff] [blame] | 572 | latest_sdk_uprev_target = existing_keyval.get( |
| 573 | "LATEST_SDK_UPREV_TARGET", None |
| 574 | ) |
Greg Edelston | 64620d1 | 2023-02-23 15:29:49 -0700 | [diff] [blame] | 575 | |
| 576 | # Write a new local latest file with target values, and upload. |
| 577 | new_file_contents = self._CreateRemoteSdkLatestFileContents( |
| 578 | latest_sdk, latest_sdk_uprev_target |
| 579 | ) |
| 580 | with osutils.TempDir() as tmpdir: |
| 581 | local_pointerfile = os.path.join(tmpdir, "cros-sdk-latest.conf") |
| 582 | osutils.WriteFile(local_pointerfile, new_file_contents) |
| 583 | self._Upload(local_pointerfile, remote_pointerfile) |
| 584 | |
| 585 | @staticmethod |
| 586 | def _CreateRemoteSdkLatestFileContents( |
| 587 | latest_sdk: str, latest_sdk_uprev_target: str |
| 588 | ) -> str: |
| 589 | """Generate file contents for a remote SDK file. |
| 590 | |
| 591 | Args: |
| 592 | latest_sdk: The latest SDK that is tested and ready to be used. |
| 593 | latest_sdk_uprev_target: The latest SDK that has been built, which |
| 594 | new PUprs can try to test and uprev. |
| 595 | |
| 596 | Returns: |
| 597 | The contents of a remote SDK latest file containing the given args |
| 598 | as a key-value store. |
| 599 | """ |
| 600 | return f"""\ |
| 601 | # The most recent SDK that is tested and ready for use. |
| 602 | LATEST_SDK=\"{latest_sdk}\" |
Greg Edelston | f3916f9 | 2023-02-22 15:49:38 -0700 | [diff] [blame] | 603 | |
| 604 | # The most recently built version. New uprev attempts should target this. |
| 605 | # Warning: This version may not be tested yet. |
Greg Edelston | 64620d1 | 2023-02-23 15:29:49 -0700 | [diff] [blame] | 606 | LATEST_SDK_UPREV_TARGET=\"{latest_sdk_uprev_target}\"""" |
Zdenek Behan | 33a3411 | 2012-09-10 21:07:51 +0200 | [diff] [blame] | 607 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 608 | def _GetTargets(self): |
| 609 | """Retuns the list of targets to use.""" |
| 610 | targets = self._slave_targets[:] |
| 611 | if self._target: |
| 612 | targets.append(self._target) |
Chris Sosa | 6a5dceb | 2012-05-14 13:48:56 -0700 | [diff] [blame] | 613 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 614 | return targets |
Chris Sosa | 6a5dceb | 2012-05-14 13:48:56 -0700 | [diff] [blame] | 615 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 616 | def SyncHostPrebuilts(self, key, git_sync, sync_binhost_conf): |
| 617 | """Synchronize host prebuilt files. |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 618 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 619 | This function will sync both the standard host packages, plus the host |
| 620 | packages associated with all targets that have been "setup" with the |
| 621 | current host's chroot. For instance, if this host has been used to build |
| 622 | x86-generic, it will sync the host packages associated with |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 623 | 'i686-pc-linux-gnu'. If this host has also been used to build |
| 624 | arm-generic, it will also sync the host packages associated with |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 625 | 'armv7a-cros-linux-gnueabi'. |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 626 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 627 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 628 | key: The variable key to update in the git file. |
| 629 | git_sync: If set, update make.conf of target to reference the latest |
| 630 | prebuilt packages generated here. |
| 631 | sync_binhost_conf: If set, update binhost config file in |
| 632 | chromiumos-overlay for the host. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 633 | """ |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 634 | # Slave boards are listed before the master board so that the master |
| 635 | # board takes priority (i.e. x86-generic preflight host prebuilts takes |
| 636 | # priority over preflight host prebuilts from other builders.) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 637 | binhost_urls = [] |
| 638 | for target in self._GetTargets(): |
| 639 | url_suffix = _REL_HOST_PATH % { |
| 640 | "version": self._version, |
| 641 | "host_arch": _HOST_ARCH, |
| 642 | "target": target, |
| 643 | } |
| 644 | packages_url_suffix = "%s/packages" % url_suffix.rstrip("/") |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 645 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 646 | if self._target == target and not self._skip_upload: |
| 647 | # Upload prebuilts. |
| 648 | package_path = os.path.join(self._chroot, _HOST_PACKAGES_PATH) |
| 649 | self._UploadPrebuilt(package_path, packages_url_suffix) |
David James | 8ece7ee | 2011-06-29 16:02:30 -0700 | [diff] [blame] | 650 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 651 | # Record URL where prebuilts were uploaded. |
| 652 | binhost_urls.append( |
| 653 | "%s/%s/" |
| 654 | % ( |
| 655 | self._binhost_base_url.rstrip("/"), |
| 656 | packages_url_suffix.rstrip("/"), |
| 657 | ) |
| 658 | ) |
David James | e248864 | 2011-11-14 16:15:20 -0800 | [diff] [blame] | 659 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 660 | binhost = " ".join(binhost_urls) |
| 661 | if git_sync: |
| 662 | git_file = os.path.join( |
| 663 | self._build_path, _PREBUILT_MAKE_CONF[_HOST_ARCH] |
| 664 | ) |
Greg Edelston | 86aea7b | 2023-02-15 16:50:25 -0700 | [diff] [blame] | 665 | binpkg.UpdateAndSubmitKeyValueFile( |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 666 | git_file, {key: binhost}, self._report, dryrun=self._dryrun |
| 667 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 668 | if sync_binhost_conf: |
| 669 | binhost_conf = os.path.join( |
| 670 | self._binhost_conf_dir, "host", "%s-%s.conf" % (_HOST_ARCH, key) |
| 671 | ) |
| 672 | UpdateBinhostConfFile(binhost_conf, key, binhost) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 673 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 674 | def SyncBoardPrebuilts( |
| 675 | self, |
| 676 | key, |
| 677 | git_sync, |
| 678 | sync_binhost_conf, |
| 679 | upload_board_tarball, |
| 680 | prepackaged_board, |
| 681 | toolchains_overlay_tarballs, |
| 682 | toolchains_overlay_upload_path, |
| 683 | toolchain_tarballs, |
| 684 | toolchain_upload_path, |
Greg Edelston | 8da51ce | 2023-03-22 10:40:59 -0600 | [diff] [blame] | 685 | sync_remote_latest_sdk_file: bool, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 686 | ): |
| 687 | """Synchronize board prebuilt files. |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 688 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 689 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 690 | key: The variable key to update in the git file. |
| 691 | git_sync: If set, update make.conf of target to reference the latest |
| 692 | prebuilt packages generated here. |
| 693 | sync_binhost_conf: If set, update binhost config file in |
| 694 | chromiumos-overlay for the current board. |
| 695 | upload_board_tarball: Include a tarball of the board in our upload. |
| 696 | prepackaged_board: A tarball of the board built outside of this |
| 697 | script. |
| 698 | toolchains_overlay_tarballs: List of toolchains overlay tarball |
| 699 | specifications to upload. Items take the form |
| 700 | "toolchains_spec:/path/to/tarball". |
| 701 | toolchains_overlay_upload_path: Path template under the bucket to |
| 702 | place toolchains overlay tarballs. |
| 703 | toolchain_tarballs: A list of toolchain tarballs to upload. |
| 704 | toolchain_upload_path: Path under the bucket to place toolchain |
| 705 | tarballs. |
| 706 | sync_remote_latest_sdk_file: If True, update the remote latest SDK |
| 707 | file in Google Storage to point to the newly uploaded SDK. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 708 | """ |
| 709 | updated_binhosts = set() |
| 710 | for target in self._GetTargets(): |
| 711 | board_path = os.path.join( |
| 712 | self._build_path, _BOARD_PATH % {"board": target.board_variant} |
| 713 | ) |
| 714 | package_path = os.path.join(board_path, "packages") |
| 715 | url_suffix = _REL_BOARD_PATH % { |
| 716 | "target": target, |
| 717 | "version": self._version, |
| 718 | } |
| 719 | packages_url_suffix = "%s/packages" % url_suffix.rstrip("/") |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 720 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 721 | # Process the target board differently if it is the main --board. |
| 722 | if self._target == target and not self._skip_upload: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 723 | # This strips "chroot" prefix because that is sometimes added as |
| 724 | # the --prepend-version argument (e.g. by chromiumos-sdk bot). |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 725 | # TODO(build): Clean it up to be less hard-coded. |
| 726 | version_str = self._version[len("chroot-") :] |
Mike Frysinger | 9e979b9 | 2012-11-29 02:55:09 -0500 | [diff] [blame] | 727 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 728 | # Upload board tarballs in the background. |
| 729 | if upload_board_tarball: |
| 730 | if toolchain_upload_path: |
| 731 | toolchain_upload_path %= {"version": version_str} |
| 732 | if toolchains_overlay_upload_path: |
| 733 | toolchains_overlay_upload_path %= { |
| 734 | "version": version_str |
| 735 | } |
| 736 | tar_process = multiprocessing.Process( |
| 737 | target=self._UploadSdkTarball, |
| 738 | args=( |
| 739 | board_path, |
| 740 | url_suffix, |
| 741 | prepackaged_board, |
| 742 | toolchains_overlay_tarballs, |
| 743 | toolchains_overlay_upload_path, |
| 744 | toolchain_tarballs, |
| 745 | toolchain_upload_path, |
Greg Edelston | 8da51ce | 2023-03-22 10:40:59 -0600 | [diff] [blame] | 746 | sync_remote_latest_sdk_file, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 747 | ), |
| 748 | ) |
| 749 | tar_process.start() |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 750 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 751 | # Upload prebuilts. |
| 752 | self._UploadPrebuilt(package_path, packages_url_suffix) |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 753 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 754 | # Make sure we finished uploading the board tarballs. |
| 755 | if upload_board_tarball: |
| 756 | tar_process.join() |
| 757 | assert tar_process.exitcode == 0 |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 758 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 759 | # Record URL where prebuilts were uploaded. |
| 760 | url_value = "%s/%s/" % ( |
| 761 | self._binhost_base_url.rstrip("/"), |
| 762 | packages_url_suffix.rstrip("/"), |
| 763 | ) |
David James | e248864 | 2011-11-14 16:15:20 -0800 | [diff] [blame] | 764 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 765 | if git_sync: |
| 766 | git_file = DeterminePrebuiltConfFile(self._build_path, target) |
Greg Edelston | 86aea7b | 2023-02-15 16:50:25 -0700 | [diff] [blame] | 767 | binpkg.UpdateAndSubmitKeyValueFile( |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 768 | git_file, |
| 769 | {key: url_value}, |
| 770 | self._report, |
| 771 | dryrun=self._dryrun, |
| 772 | ) |
Matt Tennant | e817904 | 2013-10-01 15:47:32 -0700 | [diff] [blame] | 773 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 774 | if sync_binhost_conf: |
| 775 | # Update the binhost configuration file in git. |
| 776 | binhost_conf = os.path.join( |
| 777 | self._binhost_conf_dir, |
| 778 | "target", |
| 779 | "%s-%s.conf" % (target, key), |
| 780 | ) |
| 781 | updated_binhosts.add(binhost_conf) |
| 782 | UpdateBinhostConfFile(binhost_conf, key, url_value) |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 783 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 784 | if sync_binhost_conf: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 785 | # Clear all old binhosts. The files must be left empty in case |
| 786 | # anybody is referring to them. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 787 | all_binhosts = set( |
| 788 | glob.glob( |
| 789 | os.path.join( |
| 790 | self._binhost_conf_dir, "target", "*-%s.conf" % key |
| 791 | ) |
| 792 | ) |
| 793 | ) |
| 794 | for binhost_conf in all_binhosts - updated_binhosts: |
| 795 | UpdateBinhostConfFile(binhost_conf, key, "") |
David James | b26b931 | 2014-12-15 11:26:46 -0800 | [diff] [blame] | 796 | |
David James | 05bcb2b | 2011-02-09 09:25:47 -0800 | [diff] [blame] | 797 | |
Mike Nichols | a141416 | 2021-04-22 20:07:22 +0000 | [diff] [blame] | 798 | class _AddSlaveBoardAction(argparse.Action): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 799 | """Callback that adds a slave board to the list of slave targets.""" |
| 800 | |
| 801 | def __call__(self, parser, namespace, values, option_string=None): |
| 802 | getattr(namespace, self.dest).append(BuildTarget(values)) |
David James | 4058b0d | 2011-12-08 21:24:50 -0800 | [diff] [blame] | 803 | |
| 804 | |
Mike Nichols | a141416 | 2021-04-22 20:07:22 +0000 | [diff] [blame] | 805 | class _AddSlaveProfileAction(argparse.Action): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 806 | """Callback that adds a slave profile to the list of slave targets.""" |
| 807 | |
| 808 | def __call__(self, parser, namespace, values, option_string=None): |
| 809 | if not namespace.slave_targets: |
| 810 | parser.error("Must specify --slave-board before --slave-profile") |
| 811 | if namespace.slave_targets[-1].profile is not None: |
| 812 | parser.error("Cannot specify --slave-profile twice for same board") |
| 813 | namespace.slave_targets[-1].profile = values |
David James | 4058b0d | 2011-12-08 21:24:50 -0800 | [diff] [blame] | 814 | |
| 815 | |
Greg Edelston | 325e441 | 2023-05-04 16:22:10 -0600 | [diff] [blame] | 816 | def ParseOptions(argv) -> Tuple[argparse.Namespace, Optional[BuildTarget]]: |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 817 | """Returns options given by the user and the target specified. |
Chris Sosa | 6a5dceb | 2012-05-14 13:48:56 -0700 | [diff] [blame] | 818 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 819 | Args: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 820 | argv: The args to parse. |
Mike Frysinger | 8650923 | 2014-05-24 13:18:37 -0400 | [diff] [blame] | 821 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 822 | Returns: |
Alex Klein | d719740 | 2023-04-05 13:05:29 -0600 | [diff] [blame] | 823 | A tuple containing a parsed options object and BuildTarget. |
| 824 | The target instance is None if no board is specified. |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 825 | """ |
Mike Frysinger | 4e86f86 | 2023-02-02 09:01:33 -0500 | [diff] [blame] | 826 | parser = commandline.ArgumentParser(description=__doc__, dryrun=True) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 827 | parser.add_argument( |
| 828 | "-H", |
| 829 | "--binhost-base-url", |
| 830 | default=_BINHOST_BASE_URL, |
| 831 | help="Base URL to use for binhost in make.conf updates", |
| 832 | ) |
| 833 | parser.add_argument( |
| 834 | "--previous-binhost-url", |
| 835 | action="append", |
| 836 | default=[], |
| 837 | help="Previous binhost URL", |
| 838 | ) |
| 839 | parser.add_argument( |
| 840 | "-b", "--board", help="Board type that was built on this machine" |
| 841 | ) |
| 842 | parser.add_argument( |
| 843 | "-B", |
| 844 | "--prepackaged-tarball", |
| 845 | type="path", |
| 846 | help="Board tarball prebuilt outside of this script.", |
| 847 | ) |
| 848 | parser.add_argument( |
| 849 | "--toolchains-overlay-tarball", |
| 850 | dest="toolchains_overlay_tarballs", |
| 851 | action="append", |
| 852 | default=[], |
| 853 | help="Toolchains overlay tarball specification to " |
| 854 | "upload. Takes the form " |
| 855 | '"toolchains_spec:/path/to/tarball".', |
| 856 | ) |
| 857 | parser.add_argument( |
| 858 | "--toolchains-overlay-upload-path", |
| 859 | default="", |
| 860 | help="Path template for uploading toolchains overlays.", |
| 861 | ) |
| 862 | parser.add_argument( |
| 863 | "--toolchain-tarball", |
| 864 | dest="toolchain_tarballs", |
| 865 | action="append", |
| 866 | default=[], |
| 867 | help="Redistributable toolchain tarball.", |
| 868 | ) |
| 869 | parser.add_argument( |
| 870 | "--toolchain-upload-path", |
| 871 | default="", |
| 872 | help="Path to place toolchain tarballs in the sdk tree.", |
| 873 | ) |
| 874 | parser.add_argument( |
| 875 | "--profile", help="Profile that was built on this machine" |
| 876 | ) |
| 877 | parser.add_argument( |
| 878 | "--slave-board", |
| 879 | default=[], |
| 880 | action=_AddSlaveBoardAction, |
| 881 | dest="slave_targets", |
| 882 | help="Board type that was built on a slave machine. To " |
| 883 | "add a profile to this board, use --slave-profile.", |
| 884 | ) |
| 885 | parser.add_argument( |
| 886 | "--slave-profile", |
| 887 | action=_AddSlaveProfileAction, |
| 888 | help="Board profile that was built on a slave machine. " |
| 889 | "Applies to previous slave board.", |
| 890 | ) |
| 891 | parser.add_argument( |
| 892 | "-p", |
| 893 | "--build-path", |
| 894 | required=True, |
| 895 | help="Path to the directory containing the chroot", |
| 896 | ) |
| 897 | parser.add_argument( |
| 898 | "--chroot", |
| 899 | help="Path where the chroot is located. " |
| 900 | "(Default: {build_path}/chroot)", |
| 901 | ) |
| 902 | parser.add_argument( |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 903 | "--output", |
| 904 | type=Path, |
| 905 | help="Write a JSON report to the specified file. " |
| 906 | "(Default is not to write the report.)", |
| 907 | ) |
| 908 | parser.add_argument( |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 909 | "--packages", |
| 910 | action="append", |
| 911 | default=[], |
| 912 | help="Only include the specified packages. " |
| 913 | "(Default is to include all packages.)", |
| 914 | ) |
| 915 | parser.add_argument( |
| 916 | "-s", |
| 917 | "--sync-host", |
| 918 | default=False, |
| 919 | action="store_true", |
| 920 | help="Sync host prebuilts", |
| 921 | ) |
| 922 | parser.add_argument( |
| 923 | "-g", |
| 924 | "--git-sync", |
| 925 | default=False, |
| 926 | action="store_true", |
| 927 | help="Enable git version sync (This commits to a repo.) " |
| 928 | "This is used by full builders to commit directly " |
| 929 | "to board overlays.", |
| 930 | ) |
Greg Edelston | 8da51ce | 2023-03-22 10:40:59 -0600 | [diff] [blame] | 931 | parser.add_argument( |
| 932 | "--sync-remote-latest-sdk-file", |
| 933 | action="store_true", |
Greg Edelston | 325e441 | 2023-05-04 16:22:10 -0600 | [diff] [blame] | 934 | default=True, |
Greg Edelston | 8da51ce | 2023-03-22 10:40:59 -0600 | [diff] [blame] | 935 | help="Sync the remote latest SDK file on GS://. (Default)", |
| 936 | ) |
| 937 | parser.add_argument( |
| 938 | "--no-sync-remote-latest-sdk-file", |
| 939 | dest="sync_remote_latest_sdk_file", |
| 940 | action="store_false", |
| 941 | help="Skip syncing the remote latest SDK file on GS://.", |
| 942 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 943 | parser.add_argument("-u", "--upload", help="Upload location") |
| 944 | parser.add_argument( |
| 945 | "-V", |
| 946 | "--prepend-version", |
| 947 | help="Add an identifier to the front of the version", |
| 948 | ) |
| 949 | parser.add_argument( |
| 950 | "-f", |
| 951 | "--filters", |
| 952 | action="store_true", |
| 953 | default=False, |
| 954 | help="Turn on filtering of private ebuild packages", |
| 955 | ) |
| 956 | parser.add_argument( |
| 957 | "-k", |
| 958 | "--key", |
| 959 | default="PORTAGE_BINHOST", |
| 960 | help="Key to update in make.conf / binhost.conf", |
| 961 | ) |
| 962 | parser.add_argument("--set-version", help="Specify the version string") |
| 963 | parser.add_argument( |
| 964 | "--sync-binhost-conf", |
| 965 | default=False, |
| 966 | action="store_true", |
| 967 | help="Update binhost.conf in chromiumos-overlay or " |
| 968 | "chromeos-overlay. Commit the changes, but don't " |
| 969 | "push them. This is used for preflight binhosts.", |
| 970 | ) |
| 971 | parser.add_argument( |
| 972 | "--binhost-conf-dir", |
| 973 | help="Directory to commit binhost config with " "--sync-binhost-conf.", |
| 974 | ) |
| 975 | parser.add_argument( |
| 976 | "-P", |
| 977 | "--private", |
| 978 | action="store_true", |
| 979 | default=False, |
| 980 | help="Mark gs:// uploads as private.", |
| 981 | ) |
| 982 | parser.add_argument( |
| 983 | "--skip-upload", |
| 984 | action="store_true", |
| 985 | default=False, |
| 986 | help="Skip upload step.", |
| 987 | ) |
| 988 | parser.add_argument( |
| 989 | "--upload-board-tarball", |
| 990 | action="store_true", |
| 991 | default=False, |
| 992 | help="Upload board tarball to Google Storage.", |
| 993 | ) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 994 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 995 | options = parser.parse_args(argv) |
| 996 | if not options.upload and not options.skip_upload: |
| 997 | parser.error("you need to provide an upload location using -u") |
| 998 | if not options.set_version and options.skip_upload: |
| 999 | parser.error( |
| 1000 | "If you are using --skip-upload, you must specify a " |
| 1001 | "version number using --set-version." |
| 1002 | ) |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 1003 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1004 | target = None |
| 1005 | if options.board: |
| 1006 | target = BuildTarget(options.board, options.profile) |
Chris Sosa | 6a5dceb | 2012-05-14 13:48:56 -0700 | [diff] [blame] | 1007 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1008 | if target in options.slave_targets: |
| 1009 | parser.error("--board/--profile must not also be a slave target.") |
David James | e248864 | 2011-11-14 16:15:20 -0800 | [diff] [blame] | 1010 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1011 | if len(set(options.slave_targets)) != len(options.slave_targets): |
| 1012 | parser.error("--slave-boards must not have duplicates.") |
David James | e248864 | 2011-11-14 16:15:20 -0800 | [diff] [blame] | 1013 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1014 | if options.slave_targets and options.git_sync: |
| 1015 | parser.error("--slave-boards is not compatible with --git-sync") |
David James | e248864 | 2011-11-14 16:15:20 -0800 | [diff] [blame] | 1016 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1017 | if ( |
| 1018 | options.upload_board_tarball |
| 1019 | and options.skip_upload |
| 1020 | and options.board == "amd64-host" |
| 1021 | ): |
| 1022 | parser.error( |
| 1023 | "--skip-upload is not compatible with " |
| 1024 | "--upload-board-tarball and --board=amd64-host" |
| 1025 | ) |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 1026 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1027 | if ( |
| 1028 | options.upload_board_tarball |
| 1029 | and not options.skip_upload |
| 1030 | and not options.upload.startswith("gs://") |
| 1031 | ): |
| 1032 | parser.error( |
| 1033 | "--upload-board-tarball only works with gs:// URLs.\n" |
| 1034 | "--upload must be a gs:// URL." |
| 1035 | ) |
David James | 8fa34ea | 2011-04-15 13:00:20 -0700 | [diff] [blame] | 1036 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1037 | if options.upload_board_tarball and options.prepackaged_tarball is None: |
| 1038 | parser.error("--upload-board-tarball requires --prepackaged-tarball") |
Zdenek Behan | 86c15e9 | 2012-10-13 00:55:47 +0200 | [diff] [blame] | 1039 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1040 | if options.private: |
| 1041 | if options.sync_host: |
| 1042 | parser.error( |
| 1043 | "--private and --sync-host/-s cannot be specified " |
| 1044 | "together; we do not support private host prebuilts" |
| 1045 | ) |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 1046 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1047 | if not options.upload or not options.upload.startswith("gs://"): |
| 1048 | parser.error( |
| 1049 | "--private is only valid for gs:// URLs; " |
| 1050 | "--upload must be a gs:// URL." |
| 1051 | ) |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 1052 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1053 | if options.binhost_base_url != _BINHOST_BASE_URL: |
| 1054 | parser.error( |
| 1055 | "when using --private the --binhost-base-url " |
| 1056 | "is automatically derived." |
| 1057 | ) |
David James | 27fa7d1 | 2011-06-29 17:24:14 -0700 | [diff] [blame] | 1058 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1059 | if options.sync_binhost_conf and not options.binhost_conf_dir: |
| 1060 | parser.error("--sync-binhost-conf requires --binhost-conf-dir") |
David James | c31168e | 2014-06-05 14:40:05 -0700 | [diff] [blame] | 1061 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1062 | if ( |
| 1063 | options.toolchains_overlay_tarballs |
| 1064 | and not options.toolchains_overlay_upload_path |
| 1065 | ): |
| 1066 | parser.error( |
| 1067 | "--toolchains-overlay-tarball requires " |
| 1068 | "--toolchains-overlay-upload-path" |
| 1069 | ) |
Gilad Arnold | ad33318 | 2015-05-27 15:50:41 -0700 | [diff] [blame] | 1070 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1071 | return options, target |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 1072 | |
Mike Frysinger | cc83883 | 2014-05-24 13:10:30 -0400 | [diff] [blame] | 1073 | |
Mike Frysinger | 8650923 | 2014-05-24 13:18:37 -0400 | [diff] [blame] | 1074 | def main(argv): |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 1075 | # We accumulate information about actions taken and report it at the end |
| 1076 | # if asked to do so. Currently, this only records CL creation, which |
| 1077 | # is the only thing we need for now. |
| 1078 | report = {} |
| 1079 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1080 | # Set umask so that files created as root are readable. |
| 1081 | os.umask(0o22) |
David James | db40107 | 2011-06-10 12:17:16 -0700 | [diff] [blame] | 1082 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1083 | options, target = ParseOptions(argv) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 1084 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1085 | # Calculate a list of Packages index files to compare against. Whenever we |
| 1086 | # upload a package, we check to make sure it's not already stored in one of |
| 1087 | # the packages files we uploaded. This list of packages files might contain |
| 1088 | # both board and host packages. |
| 1089 | pkg_indexes = _GrabAllRemotePackageIndexes(options.previous_binhost_url) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 1090 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1091 | if options.set_version: |
| 1092 | version = options.set_version |
| 1093 | else: |
| 1094 | version = GetVersion() |
Matt Tennant | e817904 | 2013-10-01 15:47:32 -0700 | [diff] [blame] | 1095 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1096 | if options.prepend_version: |
| 1097 | version = "%s-%s" % (options.prepend_version, version) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 1098 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1099 | acl = "public-read" |
| 1100 | binhost_base_url = options.binhost_base_url |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 1101 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1102 | if options.private: |
| 1103 | binhost_base_url = options.upload |
| 1104 | if target: |
| 1105 | acl = portage_util.FindOverlayFile( |
| 1106 | _GOOGLESTORAGE_GSUTIL_FILE, |
| 1107 | board=target.board_variant, |
| 1108 | buildroot=options.build_path, |
| 1109 | ) |
| 1110 | if acl is None: |
| 1111 | cros_build_lib.Die( |
| 1112 | "No Google Storage ACL file %s found in %s overlay.", |
| 1113 | _GOOGLESTORAGE_GSUTIL_FILE, |
| 1114 | target.board_variant, |
| 1115 | ) |
Scott Zawalski | ab1bed3 | 2011-03-16 15:24:24 -0700 | [diff] [blame] | 1116 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1117 | binhost_conf_dir = None |
| 1118 | if options.binhost_conf_dir: |
| 1119 | binhost_conf_dir = os.path.join( |
| 1120 | options.build_path, options.binhost_conf_dir |
| 1121 | ) |
David James | b26b931 | 2014-12-15 11:26:46 -0800 | [diff] [blame] | 1122 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1123 | uploader = PrebuiltUploader( |
| 1124 | options.upload, |
| 1125 | acl, |
| 1126 | binhost_base_url, |
| 1127 | pkg_indexes, |
| 1128 | options.build_path, |
| 1129 | options.packages, |
| 1130 | options.skip_upload, |
| 1131 | binhost_conf_dir, |
| 1132 | options.dryrun, |
| 1133 | target, |
| 1134 | options.slave_targets, |
| 1135 | version, |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 1136 | report, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1137 | options.chroot, |
| 1138 | ) |
David James | c0f158a | 2011-02-22 16:07:29 -0800 | [diff] [blame] | 1139 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1140 | if options.sync_host: |
| 1141 | uploader.SyncHostPrebuilts( |
| 1142 | options.key, options.git_sync, options.sync_binhost_conf |
| 1143 | ) |
David James | 8c84649 | 2011-01-25 17:07:29 -0800 | [diff] [blame] | 1144 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1145 | if options.board or options.slave_targets: |
| 1146 | uploader.SyncBoardPrebuilts( |
| 1147 | options.key, |
| 1148 | options.git_sync, |
| 1149 | options.sync_binhost_conf, |
| 1150 | options.upload_board_tarball, |
| 1151 | options.prepackaged_tarball, |
| 1152 | options.toolchains_overlay_tarballs, |
| 1153 | options.toolchains_overlay_upload_path, |
| 1154 | options.toolchain_tarballs, |
| 1155 | options.toolchain_upload_path, |
Greg Edelston | 8da51ce | 2023-03-22 10:40:59 -0600 | [diff] [blame] | 1156 | options.sync_remote_latest_sdk_file, |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 1157 | ) |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 1158 | |
Denis Nikitin | f7e5e9c | 2022-09-30 14:34:47 -0700 | [diff] [blame] | 1159 | if options.output: |
Mike Frysinger | 31fdddd | 2023-02-24 15:50:55 -0500 | [diff] [blame] | 1160 | with open(options.output, "w", encoding="utf-8") as f: |
Bob Haarman | c008260 | 2022-09-20 16:12:43 -0700 | [diff] [blame] | 1161 | pformat.json(report, fp=f) |