summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/bb/fetch2/npm.py42
1 files changed, 27 insertions, 15 deletions
diff --git a/bitbake/lib/bb/fetch2/npm.py b/bitbake/lib/bb/fetch2/npm.py
index a39f1c1998..e497c38dc7 100644
--- a/bitbake/lib/bb/fetch2/npm.py
+++ b/bitbake/lib/bb/fetch2/npm.py
@@ -79,9 +79,25 @@ class NpmEnvironment(object):
79 Using a npm config file seems more reliable than using cli arguments. 79 Using a npm config file seems more reliable than using cli arguments.
80 This class allows to create a controlled environment for npm commands. 80 This class allows to create a controlled environment for npm commands.
81 """ 81 """
82 def __init__(self, d, configs=None): 82 def __init__(self, d, configs=None, npmrc=None):
83 self.d = d 83 self.d = d
84 self.configs = configs 84
85 if configs:
86 self.user_config = tempfile.NamedTemporaryFile(mode="w", buffering=1)
87 self.user_config_name = self.user_config.name
88 for key, value in configs:
89 self.user_config.write("%s=%s\n" % (key, value))
90 else:
91 self.user_config_name = "/dev/null"
92
93 if npmrc:
94 self.global_config_name = npmrc
95 else:
96 self.global_config_name = "/dev/null"
97
98 def __del__(self):
99 if self.user_config:
100 self.user_config.close()
85 101
86 def run(self, cmd, args=None, configs=None, workdir=None): 102 def run(self, cmd, args=None, configs=None, workdir=None):
87 """Run npm command in a controlled environment""" 103 """Run npm command in a controlled environment"""
@@ -89,23 +105,19 @@ class NpmEnvironment(object):
89 d = bb.data.createCopy(self.d) 105 d = bb.data.createCopy(self.d)
90 d.setVar("HOME", tmpdir) 106 d.setVar("HOME", tmpdir)
91 107
92 cfgfile = os.path.join(tmpdir, "npmrc")
93
94 if not workdir: 108 if not workdir:
95 workdir = tmpdir 109 workdir = tmpdir
96 110
97 def _run(cmd): 111 def _run(cmd):
98 cmd = "NPM_CONFIG_USERCONFIG=%s " % cfgfile + cmd 112 cmd = "NPM_CONFIG_USERCONFIG=%s " % (self.user_config_name) + cmd
99 cmd = "NPM_CONFIG_GLOBALCONFIG=%s " % cfgfile + cmd 113 cmd = "NPM_CONFIG_GLOBALCONFIG=%s " % (self.global_config_name) + cmd
100 return runfetchcmd(cmd, d, workdir=workdir) 114 return runfetchcmd(cmd, d, workdir=workdir)
101 115
102 if self.configs:
103 for key, value in self.configs:
104 _run("npm config set %s %s" % (key, shlex.quote(value)))
105
106 if configs: 116 if configs:
117 bb.warn("Use of configs argument of NpmEnvironment.run() function"
118 " is deprecated. Please use args argument instead.")
107 for key, value in configs: 119 for key, value in configs:
108 _run("npm config set %s %s" % (key, shlex.quote(value))) 120 cmd += " --%s=%s" % (key, shlex.quote(value))
109 121
110 if args: 122 if args:
111 for key, value in args: 123 for key, value in args:
@@ -167,14 +179,14 @@ class Npm(FetchMethod):
167 179
168 def _resolve_proxy_url(self, ud, d): 180 def _resolve_proxy_url(self, ud, d):
169 def _npm_view(): 181 def _npm_view():
170 configs = [] 182 args = []
171 configs.append(("json", "true")) 183 args.append(("json", "true"))
172 configs.append(("registry", ud.registry)) 184 args.append(("registry", ud.registry))
173 pkgver = shlex.quote(ud.package + "@" + ud.version) 185 pkgver = shlex.quote(ud.package + "@" + ud.version)
174 cmd = ud.basecmd + " view %s" % pkgver 186 cmd = ud.basecmd + " view %s" % pkgver
175 env = NpmEnvironment(d) 187 env = NpmEnvironment(d)
176 check_network_access(d, cmd, ud.registry) 188 check_network_access(d, cmd, ud.registry)
177 view_string = env.run(cmd, configs=configs) 189 view_string = env.run(cmd, args=args)
178 190
179 if not view_string: 191 if not view_string:
180 raise FetchError("Unavailable package %s" % pkgver, ud.url) 192 raise FetchError("Unavailable package %s" % pkgver, ud.url)