node.configure (3283B)
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/. 6 7 option("--disable-nodejs", help="Require Node.js to build") 8 option(env="NODEJS", nargs=1, help="Path to nodejs") 9 10 11 @depends( 12 "--enable-nodejs", 13 "NODEJS", 14 bootstrap_search_path("node", when=depends("NODEJS")(lambda x: not x)), 15 host, 16 ) 17 @checking( 18 "for nodejs", callback=lambda x: "%s (%s)" % (x.path, x.str_version) if x else "no" 19 ) 20 @imports(_from="mozbuild.nodeutil", _import="find_node_executable") 21 @imports(_from="mozbuild.nodeutil", _import="NODE_MIN_VERSION") 22 @imports(_from="__builtin__", _import="OSError") 23 @imports("errno") 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 29 # not to fail. 30 search_path 31 32 node_exe = env_node[0] if env_node else None 33 34 try: 35 nodejs, version = find_node_executable(node_exe) 36 except OSError as e: 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. 43 die( 44 "Rosetta is needed to run node. Please run `softwareupdate --install-rosetta`" 45 ) 46 raise 47 48 MAYBE_FILE_A_BUG = """ 49 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> 54 """ 55 56 if not nodejs: 57 msg = ( 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) 61 ) 62 63 if require: 64 raise FatalCheckError(msg) 65 else: 66 log.warning(msg) 67 log.warning("(This will become an error in the near future.)") 68 return 69 70 if not version: 71 msg = "NODEJS must point to node %s or newer; found node location: %s. %s" % ( 72 NODE_MIN_VERSION, 73 nodejs, 74 MAYBE_FILE_A_BUG, 75 ) 76 77 if require: 78 raise FatalCheckError(msg) 79 else: 80 log.warning(msg) 81 return 82 83 return namespace( 84 path=nodejs, 85 version=version, 86 str_version=".".join(str(v) for v in version), 87 ) 88 89 90 set_config("NODEJS", depends_if(nodejs)(lambda p: p.path))