mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-12-24 08:09:16 -05:00
Download ninja and gn binaries from github (#307)
This commit is contained in:
parent
eedcb91e92
commit
3e63d63223
2 changed files with 16 additions and 45 deletions
19
build.rs
19
build.rs
|
@ -47,7 +47,7 @@ fn build_v8() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if need_gn_ninja_download() {
|
if need_gn_ninja_download() {
|
||||||
download_gn_ninja_binaries();
|
download_ninja_gn_binaries();
|
||||||
}
|
}
|
||||||
|
|
||||||
// On windows, rustc cannot link with a V8 debug build.
|
// On windows, rustc cannot link with a V8 debug build.
|
||||||
|
@ -128,7 +128,7 @@ fn platform() -> &'static str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn download_gn_ninja_binaries() {
|
fn download_ninja_gn_binaries() {
|
||||||
let root = env::current_dir().unwrap();
|
let root = env::current_dir().unwrap();
|
||||||
// target/debug//build/rusty_v8-d9e5a424d4f96994/out/
|
// target/debug//build/rusty_v8-d9e5a424d4f96994/out/
|
||||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||||
|
@ -141,10 +141,11 @@ fn download_gn_ninja_binaries() {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.parent()
|
.parent()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let download_dir = target_dir.join("gn_ninja_binaries");
|
let bin_dir = target_dir
|
||||||
let d = download_dir.join("gn_ninja_binaries").join(platform());
|
.join("ninja_gn_binaries-20191129")
|
||||||
let gn = d.join("gn");
|
.join(platform());
|
||||||
let ninja = d.join("ninja");
|
let gn = bin_dir.join("gn");
|
||||||
|
let ninja = bin_dir.join("ninja");
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
let gn = gn.with_extension("exe");
|
let gn = gn.with_extension("exe");
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
@ -152,11 +153,11 @@ fn download_gn_ninja_binaries() {
|
||||||
|
|
||||||
if !gn.exists() || !ninja.exists() {
|
if !gn.exists() || !ninja.exists() {
|
||||||
let status = Command::new("python")
|
let status = Command::new("python")
|
||||||
.arg("./tools/gn_ninja_binaries.py")
|
.arg("./tools/ninja_gn_binaries.py")
|
||||||
.arg("--dir")
|
.arg("--dir")
|
||||||
.arg(&download_dir)
|
.arg(&target_dir)
|
||||||
.status()
|
.status()
|
||||||
.expect("gn_ninja_binaries.py download failed");
|
.expect("ninja_gn_binaries.py download failed");
|
||||||
assert!(status.success());
|
assert!(status.success());
|
||||||
}
|
}
|
||||||
assert!(gn.exists());
|
assert!(gn.exists());
|
||||||
|
|
|
@ -4,14 +4,9 @@
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
"""This script is used to download prebuilt gn/ninja binaries."""
|
"""This script is used to download prebuilt gn/ninja binaries."""
|
||||||
|
|
||||||
# TODO: Running stand-alone won't work on Windows due to the dia dll copying.
|
|
||||||
|
|
||||||
from __future__ import division
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import stat
|
|
||||||
import sys
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -23,23 +18,10 @@ except ImportError: # For Py3 compatibility
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
URL = "https://s3.amazonaws.com/deno.land/gn_ninja_binaries.tar.gz"
|
URL = "https://github.com/denoland/ninja_gn_binaries/archive/20191129.tar.gz"
|
||||||
DIR = None
|
DIR = None
|
||||||
|
|
||||||
|
|
||||||
def RmTree(dir):
|
|
||||||
"""Delete dir."""
|
|
||||||
|
|
||||||
def ChmodAndRetry(func, path, _):
|
|
||||||
# Subversion can leave read-only files around.
|
|
||||||
if not os.access(path, os.W_OK):
|
|
||||||
os.chmod(path, stat.S_IWUSR)
|
|
||||||
return func(path)
|
|
||||||
raise
|
|
||||||
|
|
||||||
shutil.rmtree(dir, onerror=ChmodAndRetry)
|
|
||||||
|
|
||||||
|
|
||||||
def DownloadUrl(url, output_file):
|
def DownloadUrl(url, output_file):
|
||||||
"""Download url into output_file."""
|
"""Download url into output_file."""
|
||||||
CHUNK_SIZE = 4096
|
CHUNK_SIZE = 4096
|
||||||
|
@ -49,25 +31,18 @@ def DownloadUrl(url, output_file):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
sys.stdout.write('Downloading %s ' % url)
|
sys.stdout.write('Downloading %s...' % url)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
response = urlopen(url)
|
response = urlopen(url)
|
||||||
total_size = int(response.info().get('Content-Length').strip())
|
|
||||||
bytes_done = 0
|
bytes_done = 0
|
||||||
dots_printed = 0
|
|
||||||
while True:
|
while True:
|
||||||
chunk = response.read(CHUNK_SIZE)
|
chunk = response.read(CHUNK_SIZE)
|
||||||
if not chunk:
|
if not chunk:
|
||||||
break
|
break
|
||||||
output_file.write(chunk)
|
output_file.write(chunk)
|
||||||
bytes_done += len(chunk)
|
bytes_done += len(chunk)
|
||||||
num_dots = TOTAL_DOTS * bytes_done // total_size
|
if bytes_done == 0:
|
||||||
sys.stdout.write('.' * (num_dots - dots_printed))
|
raise URLError("empty response")
|
||||||
sys.stdout.flush()
|
|
||||||
dots_printed = num_dots
|
|
||||||
if bytes_done != total_size:
|
|
||||||
raise URLError(
|
|
||||||
"only got %d of %d bytes" % (bytes_done, total_size))
|
|
||||||
print(' Done.')
|
print(' Done.')
|
||||||
return
|
return
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
|
@ -88,9 +63,7 @@ def EnsureDirExists(path):
|
||||||
|
|
||||||
|
|
||||||
def DownloadAndUnpack(url, output_dir):
|
def DownloadAndUnpack(url, output_dir):
|
||||||
"""Download an archive from url and extract into output_dir. If path_prefixes
|
"""Download an archive from url and extract into output_dir."""
|
||||||
is not None, only extract files whose paths within the archive start with
|
|
||||||
any prefix in path_prefixes."""
|
|
||||||
with tempfile.TemporaryFile() as f:
|
with tempfile.TemporaryFile() as f:
|
||||||
DownloadUrl(url, f)
|
DownloadUrl(url, f)
|
||||||
f.seek(0)
|
f.seek(0)
|
||||||
|
@ -100,13 +73,10 @@ def DownloadAndUnpack(url, output_dir):
|
||||||
|
|
||||||
|
|
||||||
def Update():
|
def Update():
|
||||||
if os.path.exists(DIR):
|
|
||||||
RmTree(DIR)
|
|
||||||
try:
|
try:
|
||||||
DownloadAndUnpack(URL, DIR)
|
DownloadAndUnpack(URL, DIR)
|
||||||
except URLError:
|
except URLError:
|
||||||
print('Failed to download prebuilt ninja/gn binaries %s' % URL)
|
print('Failed to download ninja/gn binaries.')
|
||||||
print('Exiting.')
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return 0
|
return 0
|
Loading…
Reference in a new issue