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

Replace make + Makefile with Python Invoke library + tasks.py ((also fix…

Replace make + Makefile with Python Invoke library + tasks.py ((also fix installation under path with whitespaces) (#1239)
上级 eaa2c7b3
......@@ -55,6 +55,9 @@ jobs:
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# We need to install pip invoke library.
- name: pip3 install invoke
run: pip3 install invoke
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
......
......@@ -54,6 +54,11 @@ jobs:
- name: npm ci
run: npm ci --ignore-scripts --omit=dev
# However we also need to install pip invoke manually (since
# `--ignore-scripts` prevented invoke from being installed).
- name: pip3 install invoke
run: pip3 install invoke
- name: npm run worker:build
run: npm run worker:build
......
......@@ -64,25 +64,25 @@ jobs:
restore-keys: |
${{ matrix.build.os }}-node-${{matrix.build.cc}}-
# We need to install some NPM production deps for npm-scripts.mjs to work.
- name: npm ci
run: npm ci --ignore-scripts --omit=dev
# We need to install pip invoke manually.
- name: pip3 install invoke
run: pip3 install invoke
# We need to install deps on worker/scripts/package.json.
- name: npm run install-worker-dev-tools
run: npm run install-worker-dev-tools
# We need to install npm deps of worker/scripts/package.json.
- name: npm ci --prefix worker/scripts
run: npm ci --prefix worker/scripts
# TODO: Maybe fix this one day.
if: runner.os != 'Windows'
- name: npm run lint:worker
run: npm run lint:worker
- name: invoke -r worker lint
run: invoke -r worker lint
# TODO: Maybe fix this one day.
if: runner.os != 'Windows'
- name: npm run worker:build
run: npm run worker:build
- name: invoke -r worker mediasoup-worker
run: invoke -r worker mediasoup-worker
- name: npm run test:worker
run: npm run test:worker
- name: invoke -r worker test
run: invoke -r worker test
# TODO: Maybe fix this one day.
if: runner.os != 'Windows'
......@@ -20,10 +20,11 @@
# Flatc generated files.
/worker/include/FBS
/worker/prebuild
# Vistual Studio generated Stuff.
# Python invoke.
/worker/pip_invoke
# Build artifacts.
/worker/**/Debug
/worker/**/Release
/worker/.vs
# clang-fuzzer stuff is too big.
/worker/deps/clang-fuzzer
# Ignore all fuzzer generated test inputs.
......
# Changelog
### NEXT
* Replace make + Makefile with Python Invoke library + tasks.py (also fix installation under path with whitespaces) ([PR #1239](https://github.com/versatica/mediasoup/pull/1239)).
### 3.13.5
* Fix RTCP SDES packet size calculation ([PR #1236](https://github.com/versatica/mediasoup/pull/1236) based on PR [PR #1234](https://github.com/versatica/mediasoup/pull/1234) by @ybybwdwd).
......
差异被折叠。
......@@ -2,15 +2,16 @@ import process from 'node:process';
import os from 'node:os';
import fs from 'node:fs';
import path from 'node:path';
import { execSync, spawnSync } from 'node:child_process';
import { execSync } from 'node:child_process';
import fetch from 'node-fetch';
import tar from 'tar';
const PKG = JSON.parse(fs.readFileSync('./package.json').toString());
const IS_FREEBSD = os.platform() === 'freebsd';
const IS_WINDOWS = os.platform() === 'win32';
const MAYOR_VERSION = PKG.version.split('.')[0];
const MAKE = process.env.MAKE || (IS_FREEBSD ? 'gmake' : 'make');
const PYTHON = getPython();
const PIP_INVOKE_DIR = path.resolve('worker/pip_invoke');
const INVOKE_VERSION = process.env.INVOKE_VERSION ?? '2.2.0';
const FLATBUFFERS_VERSION = '23.3.3';
const WORKER_RELEASE_DIR = 'worker/out/Release';
const WORKER_RELEASE_BIN = IS_WINDOWS ? 'mediasoup-worker.exe' : 'mediasoup-worker';
......@@ -23,12 +24,37 @@ const GH_REPO = 'mediasoup';
const task = process.argv.slice(2).join(' ');
// PYTHONPATH env must be updated now so all invoke calls below will find the
// pip invoke module.
if (process.env.PYTHONPATH)
{
if (IS_WINDOWS)
{
process.env.PYTHONPATH = `${PIP_INVOKE_DIR};${process.env.PYTHONPATH}`;
}
else
{
process.env.PYTHONPATH = `${PIP_INVOKE_DIR}:${process.env.PYTHONPATH}`;
}
}
else
{
process.env.PYTHONPATH = PIP_INVOKE_DIR;
}
run();
async function run()
{
switch (task)
{
case 'preinstall':
{
installInvoke();
break;
}
// As per NPM documentation (https://docs.npmjs.com/cli/v9/using-npm/scripts)
// `prepare` script:
//
......@@ -142,7 +168,7 @@ async function run()
case 'format:worker':
{
executeCmd(`${MAKE} format -C worker`);
executeCmd(`"${PYTHON}" -m invoke -r worker format`);
break;
}
......@@ -185,20 +211,6 @@ async function run()
break;
}
case 'install-deps:node':
{
installNodeDeps();
break;
}
case 'install-worker-dev-tools':
{
executeCmd('npm ci --prefix worker/scripts');
break;
}
case 'release:check':
{
checkRelease();
......@@ -274,6 +286,42 @@ async function run()
}
}
function getPython()
{
let python = process.env.PYTHON;
if (!python)
{
try
{
execSync('python3 --version', { stdio: [ 'ignore', 'ignore', 'ignore' ] });
python = 'python3';
}
catch (error)
{
python = 'python';
}
}
return python;
}
function installInvoke()
{
if (fs.existsSync(PIP_INVOKE_DIR))
{
return;
}
logInfo('installInvoke()');
// Install pip invoke into custom location, so we don't depend on system-wide
// installation.
executeCmd(
`"${PYTHON}" -m pip install --upgrade --target="${PIP_INVOKE_DIR}" invoke==${INVOKE_VERSION}`, /* exitOnError */ true
);
}
function deleteNodeLib()
{
if (!fs.existsSync('node/lib'))
......@@ -311,22 +359,7 @@ function buildWorker()
{
logInfo('buildWorker()');
if (IS_WINDOWS)
{
if (!fs.existsSync('worker/out/msys/bin/make.exe'))
{
installMsysMake();
}
const msysPath = `${process.cwd()}\\worker\\out\\msys\\bin`;
if (!process.env.PATH.includes(msysPath))
{
process.env.PATH = `${msysPath};${process.env.PATH}`;
}
}
executeCmd(`${MAKE} -C worker`);
executeCmd(`"${PYTHON}" -m invoke -r worker mediasoup-worker`);
}
function cleanWorkerArtifacts()
......@@ -334,19 +367,11 @@ function cleanWorkerArtifacts()
logInfo('cleanWorkerArtifacts()');
// Clean build artifacts except `mediasoup-worker`.
executeCmd(`${MAKE} clean-build -C worker`);
executeCmd(`"${PYTHON}" -m invoke -r worker clean-build`);
// Clean downloaded dependencies.
executeCmd(`${MAKE} clean-subprojects -C worker`);
executeCmd(`"${PYTHON}" -m invoke -r worker clean-subprojects`);
// Clean PIP/Meson/Ninja.
executeCmd(`${MAKE} clean-pip -C worker`);
if (IS_WINDOWS)
{
if (fs.existsSync('worker/out/msys'))
{
executeCmd('rd /s /q worker\\out\\msys');
}
}
executeCmd(`"${PYTHON}" -m invoke -r worker clean-pip`);
}
function lintNode()
......@@ -360,7 +385,7 @@ function lintWorker()
{
logInfo('lintWorker()');
executeCmd(`${MAKE} lint -C worker`);
executeCmd(`"${PYTHON}" -m invoke -r worker lint`);
}
function flatcNode()
......@@ -368,24 +393,24 @@ function flatcNode()
logInfo('flatcNode()');
// Build flatc if needed.
executeCmd(`${MAKE} -C worker flatc`);
executeCmd(`"${PYTHON}" -m invoke -r worker flatc`);
const buildType = process.env.MEDIASOUP_BUILDTYPE || 'Release';
const extension = IS_WINDOWS ? '.exe' : '';
const flatc = path.resolve(path.join(
'worker', 'out', buildType, 'build', 'subprojects', `flatbuffers-${FLATBUFFERS_VERSION}`, `flatc${extension}`));
const src = path.resolve(path.join('worker', 'fbs', '*.fbs'));
const out = path.resolve(path.join('node', 'src'));
const options = '--ts-no-import-ext --gen-object-api';
const command = `${flatc} --ts ${options} -o ${out} `;
if (IS_WINDOWS)
for (const dirent of fs.readdirSync(path.join('worker', 'fbs'), { withFileTypes: true }))
{
executeCmd(`for %f in (${src}) do ${command} %f`);
}
else
{
executeCmd(`for file in ${src}; do ${command} \$\{file\}; done`);
if (!dirent.isFile() || path.parse(dirent.name).ext !== '.fbs')
{
continue;
}
const filePath = path.resolve(path.join('worker', 'fbs', dirent.name));
executeCmd(`"${flatc}" --ts --ts-no-import-ext --gen-object-api -o "${out}" "${filePath}"`);
}
}
......@@ -393,7 +418,7 @@ function flatcWorker()
{
logInfo('flatcWorker()');
executeCmd(`${MAKE} -C worker flatc`);
executeCmd(`"${PYTHON}" -m invoke -r worker flatc`);
}
function testNode()
......@@ -406,7 +431,7 @@ function testNode()
}
else
{
executeCmd(`jest --testPathPattern ${process.env.TEST_FILE}`);
executeCmd(`jest --testPathPattern "${process.env.TEST_FILE}"`);
}
}
......@@ -414,7 +439,7 @@ function testWorker()
{
logInfo('testWorker()');
executeCmd(`${MAKE} test -C worker`);
executeCmd(`"${PYTHON}" -m invoke -r worker test`);
}
function installNodeDeps()
......@@ -441,42 +466,6 @@ function checkRelease()
testWorker();
}
function installMsysMake()
{
logInfo('installMsysMake()');
let pythonPath;
// If PYTHON environment variable is given, use it.
if (process.env.PYTHON)
{
pythonPath = process.env.PYTHON;
}
// Otherwise ensure python3.exe is available in the PATH.
else
{
let res = spawnSync('where', [ 'python3.exe' ]);
if (res.status !== 0)
{
res = spawnSync('where', [ 'python.exe' ]);
if (res.status !== 0)
{
logError('`installMsysMake() | cannot find Python executable');
exitWithError();
}
}
pythonPath = String(res.stdout).trim();
}
const dir = path.resolve('worker/out/msys');
executeCmd(`${pythonPath} worker\\scripts\\getmake.py --dir="${dir}"`);
}
function ensureDir(dir)
{
logInfo(`ensureDir() [dir:${dir}]`);
......
......@@ -21,19 +21,20 @@
"types": "node/lib/index.d.ts",
"files": [
"node/lib",
"worker/deps/libwebrtc",
"worker/src",
"worker/include",
"worker/fbs",
"worker/fuzzer/include",
"worker/test/src",
"worker/test/include",
"worker/fuzzer/src",
"worker/include",
"worker/fuzzer/include",
"worker/scripts/*.mjs",
"worker/scripts/*.json",
"worker/scripts/*.py",
"worker/scripts/*.sh",
"worker/src",
"worker/subprojects/*.wrap",
"worker/test/include",
"worker/test/src",
"worker/deps/libwebrtc",
"worker/tasks.py",
"worker/Makefile",
"worker/meson.build",
"worker/meson_options.txt",
......@@ -49,6 +50,7 @@
"nodejs"
],
"scripts": {
"preinstall": "node npm-scripts.mjs preinstall",
"prepare": "node npm-scripts.mjs prepare",
"postinstall": "node npm-scripts.mjs postinstall",
"typescript:build": "node npm-scripts.mjs typescript:build",
......@@ -66,8 +68,6 @@
"test:node": "node npm-scripts.mjs test:node",
"test:worker": "node npm-scripts.mjs test:worker",
"coverage:node": "node npm-scripts.mjs coverage:node",
"install-deps:node": "node npm-scripts.mjs install-deps:node",
"install-worker-dev-tools": "node npm-scripts.mjs install-worker-dev-tools",
"release:check": "node npm-scripts.mjs release:check",
"release": "node npm-scripts.mjs release",
"release:upload-mac-arm-prebuilt-worker": "node npm-scripts.mjs release:upload-mac-arm-prebuilt-worker"
......
FROM ubuntu:22.04
# Install dependencies.
RUN \
set -x \
RUN set -x \
&& apt-get update \
&& apt-get install --yes \
bash-completion wget curl subversion screen gcc g++ cmake ninja-build golang \
autoconf libtool apache2 python3-pip python3-dev pkg-config zlib1g-dev \
libgss-dev libssl-dev libxml2-dev nasm libarchive-dev make automake \
libdbus-1-dev libboost-dev autoconf-archive bash-completion python3-yaml \
clang
gcc g++ clang pkg-config bash-completion wget curl \
screen python3-pip python3-yaml pkg-config zlib1g-dev \
libgss-dev libssl-dev libxml2-dev
# Install node 20.
RUN set -x \
......
FROM alpine
# Install dependencies.
RUN \
set -x \
&& apk add \
nodejs-current npm python3 py3-pip \
make gcc g++
RUN set -x \
&& apk add gcc g++ nodejs-current npm python3 py3-pip
# Make CC and CXX point to gcc/g++.
ENV LANG="C.UTF-8"
......
差异被折叠。
......@@ -7,8 +7,8 @@ fn main() {
return;
}
// On Windows Rust always links against release version of MSVC runtime, thus requires Release
// build here.
// On Windows Rust always links against release version of MSVC runtime, thus requires
// Release build here
let build_type = if cfg!(all(debug_assertions, not(windows))) {
"Debug"
} else {
......@@ -45,15 +45,9 @@ fn main() {
)
.expect("Failed to write generated Rust flatbuffers into fbs.rs");
// 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 tasks.py
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
#[cfg(target_os = "linux")]
{
......@@ -110,62 +104,49 @@ fn main() {
println!("cargo:rustc-link-lib=dylib=c++");
println!("cargo:rustc-link-lib=dylib=c++abi");
}
#[cfg(target_os = "windows")]
{
if !std::path::Path::new("worker/out/msys/bin/make.exe").exists() {
let python = if let Ok(python) = env::var("PYTHON") {
python
} else if Command::new("where")
.arg("python3")
.status()
.expect("Failed to start")
.success()
{
"python3".to_string()
} else {
"python".to_string()
};
let dir = format!("{}/msys", mediasoup_out_dir.replace('\\', "/"));
if !Command::new(python)
.arg("scripts\\getmake.py")
.arg("--dir")
.arg(dir.clone())
.status()
.expect("Failed to start")
.success()
{
panic!("Failed to install MSYS/make")
}
env::set_var(
"PATH",
format!("{}\\bin;{}", dir, env::var("PATH").unwrap()),
);
}
env::set_var(
"PATH",
format!(
"{}\\worker\\out\\msys\\bin;{}",
env::current_dir()
.unwrap()
.into_os_string()
.into_string()
.unwrap(),
env::var("PATH").unwrap()
),
);
// Install Python invoke package in custom folder
let pip_invoke_dir = format!("{out_dir}/pip_invoke");
let invoke_version = "2.2.0";
let python = env::var("PYTHON").unwrap_or("python3".to_string());
let mut pythonpath = if env::var("PYTHONPATH").is_ok() {
let original_pythonpath = env::var("PYTHONPATH").unwrap();
format!("{pip_invoke_dir}:{original_pythonpath}")
} else {
pip_invoke_dir.clone()
};
// Force ";" in PYTHONPATH on Windows
if cfg!(target_os = "windows") {
pythonpath = pythonpath.replace(':', ";");
}
if !Command::new(&python)
.arg("-m")
.arg("pip")
.arg("install")
.arg("--upgrade")
.arg(format!("--target={pip_invoke_dir}"))
.arg(format!("invoke=={invoke_version}"))
.spawn()
.expect("Failed to start")
.wait()
.expect("Wasn't running")
.success()
{
panic!("Failed to install Python invoke package")
}
// Build
if !Command::new("make")
if !Command::new(&python)
.arg("-m")
.arg("invoke")
.arg("libmediasoup-worker")
.env("PYTHONPATH", &pythonpath)
.env("MEDIASOUP_OUT_DIR", &mediasoup_out_dir)
.env("MEDIASOUP_BUILDTYPE", build_type)
// Force forward slashes on Windows too, otherwise Meson thinks path is not absolute 🤷
.env("INSTALL_DIR", &out_dir.replace('\\', "/"))
.env("MEDIASOUP_INSTALL_DIR", &out_dir.replace('\\', "/"))
.spawn()
.expect("Failed to start")
.wait()
......@@ -205,9 +186,11 @@ fn main() {
if env::var("KEEP_BUILD_ARTIFACTS") != Ok("1".to_string()) {
// Clean
if !Command::new("make")
if !Command::new(python)
.arg("-m")
.arg("invoke")
.arg("clean-all")
.env("PATH", original_path)
.env("PYTHONPATH", &pythonpath)
.env("MEDIASOUP_OUT_DIR", &mediasoup_out_dir)
.spawn()
.expect("Failed to start")
......
......@@ -25,7 +25,7 @@ async function run()
case 'lint':
{
executeCmd(
`${clangFormatNativeBinary} --Werror --dry-run ${workerFiles.join(' ')}`
`"${clangFormatNativeBinary}" --Werror --dry-run ${workerFiles.join(' ')}`
);
break;
......@@ -34,7 +34,7 @@ async function run()
case 'format':
{
executeCmd(
`${clangFormatNativeBinary} --Werror -i ${workerFiles.join(' ')}`
`"${clangFormatNativeBinary}" --Werror -i ${workerFiles.join(' ')}`
);
break;
......
#!/usr/bin/env sh
set -e
OS="$(uname -s)"
NUM_CORES=
case "${OS}" in
Linux*) NUM_CORES=$(nproc);;
Darwin*|FreeBSD) NUM_CORES=$(sysctl -n hw.ncpu);;
MINGW*) NUM_CORES=$NUMBER_OF_PROCESSORS;;
*) NUM_CORES=1;;
esac
if [ -n "${MEDIASOUP_MAX_CORES}" ]; then
NUM_CORES=$((MEDIASOUP_MAX_CORES>NUM_CORES ? NUM_CORES : MEDIASOUP_MAX_CORES))
fi
echo ${NUM_CORES}
......@@ -7,7 +7,7 @@ DEP=$1
current_dir_name=${WORKER_PWD##*/}
if [ "${current_dir_name}" != "worker" ] ; then
echo ">>> [ERROR] $(basename $0) must be called from mediasoup/worker/ directory" >&2
echo ">>> [ERROR] $(basename $0) must be called from mediasoup/worker directory" >&2
exit 1
fi
......
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):
data = urllib.request.urlopen(url).read()
assert hashlib.sha256(data).hexdigest() == digest
tar = tarfile.open(fileobj=io.BytesIO(data))
tar.extractall(args.dir)
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/libiconv/libiconv-1.14-1/libiconv-1.14-1-msys-1.0.17-dll-2.tar.lzma/download', '196921e8c232259c8e6a6852b9ee8d9ab2d29a91419f0c8dc27ba6f034231683')
get('https://sourceforge.net/projects/mingw/files/MSYS/Base/gettext/gettext-0.18.1.1-1/libintl-0.18.1.1-1-msys-1.0.17-dll-8.tar.lzma/download', '29db8c969661c511fbe2a341ab25c993c5f9c555842a75d6ddbcfa70dec16910')
get('https://sourceforge.net/projects/mingw/files/MSYS/Base/coreutils/coreutils-5.97-3/coreutils-5.97-3-msys-1.0.13-bin.tar.lzma/download', 'f8c7990416ea16a74ac336dcfe0f596bc46b8724b2d58cf8a3509414220b2366')
get('https://sourceforge.net/projects/mingw/files/MSYS/Base/regex/regex-1.20090805-2/libregex-1.20090805-2-msys-1.0.13-dll-1.tar.lzma/download', '85dd8c1e27a90675c5f867be57ba7ae2bb55dde8cd2d19f284c896be134bd3d1')
get('https://sourceforge.net/projects/mingw/files/MSYS/Base/termcap/termcap-0.20050421_1-2/libtermcap-0.20050421_1-2-msys-1.0.13-dll-0.tar.lzma/download', '62b58fe0880f0972fcc84a819265989b02439c1c5185870227bd25f870f7adb6')
get('https://sourceforge.net/projects/mingw/files/MSYS/Base/bash/bash-3.1.23-1/bash-3.1.23-1-msys-1.0.18-bin.tar.xz/download', '38da5419969ab883058a96322bb0f51434dd4e9f71de09cd4f75b96750944533')
get('https://sourceforge.net/projects/mingw/files/MSYS/Base/make/make-3.81-3/make-3.81-3-msys-1.0.13-bin.tar.lzma/download', '847f0cbbf07135801c8e67bf692d29b1821e816ad828753c997fa869a9b89988')
差异被折叠。
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论