build/moz.configure/node.configure
author Mark Banner <standard8@mozilla.com>
Tue, 25 Sep 2018 18:15:51 +0000
changeset 438163 951f04d1bb518e722e13b2a15580921590eb2b44
parent 432254 6b546d1df66256c9c538e7b5784b7c93bc2b9640
permissions -rw-r--r--
Bug 1482435 - Separate out nodejs finding logic from configure and use it for ESLint. r=firefox-build-system-reviewers,gps This extracts the current logic for finding nodejs into its own module in mozbuild. Configure and ESLint then use it. For ESLint, this will change the first location it looks for nodejs to be the .mozbuild directory. Differential Revision: https://phabricator.services.mozilla.com/D6430

# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

option('--disable-nodejs',
       help='Require Node.js to build')
option(env='NODEJS', nargs=1, help='Path to nodejs')


@depends('--enable-nodejs', 'NODEJS')
@checking('for nodejs',
          callback=lambda x: '%s (%s)' % (x.path, x.str_version) if x else 'no')
@imports(_from='mozbuild.nodeutil', _import='find_node_executable')
@imports(_from='mozbuild.nodeutil', _import='NODE_MIN_VERSION')
def nodejs(require, env_node):
    node_exe = env_node[0] if env_node else None

    nodejs, version = find_node_executable(node_exe)

    MAYBE_FILE_A_BUG = '''

    Executing `mach bootstrap --no-system-changes` should
    install a compatible version in ~/.mozbuild on most platforms.
    If you believe this is a bug, <https://mzl.la/2vLbXAv> is a good way
    to file.  More details: <https://bit.ly/2BbyD1E>
    '''

    if not nodejs:
        msg = ('could not find Node.js executable later than %s; ensure '
               '`node` or `nodejs` is in PATH or set NODEJS in environment '
               'to point to an executable.%s' % (NODE_MIN_VERSION, MAYBE_FILE_A_BUG)
               )

        if require:
            raise FatalCheckError(msg)
        else:
            log.warning(msg)
            log.warning('(This will become an error in the near future.)')
            return

    if not version:
        msg = 'NODEJS must point to node %s or newer; found node location: %s. %s' % (
            NODE_MIN_VERSION, nodejs, MAYBE_FILE_A_BUG)

        if require:
            raise FatalCheckError(msg)
        else:
            log.warning(msg)
            return

    return namespace(
        path=nodejs,
        version=version,
        str_version='.'.join(str(v) for v in version),
    )


set_config('NODEJS', depends_if(nodejs)(lambda p: p.path))