Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alternate nodejs binaries #7405

Merged
merged 2 commits into from
Mar 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

from pants.base.exceptions import TaskError
from pants.binaries.binary_tool import NativeTool
from pants.binaries.binary_util import BinaryToolUrlGenerator
from pants.option.custom_types import dir_option, file_option
from pants.util.dirutil import safe_mkdir, safe_rmtree
from pants.util.dirutil import is_readable_dir, safe_mkdir, safe_rmtree
from pants.util.memo import memoized_method, memoized_property

from pants.contrib.node.subsystems.command import command_gen
Expand All @@ -28,6 +29,20 @@
logger = logging.getLogger(__name__)


class NodeReleaseUrlGenerator(BinaryToolUrlGenerator):

_DIST_URL_FMT = 'https://nodejs.org/dist/{version}/node-{version}-{system_id}.tar.gz'

_SYSTEM_ID = {
'mac': 'darwin-x64',
'linux': 'linux-x64',
}

def generate_urls(self, version, host_platform):
system_id = self._SYSTEM_ID[host_platform.os_name]
return [self._DIST_URL_FMT.format(version=version, system_id=system_id)]


class NodeDistribution(NativeTool):
"""Represents a self-bootstrapping Node distribution."""

Expand All @@ -36,6 +51,9 @@ class NodeDistribution(NativeTool):
default_version = 'v8.11.3'
archive_type = 'tgz'

def get_external_url_generator(self):
return NodeReleaseUrlGenerator()

@classmethod
def subsystem_dependencies(cls):
# Note that we use a YarnpkgDistribution scoped to the NodeDistribution, which may itself
Expand Down Expand Up @@ -114,6 +132,10 @@ def _install_node(self):
# This line depends on repacked node distribution.
# Should change it from 'node/bin' to 'dist/bin'
node_bin_path = os.path.join(node_package_path, 'node', 'bin')
if not is_readable_dir(node_bin_path):
# The binary was pulled from nodejs and not our S3, in which
# case it's installed under a different directory.
return os.path.join(node_package_path, os.listdir(node_package_path)[0], 'bin')
return node_bin_path

@memoized_method
Expand Down Expand Up @@ -151,7 +173,7 @@ def _configure_eslinter(self, bootstrapped_support_path):

def eslint_supportdir(self, task_workdir):
""" Returns the path where the ESLint is bootstrapped.

:param string task_workdir: The task's working directory
:returns: The path where ESLint is bootstrapped and whether or not it is configured
:rtype: (string, bool)
Expand Down