summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/npm.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch2/npm.py')
-rw-r--r--bitbake/lib/bb/fetch2/npm.py64
1 files changed, 45 insertions, 19 deletions
diff --git a/bitbake/lib/bb/fetch2/npm.py b/bitbake/lib/bb/fetch2/npm.py
index df27669c58..3ff11e9c27 100644
--- a/bitbake/lib/bb/fetch2/npm.py
+++ b/bitbake/lib/bb/fetch2/npm.py
@@ -142,36 +142,62 @@ class Npm(FetchMethod):
142 142
143 self._unpackdep(ud, ud.pkgname, workobj, "%s/npmpkg" % destdir, dldir, d) 143 self._unpackdep(ud, ud.pkgname, workobj, "%s/npmpkg" % destdir, dldir, d)
144 144
145 def _getdependencies(self, pkg, data, version, d, ud): 145 def _parse_view(self, output):
146 '''
147 Parse the output of npm view --json; the last JSON result
148 is assumed to be the one that we're interested in.
149 '''
150 pdata = None
151 outdeps = {}
152 datalines = []
153 bracelevel = 0
154 for line in output.splitlines():
155 if bracelevel:
156 datalines.append(line)
157 elif '{' in line:
158 datalines = []
159 datalines.append(line)
160 bracelevel = bracelevel + line.count('{') - line.count('}')
161 if datalines:
162 pdata = json.loads('\n'.join(datalines))
163 return pdata
164
165 def _getdependencies(self, pkg, data, version, d, ud, optional=False):
146 pkgfullname = pkg 166 pkgfullname = pkg
147 if version != '*' and not '/' in version: 167 if version != '*' and not '/' in version:
148 pkgfullname += "@'%s'" % version 168 pkgfullname += "@'%s'" % version
149 logger.debug(2, "Calling getdeps on %s" % pkg) 169 logger.debug(2, "Calling getdeps on %s" % pkg)
150 fetchcmd = "npm view %s dist.tarball --registry %s" % (pkgfullname, ud.registry) 170 fetchcmd = "npm view %s --json --registry %s" % (pkgfullname, ud.registry)
151 output = runfetchcmd(fetchcmd, d, True) 171 output = runfetchcmd(fetchcmd, d, True)
152 # npm may resolve multiple versions 172 pdata = self._parse_view(output)
153 outputarray = output.strip().splitlines() 173 if not pdata:
154 if not outputarray:
155 raise FetchError("The command '%s' returned no output" % fetchcmd) 174 raise FetchError("The command '%s' returned no output" % fetchcmd)
156 # we just take the latest version npm resolved 175 if optional:
176 pkg_os = pdata.get('os', None)
177 if pkg_os:
178 if not isinstance(pkg_os, list):
179 pkg_os = [pkg_os]
180 if 'linux' not in pkg_os or '!linux' in pkg_os:
181 logger.debug(2, "Skipping %s since it's incompatible with Linux" % pkg)
182 return
157 #logger.debug(2, "Output URL is %s - %s - %s" % (ud.basepath, ud.basename, ud.localfile)) 183 #logger.debug(2, "Output URL is %s - %s - %s" % (ud.basepath, ud.basename, ud.localfile))
158 outputurl = outputarray[len(outputarray)-1].rstrip() 184 outputurl = pdata['dist']['tarball']
159 if (len(outputarray) > 1):
160 # remove the preceding version/name from npm output and then the
161 # first and last quotes
162 outputurl = outputurl.split(" ")[1][1:-1]
163 data[pkg] = {} 185 data[pkg] = {}
164 data[pkg]['tgz'] = os.path.basename(outputurl) 186 data[pkg]['tgz'] = os.path.basename(outputurl)
165 self._runwget(ud, d, "%s %s" % (self.basecmd, outputurl), False) 187 self._runwget(ud, d, "%s %s" % (self.basecmd, outputurl), False)
166 #fetchcmd = "npm view %s@%s dependencies --json" % (pkg, version) 188
167 fetchcmd = "npm view %s dependencies --json --registry %s" % (pkgfullname, ud.registry) 189 dependencies = pdata.get('dependencies', {})
168 output = runfetchcmd(fetchcmd, d, True) 190 optionalDependencies = pdata.get('optionalDependencies', {})
169 try: 191 depsfound = {}
170 depsfound = json.loads(output) 192 optdepsfound = {}
171 except:
172 # just assume there is no deps to be loaded here
173 return
174 data[pkg]['deps'] = {} 193 data[pkg]['deps'] = {}
194 for dep in dependencies:
195 if dep in optionalDependencies:
196 optdepsfound[dep] = dependencies[dep]
197 else:
198 depsfound[dep] = dependencies[dep]
199 for dep, version in optdepsfound.iteritems():
200 self._getdependencies(dep, data[pkg]['deps'], version, d, ud, optional=True)
175 for dep, version in depsfound.iteritems(): 201 for dep, version in depsfound.iteritems():
176 self._getdependencies(dep, data[pkg]['deps'], version, d, ud) 202 self._getdependencies(dep, data[pkg]['deps'], version, d, ud)
177 203