1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 option("--disable-nodejs", help="Require Node.js to build")
8 option(env="NODEJS", nargs=1, help="Path to nodejs")
11 @depends("--enable-nodejs", "NODEJS", bootstrap_search_path("node"))
13 "for nodejs", callback=lambda x: "%s (%s)" % (x.path, x.str_version) if x else "no"
15 @imports(_from="mozbuild.nodeutil", _import="find_node_executable")
16 @imports(_from="mozbuild.nodeutil", _import="NODE_MIN_VERSION")
17 def nodejs(require, env_node, search_path):
18 # We don't use the dependency directly, but having it ensures the
19 # auto-upgrade code in bootstrap_search_path is triggered, while
20 # find_node_executable will use more or less the same search path.
21 # We do however need to use the variable for the configure lint
25 node_exe = env_node[0] if env_node else None
27 nodejs, version = find_node_executable(node_exe)
29 MAYBE_FILE_A_BUG = """
31 Executing `mach bootstrap --no-system-changes` should
32 install a compatible version in ~/.mozbuild on most platforms.
33 If you believe this is a bug, <https://mzl.la/2vLbXAv> is a good way
34 to file. More details: <https://bit.ly/2BbyD1E>
39 "could not find Node.js executable later than %s; ensure "
40 "`node` or `nodejs` is in PATH or set NODEJS in environment "
41 "to point to an executable.%s" % (NODE_MIN_VERSION, MAYBE_FILE_A_BUG)
45 raise FatalCheckError(msg)
48 log.warning("(This will become an error in the near future.)")
52 msg = "NODEJS must point to node %s or newer; found node location: %s. %s" % (
59 raise FatalCheckError(msg)
67 str_version=".".join(str(v) for v in version),
71 set_config("NODEJS", depends_if(nodejs)(lambda p: p.path))