blob: 8ed324aad21e4ab44eb67b331fa93c929826864a [file] [log] [blame]
yunlianb5851d32013-02-19 21:36:46 +00001#!/usr/bin/python
Yunlian Jiang2c4b2a12013-04-03 11:52:09 -07002
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.
yunlianb5851d32013-02-19 21:36:46 +00006
7"""Script to use remote try-bot build image with local gcc."""
8
9import argparse
yunlianf4566c92013-02-19 22:34:13 +000010import glob
yunlianb5851d32013-02-19 21:36:46 +000011import os
yunlianf4566c92013-02-19 22:34:13 +000012import re
yunlianc9a6e772013-03-04 21:38:20 +000013import shutil
yunlianf4566c92013-02-19 22:34:13 +000014import socket
yunlianb5851d32013-02-19 21:36:46 +000015import sys
yunlianc9a6e772013-03-04 21:38:20 +000016import tempfile
yunlianf4566c92013-02-19 22:34:13 +000017import time
yunlianb5851d32013-02-19 21:36:46 +000018
19from utils import command_executer
yunlianf4566c92013-02-19 22:34:13 +000020from utils import logger
Luis Lozano8cf53082013-08-01 12:35:11 -070021from utils import manifest_versions
yunlianb5851d32013-02-19 21:36:46 +000022from utils import misc
23
yunlianc9a6e772013-03-04 21:38:20 +000024BRANCH = "the_actual_branch_used_in_this_script"
25TMP_BRANCH = "tmp_branch"
26SLEEP_TIME = 600
yunlianf4566c92013-02-19 22:34:13 +000027
28
29def GetPatchNum(output):
30 lines = output.splitlines()
Luis Lozano6aebeb12013-09-03 01:55:02 -070031 line = [l for l in lines if "googlesource" in l][0]
yunlianf4566c92013-02-19 22:34:13 +000032 patch_num = re.findall(r"\d+", line)[0]
Luis Lozano6aebeb12013-09-03 01:55:02 -070033 if "chrome-internal" in line:
yunlianf4566c92013-02-19 22:34:13 +000034 patch_num = "*" + patch_num
yunlianc9a6e772013-03-04 21:38:20 +000035 return str(patch_num)
yunlianf4566c92013-02-19 22:34:13 +000036
37
yunlianc9a6e772013-03-04 21:38:20 +000038def GetPatchString(patch):
39 if patch:
40 return "+".join(patch)
41 return "NO_PATCH"
42
43
yunlianb7783c02013-03-12 18:31:43 +000044def FindVersionForToolchain(branch, chromeos_root):
45 """Find the version number in artifacts link in the tryserver email."""
46 # For example: input: toolchain-3701.42.B
yunlianc244ac02013-03-12 21:36:43 +000047 # output: R26-3701.42.1
yunlianb7783c02013-03-12 18:31:43 +000048 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 Lozano8cf53082013-08-01 12:35:11 -070064def FindBuildId(description):
yunlianf4566c92013-02-19 22:34:13 +000065 """Find the build id of the build at trybot server."""
yunlianf4566c92013-02-19 22:34:13 +000066 running_time = 0
yunlianc9a6e772013-03-04 21:38:20 +000067 while True:
Luis Lozano8cf53082013-08-01 12:35:11 -070068 (result, number) = FindBuildIdFromLog(description)
69 if result >= 0:
70 return (result, number)
yunlianf4566c92013-02-19 22:34:13 +000071 logger.GetLogger().LogOutput("{0} minutes passed."
72 .format(running_time / 60))
yunlianc9a6e772013-03-04 21:38:20 +000073 logger.GetLogger().LogOutput("Sleeping {0} seconds.".format(SLEEP_TIME))
74 time.sleep(SLEEP_TIME)
75 running_time += SLEEP_TIME
yunlianf4566c92013-02-19 22:34:13 +000076
77
Luis Lozano8cf53082013-08-01 12:35:11 -070078def 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
yunlian1d2e8e12013-03-11 23:27:39 +000086
yunlian33fef352013-02-19 22:34:52 +000087 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
yunlianf4566c92013-02-19 22:34:13 +000095 my_info = buildinfo.splitlines()
96 current_line = 1
yunlian1d2e8e12013-03-11 23:27:39 +000097 running_job = False
Luis Lozano8cf53082013-08-01 12:35:11 -070098 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
yunlianf4566c92013-02-19 22:34:13 +0000103 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
yunlian1d2e8e12013-03-11 23:27:39 +0000112 if ("True" not in my_dict["completed"] and
Luis Lozano8cf53082013-08-01 12:35:11 -0700113 str(description) in my_dict["reason"]):
yunlian1d2e8e12013-03-11 23:27:39 +0000114 running_job = True
yunlianf4566c92013-02-19 22:34:13 +0000115 if ("True" not in my_dict["completed"] or
Luis Lozano8cf53082013-08-01 12:35:11 -0700116 str(description) not in my_dict["reason"]):
yunlianf4566c92013-02-19 22:34:13 +0000117 continue
Luis Lozano8cf53082013-08-01 12:35:11 -0700118 result = int(my_dict["result"])
119 build_id = int(my_dict["number"])
120 if result == 0:
121 return (result, build_id)
Luis Lozanocd968c82013-08-19 10:42:10 -0700122 else:
Luis Lozano8cf53082013-08-01 12:35:11 -0700123 # 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)
yunlianf4566c92013-02-19 22:34:13 +0000130
131
yunlianc9a6e772013-03-04 21:38:20 +0000132def DownloadImage(target, index, dest, version):
133 """Download artifacts from cloud."""
yunlianf4566c92013-02-19 22:34:13 +0000134 if not os.path.exists(dest):
135 os.makedirs(dest)
136
Luis Lozano8cf53082013-08-01 12:35:11 -0700137 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))
yunlianf4566c92013-02-19 22:34:13 +0000142
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):
yunlian33fef352013-02-19 22:34:52 +0000156 logger.GetLogger().LogFatal("Command {0} failed, existing..."
157 .format(cmd))
yunlianf4566c92013-02-19 22:34:13 +0000158
159
160def 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)
yunlianb5851d32013-02-19 21:36:46 +0000172
173
yunlianc9a6e772013-03-04 21:38:20 +0000174def 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)
yunlianb5851d32013-02-19 21:36:46 +0000186
yunlianb5851d32013-02-19 21:36:46 +0000187
yunlianc9a6e772013-03-04 21:38:20 +0000188def 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()
yunlian33fef352013-02-19 22:34:52 +0000194
yunlianc9a6e772013-03-04 21:38:20 +0000195 RemoveOldBranch()
yunlianb5851d32013-02-19 21:36:46 +0000196
yunlianc9a6e772013-03-04 21:38:20 +0000197 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))
yunlianb5851d32013-02-19 21:36:46 +0000203
yunlianc9a6e772013-03-04 21:38:20 +0000204 # 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)
yunlianb5851d32013-02-19 21:36:46 +0000211
yunlianb5851d32013-02-19 21:36:46 +0000212
Luis Lozano8cf53082013-08-01 12:35:11 -0700213def GetManifestPatch(manifests, version, chromeos_root, branch="master"):
yunlianc9a6e772013-03-04 21:38:20 +0000214 """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 Lozano8cf53082013-08-01 12:35:11 -0700217 manifests.GetManifest(version, to_file)
yunlianc9a6e772013-03-04 21:38:20 +0000218 return UploadManifest(to_file, chromeos_root, branch)
yunlianb5851d32013-02-19 21:36:46 +0000219
yunlianf4566c92013-02-19 22:34:13 +0000220
yunlianc9a6e772013-03-04 21:38:20 +0000221def 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)
yunlian33fef352013-02-19 22:34:52 +0000229
yunlianc9a6e772013-03-04 21:38:20 +0000230 commands = ("yes | repo upload . --cbr --no-verify")
231 _, _, err = ce.RunCommand(commands, return_output=True)
232 return GetPatchNum(err)
yunlian952441d2013-02-19 22:34:53 +0000233
yunlian952441d2013-02-19 22:34:53 +0000234
yunlianb7783c02013-03-12 18:31:43 +0000235def ReplaceSysroot(chromeos_root, dest_dir, target):
yunlianc9a6e772013-03-04 21:38:20 +0000236 """Copy unpacked sysroot and image to chromeos_root."""
237 ce = command_executer.GetCommandExecuter()
Luis Lozano9d1db652013-03-25 11:28:57 -0700238 # get the board name from "board-release". board may contain "-"
239 board = target.rsplit("-", 1)[0]
yunlianc9a6e772013-03-04 21:38:20 +0000240 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
256def GccBranchForToolchain(branch):
257 if branch == "toolchain-3428.65.B":
258 return "release-R25-3428.B"
259 else:
260 return None
261
262
263def 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 Jiangcc4ef902013-04-04 11:15:58 -0700277 out = "remotes/cros/master"
yunlianc9a6e772013-03-04 21:38:20 +0000278 new_branch = out.splitlines()[0]
279 return new_branch
280
281
282def 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()
yunlianc9a6e772013-03-04 21:38:20 +0000293 if not branch:
294 branch = "master"
295 branch = GetGccBranch(branch)
Yunlian Jiangcc4ef902013-04-04 11:15:58 -0700296 command = ("git checkout -b {0} -t {1} && "
yunlianc9a6e772013-03-04 21:38:20 +0000297 "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
306def 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)
Don Garrett4eb64532014-05-15 18:50:25 -0700318 cbuildbot_path = os.path.join(chromeos_root, "chromite/cbuildbot")
yunlianc9a6e772013-03-04 21:38:20 +0000319 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 Lozano8cf53082013-08-01 12:35:11 -0700329 " --chrome_rev=tot"
yunlianc9a6e772013-03-04 21:38:20 +0000330 .format(patch, branch_flag, chrome_version, local_flag,
331 chrome_version_flag, target, description))
332 ce.RunCommand(command)
Luis Lozano8cf53082013-08-01 12:35:11 -0700333
yunlianc9a6e772013-03-04 21:38:20 +0000334 return description
yunlianb5851d32013-02-19 21:36:46 +0000335
336
337def 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")
yunlian33fef352013-02-19 22:34:52 +0000343 parser.add_argument("-g", "--gcc_dir", default="", dest="gcc_dir",
yunlianb5851d32013-02-19 21:36:46 +0000344 help="The gcc dir")
yunlianc9a6e772013-03-04 21:38:20 +0000345 parser.add_argument("-t", "--target", required=True, dest="target",
yunlianb5851d32013-02-19 21:36:46 +0000346 help=("The target to be build, the list is at"
347 " $(chromeos_root)/chromite/buildbot/cbuildbot"
348 " --list -all"))
yunlianf4566c92013-02-19 22:34:13 +0000349 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"))
yunlian952441d2013-02-19 22:34:53 +0000353 parser.add_argument("--chrome_version", dest="chrome_version",
354 default="", help="The chrome version to use. "
355 "Default it will use the latest one.")
yunlianc9a6e772013-03-04 21:38:20 +0000356 parser.add_argument("--chromeos_version", dest="chromeos_version",
Luis Lozano8cf53082013-08-01 12:35:11 -0700357 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"))
yunlianc9a6e772013-03-04 21:38:20 +0000362 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 Jiang5b0ad872013-04-03 16:39:27 -0700367 parser.add_argument("-b", "--branch", dest="branch", default="",
368 help=("The branch to run trybot, default is None"))
yunlianc9a6e772013-03-04 21:38:20 +0000369 parser.add_argument("-p", "--patch", dest="patch", default="",
370 help=("The patches to be applied, the patches numbers "
371 "be seperated by ','"))
yunlianf4566c92013-02-19 22:34:13 +0000372
373 script_dir = os.path.dirname(os.path.realpath(__file__))
yunlianb5851d32013-02-19 21:36:46 +0000374
375 args = parser.parse_args(argv[1:])
yunlianb5851d32013-02-19 21:36:46 +0000376 target = args.target
Yunlian Jiang6845e5f2013-04-10 13:53:37 -0700377 if args.patch:
378 patch = args.patch.split(",")
379 else:
380 patch = []
yunlianc9a6e772013-03-04 21:38:20 +0000381 chromeos_root = misc.CanonicalizePath(args.chromeos_root)
Yunlian Jiang5b0ad872013-04-03 16:39:27 -0700382 if args.chromeos_version and args.branch:
yunlianc9a6e772013-03-04 21:38:20 +0000383 raise Exception("You can not set chromeos_version and branch at the "
384 "same time.")
Luis Lozano8cf53082013-08-01 12:35:11 -0700385
386 manifests = None
yunlianc9a6e772013-03-04 21:38:20 +0000387 if args.branch:
Luis Lozano8cf53082013-08-01 12:35:11 -0700388 chromeos_version = ""
389 branch = args.branch
yunlianc9a6e772013-03-04 21:38:20 +0000390 else:
391 chromeos_version = args.chromeos_version
Luis Lozano8cf53082013-08-01 12:35:11 -0700392 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
yunlianc244ac02013-03-12 21:36:43 +0000401 if chromeos_version:
Luis Lozano8cf53082013-08-01 12:35:11 -0700402 manifest_patch = GetManifestPatch(manifests, chromeos_version,
yunlianc9a6e772013-03-04 21:38:20 +0000403 chromeos_root)
404 patch.append(manifest_patch)
405 if args.gcc_dir:
Luis Lozano8cf53082013-08-01 12:35:11 -0700406 # 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.
yunlianc9a6e772013-03-04 21:38:20 +0000409 patch.append(UploadGccPatch(chromeos_root, args.gcc_dir, branch))
yunlianc9a6e772013-03-04 21:38:20 +0000410 description = RunRemote(chromeos_root, branch, patch, args.local,
411 target, args.chrome_version, args.dest_dir)
yunlianf4566c92013-02-19 22:34:13 +0000412 if args.local or not args.dest_dir:
Luis Lozano8cf53082013-08-01 12:35:11 -0700413 # TODO: We are not checktng the result of cbuild_bot in here!
yunlianf4566c92013-02-19 22:34:13 +0000414 return 0
Luis Lozano8cf53082013-08-01 12:35:11 -0700415
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
yunlianf4566c92013-02-19 22:34:13 +0000422 os.chdir(script_dir)
423 dest_dir = misc.CanonicalizePath(args.dest_dir)
Luis Lozano8cf53082013-08-01 12:35:11 -0700424 (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
yunlianb7783c02013-03-12 18:31:43 +0000431 if "toolchain" in branch:
432 chromeos_version = FindVersionForToolchain(branch, chromeos_root)
Luis Lozano8cf53082013-08-01 12:35:11 -0700433 assert not manifest_versions.IsRFormatCrosVersion(chromeos_version)
434 DownloadImage(target, build_id, dest_dir, chromeos_version)
yunlianc9a6e772013-03-04 21:38:20 +0000435 ret = UnpackImage(dest_dir)
Luis Lozano8cf53082013-08-01 12:35:11 -0700436 if ret != 0:
437 return 2
438 # todo: return a more inteligent return value
yunlianc9a6e772013-03-04 21:38:20 +0000439 if not args.replace_sysroot:
Luis Lozano8cf53082013-08-01 12:35:11 -0700440 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
yunlianb5851d32013-02-19 21:36:46 +0000448
449if __name__ == "__main__":
450 retval = Main(sys.argv)
451 sys.exit(retval)