yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
Yunlian Jiang | 2c4b2a1 | 2013-04-03 11:52:09 -0700 | [diff] [blame] | 2 | |
| 3 | # Copyright (c) 2013 The Chromium OS 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. |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 6 | |
| 7 | """Script to use remote try-bot build image with local gcc.""" |
| 8 | |
| 9 | import argparse |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 10 | import glob |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 11 | import os |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 12 | import re |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 13 | import shutil |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 14 | import socket |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 15 | import sys |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 16 | import tempfile |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 17 | import time |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 18 | |
| 19 | from utils import command_executer |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 20 | from utils import logger |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 21 | from utils import manifest_versions |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 22 | from utils import misc |
| 23 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 24 | BRANCH = "the_actual_branch_used_in_this_script" |
| 25 | TMP_BRANCH = "tmp_branch" |
| 26 | SLEEP_TIME = 600 |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def GetPatchNum(output): |
| 30 | lines = output.splitlines() |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 31 | line = [l for l in lines if "gerrit" in l][0] |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 32 | patch_num = re.findall(r"\d+", line)[0] |
| 33 | if "gerrit-int" in line: |
| 34 | patch_num = "*" + patch_num |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 35 | return str(patch_num) |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 36 | |
| 37 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 38 | def GetPatchString(patch): |
| 39 | if patch: |
| 40 | return "+".join(patch) |
| 41 | return "NO_PATCH" |
| 42 | |
| 43 | |
yunlian | b7783c0 | 2013-03-12 18:31:43 +0000 | [diff] [blame] | 44 | def FindVersionForToolchain(branch, chromeos_root): |
| 45 | """Find the version number in artifacts link in the tryserver email.""" |
| 46 | # For example: input: toolchain-3701.42.B |
yunlian | c244ac0 | 2013-03-12 21:36:43 +0000 | [diff] [blame] | 47 | # output: R26-3701.42.1 |
yunlian | b7783c0 | 2013-03-12 18:31:43 +0000 | [diff] [blame] | 48 | digits = branch.split("-")[1].split("B")[0] |
| 49 | manifest_dir = os.path.join(chromeos_root, "manifest-internal") |
| 50 | os.chdir(manifest_dir) |
| 51 | major_version = digits.split(".")[0] |
| 52 | ce = command_executer.GetCommandExecuter() |
| 53 | command = "repo sync . && git branch -a | grep {0}".format(major_version) |
| 54 | _, branches, _ = ce.RunCommand(command, return_output=True, |
| 55 | print_to_console=False) |
| 56 | m = re.search(r"(R\d+)", branches) |
| 57 | if not m: |
| 58 | logger.GetLogger().LogFatal("Cannot find version for branch {0}" |
| 59 | .format(branch)) |
| 60 | version = m.group(0)+"-"+digits+"1" |
| 61 | return version |
| 62 | |
| 63 | |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 64 | def FindBuildId(description): |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 65 | """Find the build id of the build at trybot server.""" |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 66 | running_time = 0 |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 67 | while True: |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 68 | (result, number) = FindBuildIdFromLog(description) |
| 69 | if result >= 0: |
| 70 | return (result, number) |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 71 | logger.GetLogger().LogOutput("{0} minutes passed." |
| 72 | .format(running_time / 60)) |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 73 | logger.GetLogger().LogOutput("Sleeping {0} seconds.".format(SLEEP_TIME)) |
| 74 | time.sleep(SLEEP_TIME) |
| 75 | running_time += SLEEP_TIME |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 76 | |
| 77 | |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 78 | def FindBuildIdFromLog(description): |
| 79 | """Get the build id from build log.""" |
| 80 | # returns tuple (result, buildid) |
| 81 | # result == 0, buildid > 0, the build was successful and we have a build id |
| 82 | # result > 0, buildid > 0, the whole build failed for some reason but we |
| 83 | # do have a build id. |
| 84 | # result == -1, buildid == -1, we have not found a finished build for this |
| 85 | # description yet |
yunlian | 1d2e8e1 | 2013-03-11 23:27:39 +0000 | [diff] [blame] | 86 | |
yunlian | 33fef35 | 2013-02-19 22:34:52 +0000 | [diff] [blame] | 87 | file_dir = os.path.dirname(os.path.realpath(__file__)) |
| 88 | commands = ("{0}/utils/buildbot_json.py builds " |
| 89 | "http://chromegw/p/tryserver.chromiumos/" |
| 90 | .format(file_dir)) |
| 91 | ce = command_executer.GetCommandExecuter() |
| 92 | _, buildinfo, _ = ce.RunCommand(commands, return_output=True, |
| 93 | print_to_console=False) |
| 94 | |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 95 | my_info = buildinfo.splitlines() |
| 96 | current_line = 1 |
yunlian | 1d2e8e1 | 2013-03-11 23:27:39 +0000 | [diff] [blame] | 97 | running_job = False |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 98 | result = -1 |
| 99 | |
| 100 | # result == 0, we have a successful build |
| 101 | # result > 0, we have a failed build but build id may be valid |
| 102 | # result == -1, we have not found a finished build for this description |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 103 | while current_line < len(my_info): |
| 104 | my_dict = {} |
| 105 | while True: |
| 106 | key = my_info[current_line].split(":")[0].strip() |
| 107 | value = my_info[current_line].split(":", 1)[1].strip() |
| 108 | my_dict[key] = value |
| 109 | current_line += 1 |
| 110 | if "Build" in key or current_line == len(my_info): |
| 111 | break |
yunlian | 1d2e8e1 | 2013-03-11 23:27:39 +0000 | [diff] [blame] | 112 | if ("True" not in my_dict["completed"] and |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 113 | str(description) in my_dict["reason"]): |
yunlian | 1d2e8e1 | 2013-03-11 23:27:39 +0000 | [diff] [blame] | 114 | running_job = True |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 115 | if ("True" not in my_dict["completed"] or |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 116 | str(description) not in my_dict["reason"]): |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 117 | continue |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 118 | result = int(my_dict["result"]) |
| 119 | build_id = int(my_dict["number"]) |
| 120 | if result == 0: |
| 121 | return (result, build_id) |
| 122 | else |
| 123 | # Found a finished failed build. |
| 124 | # Keep searching to find a successful one |
| 125 | pass |
| 126 | |
| 127 | if result > 0 and not running_job: |
| 128 | return (result, build_id) |
| 129 | return (-1, -1) |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 130 | |
| 131 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 132 | def DownloadImage(target, index, dest, version): |
| 133 | """Download artifacts from cloud.""" |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 134 | if not os.path.exists(dest): |
| 135 | os.makedirs(dest) |
| 136 | |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 137 | rversion = manifest_versions.RFormatCrosVersion(version) |
| 138 | # ls_cmd = ("gsutil ls gs://chromeos-image-archive/trybot-{0}/{1}-b{2}" |
| 139 | # .format(target, rversion, index)) |
| 140 | ls_cmd = ("gsutil ls gs://chromeos-image-archive/trybot-{0}/*-b{2}" |
| 141 | .format(target, rversion, index)) |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 142 | |
| 143 | download_cmd = ("$(which gsutil) cp {0} {1}".format("{0}", dest)) |
| 144 | ce = command_executer.GetCommandExecuter() |
| 145 | |
| 146 | _, out, _ = ce.RunCommand(ls_cmd, return_output=True, print_to_console=True) |
| 147 | lines = out.splitlines() |
| 148 | download_files = ["autotest.tar", "chromeos-chrome", |
| 149 | "chromiumos_test_image", "debug.tgz", |
| 150 | "sysroot_chromeos-base_chromeos-chrome.tar.xz" |
| 151 | ] |
| 152 | for line in lines: |
| 153 | if any([e in line for e in download_files]): |
| 154 | cmd = download_cmd.format(line) |
| 155 | if ce.RunCommand(cmd): |
yunlian | 33fef35 | 2013-02-19 22:34:52 +0000 | [diff] [blame] | 156 | logger.GetLogger().LogFatal("Command {0} failed, existing..." |
| 157 | .format(cmd)) |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 158 | |
| 159 | |
| 160 | def UnpackImage(dest): |
| 161 | """Unpack the image, the chroot build dir.""" |
| 162 | chrome_tbz2 = glob.glob(dest+"/*.tbz2")[0] |
| 163 | commands = ("tar xJf {0}/sysroot_chromeos-base_chromeos-chrome.tar.xz " |
| 164 | "-C {0} &&" |
| 165 | "tar xjf {1} -C {0} &&" |
| 166 | "tar xzf {0}/debug.tgz -C {0}/usr/lib/ &&" |
| 167 | "tar xf {0}/autotest.tar -C {0}/usr/local/ &&" |
| 168 | "tar xJf {0}/chromiumos_test_image.tar.xz -C {0}" |
| 169 | .format(dest, chrome_tbz2)) |
| 170 | ce = command_executer.GetCommandExecuter() |
| 171 | return ce.RunCommand(commands) |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 172 | |
| 173 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 174 | def RemoveOldBranch(): |
| 175 | """Remove the branch with name BRANCH.""" |
| 176 | ce = command_executer.GetCommandExecuter() |
| 177 | command = "git rev-parse --abbrev-ref HEAD" |
| 178 | _, out, _ = ce.RunCommand(command, return_output=True) |
| 179 | if BRANCH in out: |
| 180 | command = "git checkout -B {0}".format(TMP_BRANCH) |
| 181 | ce.RunCommand(command) |
| 182 | command = "git commit -m 'nouse'" |
| 183 | ce.RunCommand(command) |
| 184 | command = "git branch -D {0}".format(BRANCH) |
| 185 | ce.RunCommand(command) |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 186 | |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 187 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 188 | def UploadManifest(manifest, chromeos_root, branch="master"): |
| 189 | """Copy the manifest to $chromeos_root/manifest-internal and upload.""" |
| 190 | chromeos_root = misc.CanonicalizePath(chromeos_root) |
| 191 | manifest_dir = os.path.join(chromeos_root, "manifest-internal") |
| 192 | os.chdir(manifest_dir) |
| 193 | ce = command_executer.GetCommandExecuter() |
yunlian | 33fef35 | 2013-02-19 22:34:52 +0000 | [diff] [blame] | 194 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 195 | RemoveOldBranch() |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 196 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 197 | if branch != "master": |
| 198 | branch = "{0}".format(branch) |
| 199 | command = "git checkout -b {0} -t cros-internal/{1}".format(BRANCH, branch) |
| 200 | ret = ce.RunCommand(command) |
| 201 | if ret: |
| 202 | raise Exception("Command {0} failed".format(command)) |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 203 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 204 | # We remove the default.xml, which is the symbolic link of full.xml. |
| 205 | # After that, we copy our xml file to default.xml. |
| 206 | # We did this because the full.xml might be updated during the |
| 207 | # run of the script. |
| 208 | os.remove(os.path.join(manifest_dir, "default.xml")) |
| 209 | shutil.copyfile(manifest, os.path.join(manifest_dir, "default.xml")) |
| 210 | return UploadPatch(manifest) |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 211 | |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 212 | |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 213 | def GetManifestPatch(manifests, version, chromeos_root, branch="master"): |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 214 | """Return a gerrit patch number given a version of manifest file.""" |
| 215 | temp_dir = tempfile.mkdtemp() |
| 216 | to_file = os.path.join(temp_dir, "default.xml") |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 217 | manifests.GetManifest(version, to_file) |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 218 | return UploadManifest(to_file, chromeos_root, branch) |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 219 | |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 220 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 221 | def UploadPatch(source): |
| 222 | """Up load patch to gerrit, return patch number.""" |
| 223 | commands = ("git add -A . &&" |
| 224 | "git commit -m 'test' -m 'BUG=None' -m 'TEST=None' " |
| 225 | "-m 'hostname={0}' -m 'source={1}'" |
| 226 | .format(socket.gethostname(), source)) |
| 227 | ce = command_executer.GetCommandExecuter() |
| 228 | ce.RunCommand(commands) |
yunlian | 33fef35 | 2013-02-19 22:34:52 +0000 | [diff] [blame] | 229 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 230 | commands = ("yes | repo upload . --cbr --no-verify") |
| 231 | _, _, err = ce.RunCommand(commands, return_output=True) |
| 232 | return GetPatchNum(err) |
yunlian | 952441d | 2013-02-19 22:34:53 +0000 | [diff] [blame] | 233 | |
yunlian | 952441d | 2013-02-19 22:34:53 +0000 | [diff] [blame] | 234 | |
yunlian | b7783c0 | 2013-03-12 18:31:43 +0000 | [diff] [blame] | 235 | def ReplaceSysroot(chromeos_root, dest_dir, target): |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 236 | """Copy unpacked sysroot and image to chromeos_root.""" |
| 237 | ce = command_executer.GetCommandExecuter() |
Luis Lozano | 9d1db65 | 2013-03-25 11:28:57 -0700 | [diff] [blame] | 238 | # get the board name from "board-release". board may contain "-" |
| 239 | board = target.rsplit("-", 1)[0] |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 240 | board_dir = os.path.join(chromeos_root, "chroot", "build", board) |
| 241 | command = "sudo rm -rf {0}".format(board_dir) |
| 242 | ce.RunCommand(command) |
| 243 | |
| 244 | command = "sudo mv {0} {1}".format(dest_dir, board_dir) |
| 245 | ce.RunCommand(command) |
| 246 | |
| 247 | image_dir = os.path.join(chromeos_root, "src", "build", "images", |
| 248 | board, "latest") |
| 249 | command = "rm -rf {0} && mkdir -p {0}".format(image_dir) |
| 250 | ce.RunCommand(command) |
| 251 | |
| 252 | command = "mv {0}/chromiumos_test_image.bin {1}".format(board_dir, image_dir) |
| 253 | return ce.RunCommand(command) |
| 254 | |
| 255 | |
| 256 | def GccBranchForToolchain(branch): |
| 257 | if branch == "toolchain-3428.65.B": |
| 258 | return "release-R25-3428.B" |
| 259 | else: |
| 260 | return None |
| 261 | |
| 262 | |
| 263 | def GetGccBranch(branch): |
| 264 | """Get the remote branch name from branch or version.""" |
| 265 | ce = command_executer.GetCommandExecuter() |
| 266 | command = "git branch -a | grep {0}".format(branch) |
| 267 | _, out, _ = ce.RunCommand(command, return_output=True) |
| 268 | if not out: |
| 269 | release_num = re.match(r".*(R\d+)-*", branch) |
| 270 | if release_num: |
| 271 | release_num = release_num.group(0) |
| 272 | command = "git branch -a | grep {0}".format(release_num) |
| 273 | _, out, _ = ce.RunCommand(command, return_output=True) |
| 274 | if not out: |
| 275 | GccBranchForToolchain(branch) |
| 276 | if not out: |
Yunlian Jiang | cc4ef90 | 2013-04-04 11:15:58 -0700 | [diff] [blame] | 277 | out = "remotes/cros/master" |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 278 | new_branch = out.splitlines()[0] |
| 279 | return new_branch |
| 280 | |
| 281 | |
| 282 | def UploadGccPatch(chromeos_root, gcc_dir, branch): |
| 283 | """Upload local gcc to gerrit and get the CL number.""" |
| 284 | ce = command_executer.GetCommandExecuter() |
| 285 | gcc_dir = misc.CanonicalizePath(gcc_dir) |
| 286 | gcc_path = os.path.join(chromeos_root, "src/third_party/gcc") |
| 287 | assert os.path.isdir(gcc_path), ("{0} is not a valid chromeos root" |
| 288 | .format(chromeos_root)) |
| 289 | assert os.path.isdir(gcc_dir), ("{0} is not a valid dir for gcc" |
| 290 | "source".format(gcc_dir)) |
| 291 | os.chdir(gcc_path) |
| 292 | RemoveOldBranch() |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 293 | if not branch: |
| 294 | branch = "master" |
| 295 | branch = GetGccBranch(branch) |
Yunlian Jiang | cc4ef90 | 2013-04-04 11:15:58 -0700 | [diff] [blame] | 296 | command = ("git checkout -b {0} -t {1} && " |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 297 | "rm -rf *".format(BRANCH, branch)) |
| 298 | ce.RunCommand(command, print_to_console=False) |
| 299 | |
| 300 | command = ("rsync -az --exclude='*.svn' --exclude='*.git'" |
| 301 | " {0}/ .".format(gcc_dir)) |
| 302 | ce.RunCommand(command) |
| 303 | return UploadPatch(gcc_dir) |
| 304 | |
| 305 | |
| 306 | def RunRemote(chromeos_root, branch, patches, is_local, |
| 307 | target, chrome_version, dest_dir): |
| 308 | """The actual running commands.""" |
| 309 | ce = command_executer.GetCommandExecuter() |
| 310 | |
| 311 | if is_local: |
| 312 | local_flag = "--local -r {0}".format(dest_dir) |
| 313 | else: |
| 314 | local_flag = "--remote" |
| 315 | patch = "" |
| 316 | for p in patches: |
| 317 | patch += " -g {0}".format(p) |
| 318 | cbuildbot_path = os.path.join(chromeos_root, "chromite/buildbot") |
| 319 | os.chdir(cbuildbot_path) |
| 320 | branch_flag = "" |
| 321 | if branch != "master": |
| 322 | branch_flag = " -b {0}".format(branch) |
| 323 | chrome_version_flag = "" |
| 324 | if chrome_version: |
| 325 | chrome_version_flag = " --chrome_version={0}".format(chrome_version) |
| 326 | description = "{0}_{1}_{2}".format(branch, GetPatchString(patches), target) |
| 327 | command = ("yes | ./cbuildbot {0} {1} {2} {3} {4} {5}" |
| 328 | " --remote-description={6}" |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 329 | " --chrome_rev=tot" |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 330 | .format(patch, branch_flag, chrome_version, local_flag, |
| 331 | chrome_version_flag, target, description)) |
| 332 | ce.RunCommand(command) |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 333 | |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 334 | return description |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 335 | |
| 336 | |
| 337 | def Main(argv): |
| 338 | """The main function.""" |
| 339 | # Common initializations |
| 340 | parser = argparse.ArgumentParser() |
| 341 | parser.add_argument("-c", "--chromeos_root", required=True, |
| 342 | dest="chromeos_root", help="The chromeos_root") |
yunlian | 33fef35 | 2013-02-19 22:34:52 +0000 | [diff] [blame] | 343 | parser.add_argument("-g", "--gcc_dir", default="", dest="gcc_dir", |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 344 | help="The gcc dir") |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 345 | parser.add_argument("-t", "--target", required=True, dest="target", |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 346 | help=("The target to be build, the list is at" |
| 347 | " $(chromeos_root)/chromite/buildbot/cbuildbot" |
| 348 | " --list -all")) |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 349 | parser.add_argument("-l", "--local", action="store_true") |
| 350 | parser.add_argument("-d", "--dest_dir", dest="dest_dir", |
| 351 | help=("The dir to build the whole chromeos if" |
| 352 | " --local is set")) |
yunlian | 952441d | 2013-02-19 22:34:53 +0000 | [diff] [blame] | 353 | parser.add_argument("--chrome_version", dest="chrome_version", |
| 354 | default="", help="The chrome version to use. " |
| 355 | "Default it will use the latest one.") |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 356 | parser.add_argument("--chromeos_version", dest="chromeos_version", |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 357 | default="", |
| 358 | help=("The chromeos version to use." |
| 359 | "(1) A release version in the format: " |
| 360 | "'\d+\.\d+\.\d+\.\d+.*'" |
| 361 | "(2) 'latest_lkgm' for the latest lkgm version")) |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 362 | parser.add_argument("-r", "--replace_sysroot", action="store_true", |
| 363 | help=("Whether or not to replace the build/$board dir" |
| 364 | "under the chroot of chromeos_root and copy " |
| 365 | "the image to src/build/image/$board/latest." |
| 366 | " Default is False")) |
Yunlian Jiang | 5b0ad87 | 2013-04-03 16:39:27 -0700 | [diff] [blame] | 367 | parser.add_argument("-b", "--branch", dest="branch", default="", |
| 368 | help=("The branch to run trybot, default is None")) |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 369 | parser.add_argument("-p", "--patch", dest="patch", default="", |
| 370 | help=("The patches to be applied, the patches numbers " |
| 371 | "be seperated by ','")) |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 372 | |
| 373 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 374 | |
| 375 | args = parser.parse_args(argv[1:]) |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 376 | target = args.target |
Yunlian Jiang | 6845e5f | 2013-04-10 13:53:37 -0700 | [diff] [blame] | 377 | if args.patch: |
| 378 | patch = args.patch.split(",") |
| 379 | else: |
| 380 | patch = [] |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 381 | chromeos_root = misc.CanonicalizePath(args.chromeos_root) |
Yunlian Jiang | 5b0ad87 | 2013-04-03 16:39:27 -0700 | [diff] [blame] | 382 | if args.chromeos_version and args.branch: |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 383 | raise Exception("You can not set chromeos_version and branch at the " |
| 384 | "same time.") |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 385 | |
| 386 | manifests = None |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 387 | if args.branch: |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 388 | chromeos_version = "" |
| 389 | branch = args.branch |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 390 | else: |
| 391 | chromeos_version = args.chromeos_version |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 392 | manifests = manifest_versions.ManifestVersions() |
| 393 | if chromeos_version == "latest_lkgm": |
| 394 | chromeos_version = manifests.TimeToVersion(time.mktime(time.gmtime())) |
| 395 | logger.GetLogger().LogOutput("found version %s for latest LKGM" % ( |
| 396 | chromeos_version)) |
| 397 | # TODO: this script currently does not handle the case where the version |
| 398 | # is not in the "master" branch |
| 399 | branch = "master" |
| 400 | |
yunlian | c244ac0 | 2013-03-12 21:36:43 +0000 | [diff] [blame] | 401 | if chromeos_version: |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 402 | manifest_patch = GetManifestPatch(manifests, chromeos_version, |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 403 | chromeos_root) |
| 404 | patch.append(manifest_patch) |
| 405 | if args.gcc_dir: |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 406 | # TODO: everytime we invoke this script we are getting a different |
| 407 | # patch for GCC even if GCC has not changed. The description should |
| 408 | # be based on the MD5 of the GCC patch contents. |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 409 | patch.append(UploadGccPatch(chromeos_root, args.gcc_dir, branch)) |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 410 | description = RunRemote(chromeos_root, branch, patch, args.local, |
| 411 | target, args.chrome_version, args.dest_dir) |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 412 | if args.local or not args.dest_dir: |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 413 | # TODO: We are not checktng the result of cbuild_bot in here! |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 414 | return 0 |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 415 | |
| 416 | # return value: |
| 417 | # 0 => build bot was successful and image was put where requested |
| 418 | # 1 => Build bot FAILED but image was put where requested |
| 419 | # 2 => Build bot failed or BUild bot was successful but and image was |
| 420 | # not generated or could not be put where expected |
| 421 | |
yunlian | f4566c9 | 2013-02-19 22:34:13 +0000 | [diff] [blame] | 422 | os.chdir(script_dir) |
| 423 | dest_dir = misc.CanonicalizePath(args.dest_dir) |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 424 | (bot_result, build_id) = FindBuildId(description) |
| 425 | if bot_result > 0 and build_id > 0: |
| 426 | logger.GetLogger().LogError("Remote trybot failed but image was generated") |
| 427 | bot_result = 1 |
| 428 | elif bot_result > 0: |
| 429 | logger.GetLogger().LogError("Remote trybot failed. No image was generated") |
| 430 | return 2 |
yunlian | b7783c0 | 2013-03-12 18:31:43 +0000 | [diff] [blame] | 431 | if "toolchain" in branch: |
| 432 | chromeos_version = FindVersionForToolchain(branch, chromeos_root) |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 433 | assert not manifest_versions.IsRFormatCrosVersion(chromeos_version) |
| 434 | DownloadImage(target, build_id, dest_dir, chromeos_version) |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 435 | ret = UnpackImage(dest_dir) |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 436 | if ret != 0: |
| 437 | return 2 |
| 438 | # todo: return a more inteligent return value |
yunlian | c9a6e77 | 2013-03-04 21:38:20 +0000 | [diff] [blame] | 439 | if not args.replace_sysroot: |
Luis Lozano | 8cf5308 | 2013-08-01 12:35:11 -0700 | [diff] [blame] | 440 | return bot_result |
| 441 | |
| 442 | ret = ReplaceSysroot(chromeos_root, args.dest_dir, target) |
| 443 | if ret != 0: |
| 444 | return 2 |
| 445 | |
| 446 | # got an image and we were successful in placing it where requested |
| 447 | return bot_result |
yunlian | b5851d3 | 2013-02-19 21:36:46 +0000 | [diff] [blame] | 448 | |
| 449 | if __name__ == "__main__": |
| 450 | retval = Main(sys.argv) |
| 451 | sys.exit(retval) |