fix(bin/linja): download ninja to a temporary directory

Assume that we have two linja processes running on a system where there
is no ninja installed. Then, the first linja process downloads ninja
from github. If the internet is slow, the second linja process can pick
up the incomplete ninja binary and execute it, which causes an
exception (i.e. "Malformed Mach-o file" error on OSX). An example build
trace is at

    https://s3.amazonaws.com/archive.travis-ci.org/jobs/56366771/log.txt

This commit fixes the problem by downloading ninja to a temporary
directory and copy it to "lean/bin/ninja" when it's completed.
This commit is contained in:
Soonho Kong 2015-03-30 01:20:24 -04:00
parent 3ac29fae43
commit 47c0ae5914

View file

@ -289,10 +289,13 @@ def download_ninja_and_save_at(ninja_path):
else: else:
url = get_ninja_url() url = get_ninja_url()
log("Downloading ninja: %s ===> %s\n" % (url, ninja_path)) log("Downloading ninja: %s ===> %s\n" % (url, ninja_path))
urlretrieve(url, ninja_path, show_download_progress) tempdir = tempfile.mkdtemp()
temp_download_path = os.path.join(tempdir, os.path.split(ninja_path)[1])
urlretrieve(url, temp_download_path, show_download_progress)
log("\n") log("\n")
if not os.path.isfile(ninja_path): if not os.path.isfile(temp_download_path):
error("failed to download ninja executable from %s" % url) error("failed to download ninja executable from %s" % url)
shutil.copy2(temp_download_path, ninja_path)
give_exec_permission(ninja_path) give_exec_permission(ninja_path)
return ninja_path return ninja_path