2018-07-04 00:24:58 +03:00
|
|
|
# -*- 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('--enable-nodejs',
|
|
|
|
help='Require Node.js to build')
|
|
|
|
|
|
|
|
|
|
|
|
# "nodejs" is first in the tuple on the assumption that it's only likely to
|
|
|
|
# exist on systems (probably linux distros) where there is a program in the path
|
|
|
|
# called "node" that does something else.
|
|
|
|
nodejs = check_prog('NODEJS', ('nodejs', 'node',),
|
|
|
|
allow_missing=True)
|
|
|
|
|
|
|
|
|
|
|
|
@depends_if(nodejs)
|
|
|
|
@checking('for node.js version')
|
|
|
|
@imports('os')
|
|
|
|
@imports('re')
|
|
|
|
@imports('subprocess')
|
|
|
|
def nodejs_version(node):
|
|
|
|
env = dict(os.environ)
|
|
|
|
env[b'NODE_DISABLE_COLORS'] = b'1'
|
|
|
|
|
2018-07-04 19:09:41 +03:00
|
|
|
out = check_cmd_output(node, '--version', env=env)
|
2018-07-04 00:24:58 +03:00
|
|
|
|
|
|
|
match = re.search(r'v(.+)$', out)
|
|
|
|
|
|
|
|
if not match:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return Version(match.group(1))
|
|
|
|
|
|
|
|
|
|
|
|
@depends('--enable-nodejs', nodejs, nodejs_version)
|
|
|
|
def nodejs_suitability(require, node, version):
|
|
|
|
MIN_NODE_VERSION = Version('8.11')
|
|
|
|
|
|
|
|
if not node:
|
|
|
|
msg = ('could not find Node.js executable; ensure `node` or `nodejs` '
|
|
|
|
'is in PATH or set NODEJS in environment to point to an '
|
|
|
|
'executable')
|
|
|
|
|
|
|
|
if require:
|
|
|
|
raise FatalCheckError(msg)
|
|
|
|
else:
|
|
|
|
log.warning(msg)
|
2018-07-19 10:36:36 +03:00
|
|
|
log.warning('(This will become an error in the near future.)')
|
2018-07-04 00:24:58 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
if not version:
|
|
|
|
msg = 'could not resolve Node.js version'
|
|
|
|
if require:
|
|
|
|
raise FatalCheckError(msg)
|
|
|
|
else:
|
|
|
|
log.warning(msg)
|
2018-07-19 10:36:36 +03:00
|
|
|
log.warning('(This will become an error in the near future.)')
|
2018-07-04 00:24:58 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
if version < MIN_NODE_VERSION:
|
2018-07-04 14:46:08 +03:00
|
|
|
msg = 'NODEJS must point to node %s or newer; %s found' % (
|
|
|
|
MIN_NODE_VERSION, version)
|
2018-07-04 00:24:58 +03:00
|
|
|
|
|
|
|
if require:
|
|
|
|
raise FatalCheckError(msg)
|
|
|
|
else:
|
|
|
|
log.warning(msg)
|