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")
14 bootstrap_search_path("node", when=depends("NODEJS")(lambda x: not x)),
18 "for nodejs", callback=lambda x: "%s (%s)" % (x.path, x.str_version) if x else "no"
20 @imports(_from="mozbuild.nodeutil", _import="find_node_executable")
21 @imports(_from="mozbuild.nodeutil", _import="NODE_MIN_VERSION")
22 @imports(_from="__builtin__", _import="OSError")
24 def nodejs(require, env_node, search_path, host):
25 # We don't use the dependency directly, but having it ensures the
26 # auto-upgrade code in bootstrap_search_path is triggered, while
27 # find_node_executable will use more or less the same search path.
28 # We do however need to use the variable for the configure lint
32 node_exe = env_node[0] if env_node else None
35 nodejs, version = find_node_executable(node_exe)
37 if host.cpu == "aarch64" and host.os == "OSX" and e.errno == errno.EBADARCH:
38 # Ideally we'd do it when --enable-bootstrap is set, but when we're wrapped in
39 # mach build or mach configure, running the command doesn't print anything and
40 # waits on input (for license agreement) that it can't actually get.
41 # mach bootstrap should have taken care of it anyways, but in case it hasn't,
42 # it's simpler to ask to run the rosetta install than the whole mach bootstrap.
44 "Rosetta is needed to run node. Please run `softwareupdate --install-rosetta`"
48 MAYBE_FILE_A_BUG = """
50 Executing `mach bootstrap --no-system-changes` should
51 install a compatible version in ~/.mozbuild on most platforms.
52 If you believe this is a bug, <https://mzl.la/2vLbXAv> is a good way
53 to file. More details: <https://bit.ly/2BbyD1E>
58 "could not find Node.js executable later than %s; ensure "
59 "`node` or `nodejs` is in PATH or set NODEJS in environment "
60 "to point to an executable.%s" % (NODE_MIN_VERSION, MAYBE_FILE_A_BUG)
64 raise FatalCheckError(msg)
67 log.warning("(This will become an error in the near future.)")
71 msg = "NODEJS must point to node %s or newer; found node location: %s. %s" % (
78 raise FatalCheckError(msg)
86 str_version=".".join(str(v) for v in version),
90 set_config("NODEJS", depends_if(nodejs)(lambda p: p.path))