Skip to content

Commit

Permalink
meson: Fail early if npm is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Apr 18, 2024
1 parent f53bd89 commit b9d5ec4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
51 changes: 19 additions & 32 deletions bindings/gumjs/generate-runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions bindings/gumjs/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b9d5ec4

Please sign in to comment.