Bug NODE: Remove node_manager and references draft
authorDan Mosedale <dmose@meer.net>
Tue, 15 May 2018 20:29:40 -0700
changeset 795817 8da66ded52a8701cb8d76a67fb2a0d46ec83f5a5
parent 795816 79f159d867e786b8fea50cbb255d5a48f737b9a2
child 795818 1e5c2f551e0c34d4e323d8777e367a7adabcdee4
push id110091
push userbmo:dmose@mozilla.org
push dateWed, 16 May 2018 16:58:05 +0000
milestone62.0a1
Bug NODE: Remove node_manager and references
python/mozbuild/mozbuild/action/node.py
python/mozbuild/mozbuild/node_manager.py
--- a/python/mozbuild/mozbuild/action/node.py
+++ b/python/mozbuild/mozbuild/action/node.py
@@ -2,59 +2,44 @@
 # 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/.
 
 # Invoke yarn.
 
 from __future__ import absolute_import, unicode_literals, print_function
 
 import buildconfig
-from mozbuild import (
-    node_manager,
-)
-from mozbuild.configure.util import (
-    LineIO,
-)
 import mozpack.path as mozpath
 import os
 import pipes
 import subprocess
 import sys
 
 
 def main(output, config, *flags):
-    log_handle = LineIO(print)
-
-    manager = node_manager.NodeManager(buildconfig.topsrcdir, log_handle)
-
-    # XXX -- comment on why offline=False.
-    # XXX -- comment on why '_node'.
-    manager.populate(buildconfig.substs['NODE'], mozpath.join(buildconfig.topobjdir, '_node'),
-                        offline=False)
-
+    # XXX once we switch to multiple inputs, we may need a better way
+    # to get this
     cwd = os.path.dirname(os.path.abspath(config))
 
     try:
-        args = [
-            mozpath.join(buildconfig.topsrcdir, 'mach'), 'yarn',
-        ]
-        args.extend(flags)
+        args = flags
 
         cmd = ' '.join(pipes.quote(arg) for arg in args)
         print('"{}" in {}'.format(cmd, cwd), file=sys.stderr)
         sys.stderr.flush()
 
         env = dict(os.environ)
 
         # TODO: explain how this enables bare `webpack` in scripts.
-        relcwd = mozpath.relpath(os.getcwd(), buildconfig.topobjdir)
-        path = mozpath.join(buildconfig.topobjdir, '_node', relcwd, 'node_modules', '.bin')
+        path = mozpath.join(buildconfig.topsrcdir, 'node_modules', '.bin')
         if os.path.exists(path) and os.path.isdir(path):
             if 'PATH' in env:
                 path += os.pathsep + env['PATH']
             env['PATH'] = path
 
         subprocess.check_call(args, cwd=cwd, env=env)
 
         return 0
     except subprocess.CalledProcessError as err:
+        # XXX OSError: [Errno 13] Permission denied may mean "not installed".
+        # Figure out way to display more clearly.
         print('Failed with %s.' % str(err))
         return 1
deleted file mode 100644
--- a/python/mozbuild/mozbuild/node_manager.py
+++ /dev/null
@@ -1,115 +0,0 @@
-# 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/.
-
-# This file contains code for populating the virtualenv environment for
-# Mozilla's build system. It is typically called as part of configure.
-
-from __future__ import absolute_import, print_function, unicode_literals
-
-import json
-import os
-import pipes
-import shutil
-import subprocess
-from mozbuild.util import (
-    ensureParentDir,
-)
-from mozpack.copier import (
-    FileCopier,
-    FileRegistry,
-)
-from mozpack.manifests import InstallManifest
-import mozpack.path as mozpath
-
-
-class NodeManager:
-    def __init__(self, topsrcdir, log_handle):
-        self.topsrcdir = topsrcdir
-        self.log_handle = log_handle
-
-    def _log_process_output(self, *args, **kwargs):
-        if hasattr(self.log_handle, 'fileno'):
-            return subprocess.call(*args, stdout=self.log_handle,
-                                   stderr=subprocess.STDOUT, **kwargs)
-
-        proc = subprocess.Popen(*args, stdout=subprocess.PIPE,
-                                stderr=subprocess.STDOUT, **kwargs)
-
-        for line in proc.stdout:
-            self.log_handle.write(line)
-
-        return proc.wait()
-
-    def populate(self, node, destdir, offline=True):
-        """
-XXX
-Create a new, empty virtualenv.
-
-        Receives the path to virtualenv's virtualenv.py script (which will be
-        called out to), the path to create the virtualenv in, and a handle to
-        write output to.
-        """
-        package_json = json.load(open(mozpath.join(self.topsrcdir, 'package.json'), 'rt'))
-        dependencies = package_json.get('dependencies', {})
-
-        install_manifest = InstallManifest()
-
-        for workspace in package_json.get('workspaces', []):
-            workspace_name = os.path.basename(os.path.abspath(workspace))
-            if workspace_name in dependencies:
-                raise ValueError('XXX 1')
-
-            src = mozpath.join(self.topsrcdir, workspace, 'package.json')
-            dst = mozpath.join(workspace, 'package.json')
-
-            install_manifest.add_link(src, dst)
-
-        copier = FileCopier()
-        install_manifest.populate_registry(
-            copier, link_policy="symlink"
-        )
-        result = copier.copy(destdir,
-                             remove_unaccounted=False,
-                             remove_all_directory_symlinks=False,
-                             remove_empty_directories=False)
-
-        # "workspaces": ["path/relative/to/topsrcdir"] correctly installs
-        # one layer of devDependencies, essential for (e.g.) webpack.
-        # However, this can write into topsrcdir because of symlinks.
-        # (Unclear what happens across drives, where symlinking is
-        # generally not supported.)  Solutions:
-        #
-        # 1) unroll writes into topsrcdir.  Violates read-only nature of
-        # topsrcdir.
-        #
-        # 2) create a shadow package hierarchy in object directory so that
-        # symlink targets are in the object directory.
-        #
-        # "dependencies": ["file:/absolute/path/into/topsrcdir"] and
-        # "yarn-link-file-dependencies false" does not handle
-        # devDependencies correctly.
-
-        json.dump(package_json, open(mozpath.join(destdir, 'package.json'), 'wt'))
-
-        print(json.dumps(package_json, indent=2))
-
-        s = open(mozpath.join(self.topsrcdir, '.yarnrc'), 'rt').read()
-
-        with open(mozpath.join(destdir, '.yarnrc'), 'wt') as f:
-            f.write(s.replace('"third_party/yarn-offline-mirror"',
-                              '"{}/third_party/yarn-offline-mirror"'.format(self.topsrcdir)))
-
-        yarn = mozpath.join(self.topsrcdir, 'third_party', 'yarn', 'yarn.js')
-        args = [node, yarn, 'install', '--production=false', '--ignore-engines', '--verbose']
-        if offline:
-            shutil.copy(mozpath.join(self.topsrcdir, 'yarn.lock'), destdir)
-            args.append('--offline')
-
-        cmd = ' '.join(pipes.quote(a) for a in args)
-        print('"{}" in {}'.format(cmd, destdir))
-        result = self._log_process_output(args, cwd=destdir)
-
-        if result:
-            node_modules = mozpath.join(destdir, 'node_modules')
-            raise Exception('Failed to create node_modules: {}'.format(node_modules))