Skip to content

Commit

Permalink
Pull Node x86 build for x86 platform (#202)
Browse files Browse the repository at this point in the history
* setup nodejs build for x86

* normaliz the version number

* update version format

* normalize version

* fix version normalize

* update build path

* test extra path

* update extra path

* clean up print and comments

* using constant variable for default version

* fix lint

* try using target os/arch information instead of current_os and arch

* setup npm alias on linux

* dont skip windows when arch==x86

* revert armv6 changes

* setup alias for node and npm

* revert os support changes

* revert os support changes
  • Loading branch information
xiazhvera authored Nov 16, 2022
1 parent ed96f8a commit 3dc392c
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions builder/imports/nodejs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.

from builder.core.fetch import fetch_script
from builder.core.host import current_os
from builder.core.fetch import fetch_script, fetch_and_extract
from builder.core.host import current_os, current_arch
from builder.core.project import Import
import builder.core.util as util
from builder.actions.install import InstallPackages
from builder.actions.script import Script

import stat
import os
import re


NVM = """\
Expand All @@ -20,6 +21,8 @@
nvm $*
"""

DEFAULT_VERSION = '12'


class NodeJS(Import):
def __init__(self, **kwargs):
Expand All @@ -30,7 +33,7 @@ def __init__(self, **kwargs):
},
**kwargs)
self.url = 'https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh'
self.version = kwargs.get('version', '12')
self.version = kwargs.get('version', DEFAULT_VERSION)

self.nvm = 'nvm'
self.installed = False
Expand All @@ -44,12 +47,15 @@ def install(self, env):
self.install_dir = os.path.join(env.deps_dir, self.name)
sh.mkdir(self.install_dir)

if current_os() == 'windows':
self.install_nvm_choco(env)
if current_arch() == "x86":
self.install_node_via_unofficial_build(env)
else:
self.install_nvm_sh(env)
if current_os() == 'windows':
self.install_nvm_choco(env)
else:
self.install_nvm_sh(env)

self.install_node_via_nvm(env)
self.install_node_via_nvm(env)

self.installed = True

Expand Down Expand Up @@ -113,6 +119,36 @@ def install_nvm_sh(self, env):
os.chmod(run_nvm, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
self.nvm = run_nvm

def install_node_via_unofficial_build(self, env):
sh = env.shell
print('Installing node build directly'.format(self.version))

# Normaliz version format, please note 12.16.3 is the last version has x86 support
def normalize_version(v):
append_times = 0
while re.match('^([0-9]+\.){2}[0-9]+$', v) == None:
# Only try append sub version twice
if append_times < 2:
v += ".0"
append_times += 1
else: # DEFAULT TO 12.0.0
return (DEFAULT_VERSION + ".0.0")
return v

version = normalize_version(self.version)
url = "https://unofficial-builds.nodejs.org/download/release/v{}/node-v{}-{}-{}.tar.gz".format(
version, version, current_os(), current_arch())
package_name = "node-v{}-{}-{}".format(version, current_os(), current_arch())

# Fetch the node build
extra_path = '{}/node_install'.format(self.install_dir)
package_path = '{}/node_package'.format(self.install_dir)
fetch_and_extract(url, package_path, extra_path)

# Set PATH
node_path = '{}/{}/bin'.format(extra_path, package_name)
sh.setenv('PATH', '{}{}{}'.format(node_path, os.pathsep, sh.getenv('PATH')))


class Node12(NodeJS):
def __init__(self, **kwargs):
Expand Down

0 comments on commit 3dc392c

Please sign in to comment.