Bug NODE - Part 1: Add NODE to configure; add --enable-node-environment. draft
authorNick Alexander <nalexander@mozilla.com>
Thu, 05 Apr 2018 17:00:42 -0700
changeset 795812 6c0fccdfb560d6acb7d8135a94a795615aea9b8c
parent 795811 f950de93d8b8707dc9b7dd4bfcb1e79566837991
child 795813 d3be09fd0cb58e8c7348fd701f8e015c770d8ef9
push id110091
push userbmo:dmose@mozilla.org
push dateWed, 16 May 2018 16:58:05 +0000
milestone62.0a1
Bug NODE - Part 1: Add NODE to configure; add --enable-node-environment. The idea is that --enable-node-environment is a sibling to --disable-compile-environment. We can have folks opt-in to the Node development experience and iterate on the best workflows without requiring Node or inconveniencing all developers.
build/moz.configure/init.configure
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -417,16 +417,67 @@ def python3(env_python, mozillabuild):
         version=version,
         str_version='.'.join(str(v) for v in version),
     )
 
 
 set_config('PYTHON3', depends_if(python3)(lambda p: p.path))
 set_config('PYTHON3_VERSION', depends_if(python3)(lambda p: p.str_version))
 
+
+# node
+# ====
+
+# TODO remove node.exe once bug 1382940 addresses ambiguous executables case.
+node = check_prog('NODE', ('node.exe', 'node',), allow_missing=True)
+
+
+@depends_if(node)
+@checking('for node version >= 8.9.0')
+@imports('os')
+@imports('re')
+def node_version(node):
+    env = dict(os.environ)
+    env['NODE_DISABLE_COLORS'] = '1'
+
+    out = check_cmd_output(node, '--version', env=env)
+
+    match = re.search(r'v(.+)$', out)
+
+    if not match:
+        raise FatalCheckError('unable to determine node version: %s' % out)
+
+    node_version = Version(match.group(1))
+
+    min_node_version = '8.9.0'
+    if not node_version >= min_node_version:
+        raise FatalCheckError('NODE must point to node %s or newer; '
+                              '%s found' % (min_node_version, node_version))
+
+    return node_version
+
+
+option('--enable-node-environment',
+       help='Opt-in to experimental Node development experience.')
+
+
+@depends('--enable-node-environment', node, '--help')
+def enable_node_environment(node_env, node, help):
+    if node_env:
+        if not node:
+            die('You must specify NODE when building with '
+                '--enable-node-environment')
+
+        return node_env
+
+
+set_config('NODE_ENVIRONMENT', depends_if(enable_node_environment)(lambda _: True))
+add_old_configure_assignment('NODE_ENVIRONMENT', enable_node_environment)
+
+
 # Source checkout and version control integration.
 # ================================================
 
 
 @depends(check_build_environment, 'MOZ_AUTOMATION', '--help')
 @checking('for vcs source checkout')
 @imports('os')
 def vcs_checkout_type(build_env, automation, _):