Unverified 提交 a3b13cc7 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Fix NPM 'postinstall' task in Windows (#1187)

上级 e782b794
...@@ -445,7 +445,9 @@ function installMsysMake() ...@@ -445,7 +445,9 @@ function installMsysMake()
pythonPath = String(res.stdout).trim(); pythonPath = String(res.stdout).trim();
} }
executeCmd(`${pythonPath} worker\\scripts\\getmake.py`); const dir = path.resolve('worker/out/msys');
executeCmd(`${pythonPath} worker\\scripts\\getmake.py --dir="${dir}"`);
} }
function ensureDir(dir) function ensureDir(dir)
......
...@@ -16,9 +16,15 @@ fn main() { ...@@ -16,9 +16,15 @@ fn main() {
}; };
let out_dir = env::var("OUT_DIR").unwrap(); let out_dir = env::var("OUT_DIR").unwrap();
// Force forward slashes on Windows too so that is plays well with our dumb `Makefile` // Force forward slashes on Windows too so that is plays well with our dumb `Makefile`.
let mediasoup_out_dir = format!("{}/out", out_dir.replace('\\', "/")); let mediasoup_out_dir = format!("{}/out", out_dir.replace('\\', "/"));
// Store original PATH so we make `make clean-all` use it. This is because, in Windows,
// we may need to fetch `make` and we store it in out/msys and then we add out/msys/bin
// to the PATH, and that folder may contain rm.exe, so `make clean-all` would use
// that rm.exe and delete itself and make the task fail.
let original_path = env::var("PATH").unwrap();
// Add C++ std lib // Add C++ std lib
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
{ {
...@@ -78,25 +84,36 @@ fn main() { ...@@ -78,25 +84,36 @@ fn main() {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
if !std::path::Path::new("worker/out/msys/bin/make.exe").exists() { if !std::path::Path::new("worker/out/msys/bin/make.exe").exists() {
let python = if Command::new("where") let python = if let Ok(python) = env::var("PYTHON") {
.arg("python3.exe") python
} else if Command::new("where")
.arg("python3")
.status() .status()
.expect("Failed to start") .expect("Failed to start")
.success() .success()
{ {
"python3" "python3".to_string()
} else { } else {
"python" "python".to_string()
}; };
let dir = format!("{}/msys", mediasoup_out_dir.replace('\\', "/"));
if !Command::new(python) if !Command::new(python)
.arg("scripts\\getmake.py") .arg("scripts\\getmake.py")
.arg("--dir")
.arg(dir.clone())
.status() .status()
.expect("Failed to start") .expect("Failed to start")
.success() .success()
{ {
panic!("Failed to install MSYS/make") panic!("Failed to install MSYS/make")
} }
env::set_var(
"PATH",
format!("{}\\bin;{}", dir, env::var("PATH").unwrap()),
);
} }
env::set_var( env::set_var(
...@@ -161,6 +178,7 @@ fn main() { ...@@ -161,6 +178,7 @@ fn main() {
// Clean // Clean
if !Command::new("make") if !Command::new("make")
.arg("clean-all") .arg("clean-all")
.env("PATH", original_path)
.env("MEDIASOUP_OUT_DIR", &mediasoup_out_dir) .env("MEDIASOUP_OUT_DIR", &mediasoup_out_dir)
.spawn() .spawn()
.expect("Failed to start") .expect("Failed to start")
......
import io, hashlib, tarfile, urllib.request import argparse, io, hashlib, tarfile, urllib.request
argParser = argparse.ArgumentParser()
argParser.add_argument(
'--dir',
type=str,
required=True,
help='absolute path of the directoy in which fetched content will be placed'
)
args = argParser.parse_args()
def get(url, digest): def get(url, digest):
data = urllib.request.urlopen(url).read() data = urllib.request.urlopen(url).read()
assert hashlib.sha256(data).hexdigest() == digest assert hashlib.sha256(data).hexdigest() == digest
tar = tarfile.open(fileobj=io.BytesIO(data)) tar = tarfile.open(fileobj=io.BytesIO(data))
tar.extractall('worker/out/msys') tar.extractall(args.dir)
tar.close() tar.close()
get('https://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.19-1/msysCORE-1.0.19-1-msys-1.0.19-bin.tar.xz/download', '8c4157d739a460f85563bc4451e9f1bbd42b13c4f63770d43b9f45a781f07858') get('https://sourceforge.net/projects/mingw/files/MSYS/Base/msys-core/msys-1.0.19-1/msysCORE-1.0.19-1-msys-1.0.19-bin.tar.xz/download', '8c4157d739a460f85563bc4451e9f1bbd42b13c4f63770d43b9f45a781f07858')
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论