| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/python |
| 2 |
| 3 # Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Steps to archive dartium, content_shell, and chromedriver from buildbots. |
| 8 |
| 9 Imported by buildbot_annotated_steps.py and multivm_archive.py |
| 10 """ |
| 11 |
| 12 import imp |
| 13 import os |
| 14 import platform |
| 15 import re |
| 16 import subprocess |
| 17 import sys |
| 18 |
| 19 import dartium_bot_utils |
| 20 import archive |
| 21 |
| 22 BUILDER_NAME = 'BUILDBOT_BUILDERNAME' |
| 23 REVISION = 'BUILDBOT_REVISION' |
| 24 BUILDER_PATTERN = (r'^(dartium|multivm)-(mac|lucid64|lucid32|win)' |
| 25 r'-(full|inc|debug|build)(-ninja)?(-(be|dev|stable|integration))?$') |
| 26 |
| 27 if platform.system() == 'Windows': |
| 28 GSUTIL = 'e:/b/build/scripts/slave/gsutil.bat' |
| 29 else: |
| 30 GSUTIL = '/b/build/scripts/slave/gsutil' |
| 31 ACL = 'public-read' |
| 32 GS_SITE = 'gs://' |
| 33 GS_URL = 'https://sandbox.google.com/storage/' |
| 34 GS_DIR = 'dartium-archive' |
| 35 LATEST = 'latest' |
| 36 CONTINUOUS = 'continuous' |
| 37 |
| 38 SRC_PATH = dartium_bot_utils.srcPath() |
| 39 DART_PATH = os.path.join(SRC_PATH, 'dart') |
| 40 |
| 41 bot_utils = imp.load_source('bot_utils', |
| 42 os.path.join(DART_PATH, 'tools', 'bots', 'bot_utils.py')) |
| 43 |
| 44 class BuildInfo(object): |
| 45 """ |
| 46 name: A name for the build - the buildbot host if a buildbot. |
| 47 mode: 'Debug' or 'Release' |
| 48 arch: target architecture |
| 49 channel: the channel this build is happening on |
| 50 is_full: True if this is a full build. |
| 51 is_incremental: True if this is an incremental build. |
| 52 is_build: True if this is a builder for the performance testers. |
| 53 is_win_ninja: True if this is a ninja build on Windows. |
| 54 |
| 55 """ |
| 56 def __init__(self, revision, version): |
| 57 |
| 58 self.revision = revision |
| 59 self.version = version |
| 60 # Populate via builder environment variables. |
| 61 self.name = os.environ[BUILDER_NAME] |
| 62 # Temporary hack, until we rename the FYI bots. |
| 63 # We should eventually rename all to linux32 and linux64. |
| 64 self.name = self.name.replace('-linux-', '-lucid64-') |
| 65 |
| 66 self.is_incremental = '-inc' in self.name |
| 67 self.is_win_ninja = 'win-inc-ninja' in self.name |
| 68 pattern = re.match(BUILDER_PATTERN, self.name) |
| 69 assert pattern |
| 70 self.arch = 'x64' if pattern.group(2) == 'lucid64' else 'ia32' |
| 71 self.mode = 'Debug' if pattern.group(3) == 'debug' else 'Release' |
| 72 self.is_full = pattern.group(3) == 'full' |
| 73 self.is_build = pattern.group(3) == 'build' |
| 74 self.channel = pattern.group(6) if pattern.group(6) else 'be' |
| 75 |
| 76 |
| 77 def ArchiveAndUpload(info, archive_latest=False): |
| 78 print '@@@BUILD_STEP dartium_generate_archive@@@' |
| 79 cwd = os.getcwd() |
| 80 |
| 81 dartium_bucket = info.name |
| 82 dartium_bucket = dartium_bucket.replace('multivm', 'multivm-dartium') |
| 83 drt_bucket = dartium_bucket.replace('dartium', 'drt') |
| 84 chromedriver_bucket = dartium_bucket.replace('dartium', 'chromedriver') |
| 85 dartium_archive = dartium_bucket + '-' + info.version |
| 86 drt_archive = drt_bucket + '-' + info.version |
| 87 chromedriver_archive = chromedriver_bucket + '-' + info.version |
| 88 dartium_zip, drt_zip, chromedriver_zip = archive.Archive( |
| 89 SRC_PATH, |
| 90 info.mode, |
| 91 dartium_archive, |
| 92 drt_archive, |
| 93 chromedriver_archive, |
| 94 is_win_ninja=info.is_win_ninja) |
| 95 |
| 96 status = 0 |
| 97 # Upload bleeding-edge builds to old dartium-archive bucket |
| 98 if info.channel == 'be': |
| 99 status = (OldUpload('dartium', dartium_bucket, |
| 100 os.path.abspath(dartium_zip), |
| 101 archive_latest=archive_latest) |
| 102 or OldUpload('drt', drt_bucket, |
| 103 os.path.abspath(drt_zip), |
| 104 archive_latest=archive_latest) |
| 105 or OldUpload('chromedriver', chromedriver_bucket, |
| 106 os.path.abspath(chromedriver_zip), |
| 107 archive_latest=archive_latest)) |
| 108 |
| 109 # Upload to new dart-archive bucket using GCSNamer, but not incremental |
| 110 # or perf builder builds. |
| 111 if not info.is_incremental and not info.is_build: |
| 112 Upload('dartium', os.path.abspath(dartium_zip), |
| 113 info, archive_latest=archive_latest) |
| 114 Upload('drt', os.path.abspath(drt_zip), |
| 115 info, archive_latest=archive_latest) |
| 116 Upload('chromedriver', os.path.abspath(chromedriver_zip), |
| 117 info, archive_latest=archive_latest) |
| 118 |
| 119 os.chdir(cwd) |
| 120 if status != 0: |
| 121 print '@@@STEP_FAILURE@@@' |
| 122 return status |
| 123 |
| 124 |
| 125 def OldUpload(module, bucket, zip_file, archive_latest=False): |
| 126 """Upload a zip file to the old bucket gs://dartium-archive/ |
| 127 """ |
| 128 # TODO(whesse): Remove the old archiving code (OldUpload, OldUploadFile, |
| 129 # and constants they use) once everything points to the new location. |
| 130 status = 0 |
| 131 _, filename = os.path.split(zip_file) |
| 132 if not archive_latest: |
| 133 target = '/'.join([GS_DIR, bucket, filename]) |
| 134 print '@@@BUILD_STEP %s_upload_archive_old@@@' % module |
| 135 status = OldUploadFile(zip_file, GS_SITE + target) |
| 136 print '@@@STEP_LINK@download@' + GS_URL + target + '@@@' |
| 137 else: |
| 138 print '@@@BUILD_STEP %s_upload_latest_old@@@' % module |
| 139 # Clear latest for this build type. |
| 140 old = '/'.join([GS_DIR, LATEST, bucket + '-*']) |
| 141 old_archives = ListArchives(GS_SITE + old) |
| 142 |
| 143 # Upload the new latest and remove unnecessary old ones. |
| 144 target = GS_SITE + '/'.join([GS_DIR, LATEST, filename]) |
| 145 status = OldUploadFile(zip_file, target) |
| 146 if status == 0: |
| 147 RemoveArchives( |
| 148 [iarch for iarch in old_archives if iarch != target]) |
| 149 else: |
| 150 print 'Upload failed' |
| 151 |
| 152 # Upload unversioned name to continuous site for incremental |
| 153 # builds. |
| 154 if '-inc' in bucket: |
| 155 continuous_name = bucket[:bucket.find('-inc')] |
| 156 target = GS_SITE + '/'.join([GS_DIR, CONTINUOUS, |
| 157 continuous_name + '.zip']) |
| 158 status = OldUploadFile(zip_file, target) |
| 159 |
| 160 print ('@@@BUILD_STEP %s_upload_archive is over (status = %s)@@@' % |
| 161 (module, status)) |
| 162 return status |
| 163 |
| 164 |
| 165 def Upload(module, zip_file, info, archive_latest=False): |
| 166 """Upload a zip file to cloud storage bucket gs://dart-archive/ |
| 167 """ |
| 168 print '@@@BUILD_STEP %s_upload_archive @@@' % module |
| 169 revision = 'latest' if archive_latest else info.revision |
| 170 name = module.replace('drt', 'content_shell') |
| 171 namer = bot_utils.GCSNamer(info.channel, bot_utils.ReleaseType.RAW) |
| 172 remote_path = namer.dartium_variant_zipfilepath(revision, |
| 173 name, |
| 174 sys.platform, |
| 175 info.arch, |
| 176 info.mode.lower()) |
| 177 UploadFile(zip_file, remote_path, create_md5sum=True) |
| 178 |
| 179 print '@@@STEP_LINK@download@' + remote_path + '@@@' |
| 180 |
| 181 |
| 182 def OldUploadFile(source, target): |
| 183 """Upload an archive zip file to Google storage. |
| 184 """ |
| 185 |
| 186 # Upload file. |
| 187 cmd = [GSUTIL, 'cp', source, target] |
| 188 (status, output) = ExecuteCommand(cmd) |
| 189 if status != 0: |
| 190 return status |
| 191 print 'Uploaded: ' + output |
| 192 |
| 193 # Set ACL. |
| 194 if ACL is not None: |
| 195 cmd = [GSUTIL, 'setacl', ACL, target] |
| 196 (status, output) = ExecuteCommand(cmd) |
| 197 return status |
| 198 |
| 199 |
| 200 def UploadFile(local_path, remote_path, create_md5sum=False): |
| 201 # Copy it to the new unified gs://dart-archive bucket |
| 202 gsutil = bot_utils.GSUtil() |
| 203 gsutil.upload(local_path, remote_path, public=True) |
| 204 if create_md5sum: |
| 205 # 'local_path' may have a different filename than 'remote_path'. So we need |
| 206 # to make sure the *.md5sum file contains the correct name. |
| 207 assert '/' in remote_path and not remote_path.endswith('/') |
| 208 mangled_filename = remote_path[remote_path.rfind('/') + 1:] |
| 209 local_md5sum = bot_utils.CreateChecksumFile(local_path, mangled_filename) |
| 210 gsutil.upload(local_md5sum, remote_path + '.md5sum', public=True) |
| 211 |
| 212 |
| 213 def ExecuteCommand(cmd): |
| 214 """Execute a command in a subprocess. |
| 215 """ |
| 216 print 'Executing: ' + ' '.join(cmd) |
| 217 try: |
| 218 pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 219 (output, error) = pipe.communicate() |
| 220 if pipe.returncode != 0: |
| 221 print 'Execution failed: ' + str(error) |
| 222 return (pipe.returncode, output) |
| 223 except: |
| 224 import traceback |
| 225 print 'Execution raised exception:', traceback.format_exc() |
| 226 return (-1, '') |
| 227 |
| 228 |
| 229 def UploadDartTestsResults(layout_test_results_dir, name, version, |
| 230 component, checked): |
| 231 """Uploads test results to google storage. |
| 232 """ |
| 233 print ('@@@BUILD_STEP archive %s_layout_%s_tests results@@@' % |
| 234 (component, checked)) |
| 235 dir_name = os.path.dirname(layout_test_results_dir) |
| 236 base_name = os.path.basename(layout_test_results_dir) |
| 237 cwd = os.getcwd() |
| 238 os.chdir(dir_name) |
| 239 |
| 240 archive_name = 'layout_test_results.zip' |
| 241 archive.ZipDir(archive_name, base_name) |
| 242 |
| 243 target = '/'.join([GS_DIR, 'layout-test-results', name, component + '-' + |
| 244 checked + '-' + version + '.zip']) |
| 245 status = OldUploadFile(os.path.abspath(archive_name), GS_SITE + target) |
| 246 os.remove(archive_name) |
| 247 if status == 0: |
| 248 print ('@@@STEP_LINK@download@' + GS_URL + target + '@@@') |
| 249 else: |
| 250 print '@@@STEP_FAILURE@@@' |
| 251 os.chdir(cwd) |
| 252 |
| 253 |
| 254 def ListArchives(pattern): |
| 255 """List the contents in Google storage matching the file pattern. |
| 256 """ |
| 257 cmd = [GSUTIL, 'ls', pattern] |
| 258 (status, output) = ExecuteCommand(cmd) |
| 259 if status != 0: |
| 260 return [] |
| 261 return output.split(os.linesep) |
| 262 |
| 263 |
| 264 def RemoveArchives(archives): |
| 265 """Remove the list of archives in Google storage. |
| 266 """ |
| 267 for archive in archives: |
| 268 if archive.find(GS_SITE) == 0: |
| 269 cmd = [GSUTIL, 'rm', archive.rstrip()] |
| 270 (status, _) = ExecuteCommand(cmd) |
| 271 if status != 0: |
| 272 return status |
| 273 return 0 |
| OLD | NEW |