Bug 1578501 [wpt PR 18803] - WebKit export of https://bugs.webkit.org/show_bug.cgi...
[gecko.git] / build / moz.configure / node.configure
blob5dccc8ba58147b90dd86ae958834605f799490de
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',
8        help='Require Node.js to build')
9 option(env='NODEJS', nargs=1, help='Path to nodejs')
12 @depends('--enable-nodejs', 'NODEJS')
13 @checking('for nodejs',
14           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 @imports(_from='mozbuild.util', _import='system_encoding')
18 def nodejs(require, env_node):
19     node_exe = env_node[0] if env_node else None
21     nodejs, version = find_node_executable(node_exe)
23     MAYBE_FILE_A_BUG = '''
25     Executing `mach bootstrap --no-system-changes` should
26     install a compatible version in ~/.mozbuild on most platforms.
27     If you believe this is a bug, <https://mzl.la/2vLbXAv> is a good way
28     to file.  More details: <https://bit.ly/2BbyD1E>
29     '''
31     if not nodejs:
32         msg = ('could not find Node.js executable later than %s; ensure '
33                '`node` or `nodejs` is in PATH or set NODEJS in environment '
34                'to point to an executable.%s' % (NODE_MIN_VERSION, MAYBE_FILE_A_BUG)
35                )
37         if require:
38             raise FatalCheckError(msg)
39         else:
40             log.warning(msg)
41             log.warning('(This will become an error in the near future.)')
42             return
44     if not version:
45         msg = 'NODEJS must point to node %s or newer; found node location: %s. %s' % (
46             NODE_MIN_VERSION, nodejs, MAYBE_FILE_A_BUG)
48         if require:
49             raise FatalCheckError(msg)
50         else:
51             log.warning(msg)
52             return
54     return namespace(
55         path=nodejs.decode(system_encoding),
56         version=version,
57         str_version='.'.join(str(v) for v in version),
58     )
61 set_config('NODEJS', depends_if(nodejs)(lambda p: p.path))