예제 #1
0
def eslint_setup(should_clobber=False):
    """Ensure eslint is optimally configured.

    This command will inspect your eslint configuration and
    guide you through an interactive wizard helping you configure
    eslint for optimal use on Mozilla projects.
    """
    orig_cwd = os.getcwd()
    sys.path.append(os.path.dirname(__file__))

    # npm sometimes fails to respect cwd when it is run using check_call so
    # we manually switch folders here instead.
    project_root = get_project_root()
    os.chdir(project_root)

    if should_clobber:
        node_modules_path = os.path.join(project_root, "node_modules")
        print("Clobbering node_modules...")
        if sys.platform.startswith('win') and have_winrm():
            process = subprocess.Popen(['winrm', '-rf', node_modules_path])
            process.wait()
        else:
            mozfileremove(node_modules_path)

    npm_path, version = get_node_or_npm_path("npm")
    if not npm_path:
        return 1

    extra_parameters = ["--loglevel=error"]

    package_lock_json_path = os.path.join(get_project_root(), "package-lock.json")
    package_lock_json_tmp_path = os.path.join(tempfile.gettempdir(), "package-lock.json.tmp")

    # If we have an npm version newer than 5.8.0, just use 'ci', as that's much
    # simpler and does exactly what we want.
    npm_is_older_version = version < LooseVersion("5.8.0")

    if npm_is_older_version:
        cmd = [npm_path, "install"]
        shutil.copy2(package_lock_json_path, package_lock_json_tmp_path)
    else:
        cmd = [npm_path, "ci"]

    cmd.extend(extra_parameters)
    print("Installing eslint for mach using \"%s\"..." % (" ".join(cmd)))
    result = call_process("eslint", cmd)

    if npm_is_older_version:
        shutil.move(package_lock_json_tmp_path, package_lock_json_path)

    if not result:
        return 1

    eslint_path = os.path.join(get_project_root(), "node_modules", ".bin", "eslint")

    print("\nESLint and approved plugins installed successfully!")
    print("\nNOTE: Your local eslint binary is at %s\n" % eslint_path)

    os.chdir(orig_cwd)
예제 #2
0
    def delete_dirs(self, root, paths_to_delete):
        """Deletes the given subdirectories in an optimal way."""
        procs = []
        for p in sorted(paths_to_delete):
            path = os.path.join(root, p)
            if sys.platform.startswith(
                    'win') and self.have_winrm() and os.path.isdir(path):
                procs.append(subprocess.Popen(['winrm', '-rf', path]))
            else:
                # We use mozfile because it is faster than shutil.rmtree().
                mozfileremove(path)

        for p in procs:
            p.wait()
예제 #3
0
def eslint_setup(should_clobber=False):
    """Ensure eslint is optimally configured.

    This command will inspect your eslint configuration and
    guide you through an interactive wizard helping you configure
    eslint for optimal use on Mozilla projects.
    """
    orig_cwd = os.getcwd()
    sys.path.append(os.path.dirname(__file__))

    # npm sometimes fails to respect cwd when it is run using check_call so
    # we manually switch folders here instead.
    project_root = get_project_root()
    os.chdir(project_root)

    if should_clobber:
        node_modules_path = os.path.join(project_root, "node_modules")
        print("Clobbering node_modules...")
        if sys.platform.startswith('win') and have_winrm():
            process = subprocess.Popen(['winrm', '-rf', node_modules_path])
            process.wait()
        else:
            mozfileremove(node_modules_path)

    npm_path = get_node_or_npm_path("npm")
    if not npm_path:
        return 1

    extra_parameters = ["--loglevel=error"]

    # Install ESLint and external plugins. We pass `--no-package-lock` to avoid
    # unexpected/unwanted npm changes to package-lock.json passing into the
    # tree.
    cmd = [npm_path, "install", "--no-package-lock"]
    cmd.extend(extra_parameters)
    print("Installing eslint for mach using \"%s\"..." % (" ".join(cmd)))
    if not call_process("eslint", cmd):
        return 1

    eslint_path = os.path.join(get_project_root(), "node_modules", ".bin",
                               "eslint")

    print("\nESLint and approved plugins installed successfully!")
    print("\nNOTE: Your local eslint binary is at %s\n" % eslint_path)

    os.chdir(orig_cwd)
예제 #4
0
def eslint_setup(should_clobber=False):
    """Ensure eslint is optimally configured.

    This command will inspect your eslint configuration and
    guide you through an interactive wizard helping you configure
    eslint for optimal use on Mozilla projects.
    """
    orig_cwd = os.getcwd()
    sys.path.append(os.path.dirname(__file__))

    # npm sometimes fails to respect cwd when it is run using check_call so
    # we manually switch folders here instead.
    project_root = get_project_root()
    os.chdir(project_root)

    if should_clobber:
        node_modules_path = os.path.join(project_root, "node_modules")
        print("Clobbering node_modules...")
        if sys.platform.startswith('win') and have_winrm():
            process = subprocess.Popen(['winrm', '-rf', node_modules_path])
            process.wait()
        else:
            mozfileremove(node_modules_path)

    npm_path = get_node_or_npm_path("npm")
    if not npm_path:
        return 1

    extra_parameters = ["--loglevel=error"]

    # Install ESLint and external plugins
    cmd = [npm_path, "install"]
    cmd.extend(extra_parameters)
    print("Installing eslint for mach using \"%s\"..." % (" ".join(cmd)))
    if not call_process("eslint", cmd):
        return 1

    eslint_path = os.path.join(get_project_root(), "node_modules", ".bin", "eslint")

    print("\nESLint and approved plugins installed successfully!")
    print("\nNOTE: Your local eslint binary is at %s\n" % eslint_path)

    os.chdir(orig_cwd)
예제 #5
0
    def remove_objdir(self, full=True):
        """Remove the object directory.

        ``full`` controls whether to fully delete the objdir. If False,
        some directories (e.g. Visual Studio Project Files) will not be
        deleted.
        """
        # Top-level files and directories to not clobber by default.
        no_clobber = {
            '.mozbuild',
            'msvc',
        }

        if full:
            # mozfile doesn't like unicode arguments (bug 818783).
            paths = [self.topobjdir.encode('utf-8')]
        else:
            try:
                paths = []
                for p in os.listdir(self.topobjdir):
                    if p not in no_clobber:
                        paths.append(
                            os.path.join(self.topobjdir, p).encode('utf-8'))
            except OSError as e:
                if e.errno != errno.ENOENT:
                    raise
                return

        procs = []
        for p in sorted(paths):
            path = os.path.join(self.topobjdir, p)
            if sys.platform.startswith(
                    'win') and self.have_winrm() and os.path.isdir(path):
                procs.append(subprocess.Popen(['winrm', '-rf', path]))
            else:
                # We use mozfile because it is faster than shutil.rmtree().
                mozfileremove(path)

        for p in procs:
            p.wait()
예제 #6
0
    def remove_objdir(self, full=True):
        """Remove the object directory.

        ``full`` controls whether to fully delete the objdir. If False,
        some directories (e.g. Visual Studio Project Files) will not be
        deleted.
        """
        # Top-level files and directories to not clobber by default.
        no_clobber = {
            '.mozbuild',
            'msvc',
        }

        if full:
            # mozfile doesn't like unicode arguments (bug 818783).
            paths = [self.topobjdir.encode('utf-8')]
        else:
            try:
                paths = []
                for p in os.listdir(self.topobjdir):
                    if p not in no_clobber:
                        paths.append(os.path.join(self.topobjdir, p).encode('utf-8'))
            except OSError as e:
                if e.errno != errno.ENOENT:
                    raise
                return

        procs = []
        for p in sorted(paths):
            path = os.path.join(self.topobjdir, p)
            if sys.platform.startswith('win') and self.have_winrm() and os.path.isdir(path):
                procs.append(subprocess.Popen(['winrm', '-rf', path]))
            else:
                # We use mozfile because it is faster than shutil.rmtree().
                mozfileremove(path)

        for p in procs:
            p.wait()
예제 #7
0
def package_setup(
    package_root,
    package_name,
    should_update=False,
    should_clobber=False,
    no_optional=False,
):
    """Ensure `package_name` at `package_root` is installed.

    When `should_update` is true, clobber, install, and produce a new
    "package-lock.json" file.

    This populates `package_root/node_modules`.

    """
    orig_project_root = get_project_root()
    orig_cwd = os.getcwd()

    if should_update:
        should_clobber = True

    try:
        set_project_root(package_root)
        sys.path.append(os.path.dirname(__file__))

        # npm sometimes fails to respect cwd when it is run using check_call so
        # we manually switch folders here instead.
        project_root = get_project_root()
        os.chdir(project_root)

        if should_clobber:
            node_modules_path = os.path.join(project_root, "node_modules")
            print("Clobbering %s..." % node_modules_path)
            if sys.platform.startswith("win") and have_winrm():
                process = subprocess.Popen(["winrm", "-rf", node_modules_path])
                process.wait()
            else:
                mozfileremove(node_modules_path)

        npm_path, _ = find_npm_executable()
        if not npm_path:
            return 1

        node_path, _ = find_node_executable()
        if not node_path:
            return 1

        extra_parameters = ["--loglevel=error"]

        if no_optional:
            extra_parameters.append("--no-optional")

        package_lock_json_path = os.path.join(get_project_root(),
                                              "package-lock.json")

        if should_update:
            cmd = [npm_path, "install"]
            mozfileremove(package_lock_json_path)
        else:
            cmd = [npm_path, "ci"]

        # On non-Windows, ensure npm is called via node, as node may not be in the
        # path.
        if platform.system() != "Windows":
            cmd.insert(0, node_path)

        # Ensure that bare `node` and `npm` in scripts, including post-install scripts, finds the
        # binary we're invoking with.  Without this, it's easy for compiled extensions to get
        # mismatched versions of the Node.js extension API.
        extra_parameters.append("--scripts-prepend-node-path")

        cmd.extend(extra_parameters)

        print('Installing %s for mach using "%s"...' %
              (package_name, " ".join(cmd)))
        result = call_process(package_name, cmd)

        if not result:
            return 1

        bin_path = os.path.join(get_project_root(), "node_modules", ".bin",
                                package_name)

        print("\n%s installed successfully!" % package_name)
        print("\nNOTE: Your local %s binary is at %s\n" %
              (package_name, bin_path))

    finally:
        set_project_root(orig_project_root)
        os.chdir(orig_cwd)
예제 #8
0
def package_setup(package_root,
                  package_name,
                  should_clobber=False,
                  no_optional=False):
    """Ensure `package_name` at `package_root` is installed.

    This populates `package_root/node_modules`.
    """
    orig_project_root = get_project_root()
    orig_cwd = os.getcwd()
    try:
        set_project_root(package_root)
        sys.path.append(os.path.dirname(__file__))

        # npm sometimes fails to respect cwd when it is run using check_call so
        # we manually switch folders here instead.
        project_root = get_project_root()
        os.chdir(project_root)

        if should_clobber:
            node_modules_path = os.path.join(project_root, "node_modules")
            print("Clobbering %s..." % node_modules_path)
            if sys.platform.startswith('win') and have_winrm():
                process = subprocess.Popen(['winrm', '-rf', node_modules_path])
                process.wait()
            else:
                mozfileremove(node_modules_path)

        npm_path, version = find_npm_executable()
        if not npm_path:
            return 1

        node_path, _ = find_node_executable()
        if not node_path:
            return 1

        extra_parameters = ["--loglevel=error"]

        if no_optional:
            extra_parameters.append('--no-optional')

        package_lock_json_path = os.path.join(get_project_root(),
                                              "package-lock.json")
        package_lock_json_tmp_path = os.path.join(tempfile.gettempdir(),
                                                  "package-lock.json.tmp")

        # If we have an npm version newer than 5.8.0, just use 'ci', as that's much
        # simpler and does exactly what we want.
        npm_is_older_version = version < StrictVersion("5.8.0").version

        if npm_is_older_version:
            cmd = [npm_path, "install"]
            shutil.copy2(package_lock_json_path, package_lock_json_tmp_path)
        else:
            cmd = [npm_path, "ci"]

        # On non-Windows, ensure npm is called via node, as node may not be in the
        # path.
        if platform.system() != "Windows":
            cmd.insert(0, node_path)

        cmd.extend(extra_parameters)

        # Ensure that bare `node` and `npm` in scripts, including post-install scripts, finds the
        # binary we're invoking with.  Without this, it's easy for compiled extensions to get
        # mismatched versions of the Node.js extension API.
        path = os.environ.get('PATH', '').split(os.pathsep)
        node_dir = os.path.dirname(node_path)
        if node_dir not in path:
            path = [node_dir] + path

        print("Installing %s for mach using \"%s\"..." %
              (package_name, " ".join(cmd)))
        result = call_process(package_name,
                              cmd,
                              append_env={'PATH': os.pathsep.join(path)})

        if npm_is_older_version:
            shutil.move(package_lock_json_tmp_path, package_lock_json_path)

        if not result:
            return 1

        bin_path = os.path.join(get_project_root(), "node_modules", ".bin",
                                package_name)

        print("\n%s installed successfully!" % package_name)
        print("\nNOTE: Your local %s binary is at %s\n" %
              (package_name, bin_path))

    finally:
        set_project_root(orig_project_root)
        os.chdir(orig_cwd)