diff options
author | Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com> | 2019-05-17 17:14:07 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-05-20 12:16:03 +0100 |
commit | 3d319c79981811d3cfd4732885057db4fd5afcc2 (patch) | |
tree | 7bdbb7c9f812275933bb1f96aca257d8c48fc4ad /lib | |
parent | bf53f07c3647e57d8452a7743a2b04bcb72c80d6 (diff) | |
download | bitbake-3d319c79981811d3cfd4732885057db4fd5afcc2.tar.gz |
bitbake: fetch2/npm: fix npw view parsing
Fixes [YOCTO #13344]
When parsing manually the 'npm view --json' ouput, an extra closing
brackets in a JSON string can leads the fetcher to fail with a
JSONDecodeError exception.
This commit use the JSON parser to extract:
- The last object in the returned array if there are multiple results.
- The returned object if there is only one result.
Signed-off-by: Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bb/fetch2/npm.py | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py index f08bdee73..4427b1bb8 100644 --- a/lib/bb/fetch2/npm.py +++ b/lib/bb/fetch2/npm.py @@ -151,20 +151,11 @@ class Npm(FetchMethod): Parse the output of npm view --json; the last JSON result is assumed to be the one that we're interested in. ''' - pdata = None - outdeps = {} - datalines = [] - bracelevel = 0 - for line in output.splitlines(): - if bracelevel: - datalines.append(line) - elif '{' in line: - datalines = [] - datalines.append(line) - bracelevel = bracelevel + line.count('{') - line.count('}') - if datalines: - pdata = json.loads('\n'.join(datalines)) - return pdata + pdata = json.loads(output); + try: + return pdata[-1] + except: + return pdata def _getdependencies(self, pkg, data, version, d, ud, optional=False, fetchedlist=None): if fetchedlist is None: |