Bug 1471028 - Detect Node.js in configure; r=glandium
authorGregory Szorc <gps@mozilla.com>
Tue, 03 Jul 2018 21:24:58 +0000
changeset 424907 fe18414fe6852d0258895d45efc363ddde5210ed
parent 424906 d3d4619e8133d286727a1062e27ebeb962450647
child 424908 56833e08843f5e7e7ef5f909be5a6ba28a51d294
push id34226
push userrgurzau@mozilla.com
push dateWed, 04 Jul 2018 09:57:31 +0000
treeherdermozilla-central@3d7f2fdc5bf7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1471028
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1471028 - Detect Node.js in configure; r=glandium The intent is for the build system to soon require Node.js to build Firefox. But we aren't ready to make Node.js a build requirement just yet. The goal of this commit is to implement configure detection for Node.js so that we can a) work out detection bugs b) give people a means to validate system compatibility *before* we throw the switch to require Node.js. This commit introduces configure logic for finding a Node.js executable, resolving its version, and validating its suitability. By default, if Node.js cannot be found or there is an error resolving its version, we print some warning messages and move on. If --enable-nodejs is used (not the default), errors are raised if Node.js cannot be found or its version isn't suitable. Once we require Node.js, the added code can likely be simplified. When writing the code, I went out of my way to make failures as non-fatal as possible. e.g. normally we'd say that failures to run `node --version` would be fatal. I'm purposefully trying to not have this configure check break anyone's environment, even if failure occurs. Again, the goal is to introduce the configure checks first in a non-fatal way such that we can debug failures so the flag day transition is simpler. Differential Revision: https://phabricator.services.mozilla.com/D1818
build/moz.configure/node.configure
toolkit/moz.configure
new file mode 100644
--- /dev/null
+++ b/build/moz.configure/node.configure
@@ -0,0 +1,73 @@
+# -*- 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'
+
+    try:
+        out = subprocess.check_output([node, '--version'], env=env,
+                                      stderr=subprocess.STDOUT)
+    except subprocess.CalledProcessError as e:
+        return None
+
+    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)
+            log.warning('(This will become a fatal error in the near future.)')
+            return
+
+    if not version:
+        msg = 'could not resolve Node.js version'
+        if require:
+            raise FatalCheckError(msg)
+        else:
+            log.warning(msg)
+            log.warning('(This will become a fatal error in the near future.)')
+            return
+
+    if version < MIN_NODE_VERSION:
+        msg = 'NODEJS must point to node %s or newer; %s found' (
+            MIN_NODE_VERSION, node_version)
+
+        if require:
+            raise FatalCheckError(msg)
+        else:
+            log.warning(msg)
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -94,16 +94,19 @@ set_define('MOZ_PULSEAUDIO', depends_if(
 include('../js/moz.configure')
 
 
 # Rust
 # ==============================================================
 include('../build/moz.configure/rust.configure',
         when='--enable-compile-environment')
 
+# NodeJS
+# ==============================================================
+include('../build/moz.configure/node.configure')
 
 # L10N
 # ==============================================================
 option('--with-l10n-base', nargs=1, env='L10NBASEDIR',
        help='Path to l10n repositories')
 
 @depends('--with-l10n-base')
 @imports(_from='os.path', _import='isdir')