diff --git a/bindings/gumjs/generate-runtime.py b/bindings/gumjs/generate-runtime.py index f2fa45084..81740150d 100755 --- a/bindings/gumjs/generate-runtime.py +++ b/bindings/gumjs/generate-runtime.py @@ -23,20 +23,21 @@ def main(argv): - output_dir, priv_dir, input_dir, gum_dir, capstone_incdir, libtcc_incdir, quickcompile = \ - [Path(d).resolve() if d else None for d in argv[1:8]] - backends = set(argv[8].split(",")) - arch, endian = argv[9:] + output_dir, priv_dir, input_dir, gum_dir, capstone_incdir, libtcc_incdir, npm, quickcompile = \ + [Path(d).resolve() if d else None for d in argv[1:9]] + backends = set(argv[9].split(",")) + arch, endian = argv[10:] try: - generate_runtime(output_dir, priv_dir, input_dir, gum_dir, capstone_incdir, libtcc_incdir, quickcompile, + generate_runtime(output_dir, priv_dir, input_dir, gum_dir, capstone_incdir, libtcc_incdir, + npm, quickcompile, backends, arch, endian) except Exception as e: print(e, file=sys.stderr) sys.exit(1) -def generate_runtime(output_dir, priv_dir, input_dir, gum_dir, capstone_incdir, libtcc_incdir, quickcompile, backends, arch, endian): +def generate_runtime(output_dir, priv_dir, input_dir, gum_dir, capstone_incdir, libtcc_incdir, npm, quickcompile, backends, arch, endian): frida_compile = priv_dir / "node_modules" / ".bin" / make_script_filename("frida-compile") if not frida_compile.exists(): if priv_dir.exists(): @@ -45,32 +46,18 @@ def generate_runtime(output_dir, priv_dir, input_dir, gum_dir, capstone_incdir, (priv_dir / "tsconfig.json").write_text("{ \"files\": [], \"compilerOptions\": { \"typeRoots\": [] } }", encoding="utf-8") - npm = os.environ.get("NPM", make_script_filename("npm")) - try: - subprocess.run([npm, "init", "-y"], - capture_output=True, - cwd=priv_dir, - check=True) - subprocess.run([npm, "install"] + [f"{name}@{version_spec}" for name, version_spec in RELAXED_DEPS.items()], - capture_output=True, - cwd=priv_dir, - check=True) - subprocess.run([npm, "install", "-E"] + [f"{name}@{version_spec}" for name, version_spec in EXACT_DEPS.items()], - capture_output=True, - cwd=priv_dir, - check=True) - except Exception as e: - message = "\n".join([ - "", - "***", - "Failed to bootstrap frida-compile:", - "\t" + str(e), - "It appears Node.js is not installed.", - "We need it for processing JavaScript code at build-time.", - "Check PATH or set NPM to the absolute path of your npm binary.", - "***\n", - ]) - raise EnvironmentError(message) + subprocess.run([npm, "init", "-y"], + capture_output=True, + cwd=priv_dir, + check=True) + subprocess.run([npm, "install"] + [f"{name}@{version_spec}" for name, version_spec in RELAXED_DEPS.items()], + capture_output=True, + cwd=priv_dir, + check=True) + subprocess.run([npm, "install", "-E"] + [f"{name}@{version_spec}" for name, version_spec in EXACT_DEPS.items()], + capture_output=True, + cwd=priv_dir, + check=True) runtime_reldir = Path("runtime") runtime_srcdir = input_dir / runtime_reldir diff --git a/bindings/gumjs/meson.build b/bindings/gumjs/meson.build index 9b142fff7..45e4acbbb 100644 --- a/bindings/gumjs/meson.build +++ b/bindings/gumjs/meson.build @@ -243,6 +243,7 @@ gumjs_runtime = custom_target('gumjs-runtime', meson.project_source_root() / 'gum', capstone_dep.get_variable('includedir') / 'capstone', libtcc_incdir, + npm, quickcompile, ','.join(backends), host_arch, diff --git a/meson.build b/meson.build index ae006bfbf..e78de9d5f 100644 --- a/meson.build +++ b/meson.build @@ -643,6 +643,11 @@ if have_gumjs 'tests=false', 'sysprof=disabled', ]) + + npm = find_program('npm', native: true, required: false) + if not npm.found() + error('Need Node.js and npm to process JavaScript code at build-time') + endif else v8_dep = disabler() endif