diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2017-02-07 09:45:41 +1300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-02-07 14:50:09 +0000 |
commit | 6ac9c605e6f921f272e1a6764c5ad68cca864865 (patch) | |
tree | ba138a393a8479e4ec8fe2bbcf9db9c306c33b9c /scripts | |
parent | 21ace8b6202e906689619ebdb41e745a6c12975b (diff) | |
download | poky-6ac9c605e6f921f272e1a6764c5ad68cca864865.tar.gz |
recipetool: create: properly handle npm optional dependencies
npm's package.json supports two types of dependencies -
optionalDependencies and dependencies; in the code for creating a recipe
from a non-npm source (e.g. a git repository) we were not handling
optionalDependencies and thus when pointed at a node.js application
outside of npm we weren't taking care of all dependencies.
(From OE-Core rev: 2b66cb9982d10ce1744d430858eaef3e5a72c8c0)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/recipetool/create_npm.py | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py index 888aa2b00a..3ba6de029c 100644 --- a/scripts/lib/recipetool/create_npm.py +++ b/scripts/lib/recipetool/create_npm.py | |||
@@ -83,7 +83,7 @@ class NpmRecipeHandler(RecipeHandler): | |||
83 | extravalues['extrafiles']['lockdown.json'] = tmpfile | 83 | extravalues['extrafiles']['lockdown.json'] = tmpfile |
84 | lines_before.append('NPM_LOCKDOWN := "${THISDIR}/${PN}/lockdown.json"') | 84 | lines_before.append('NPM_LOCKDOWN := "${THISDIR}/${PN}/lockdown.json"') |
85 | 85 | ||
86 | def _handle_dependencies(self, d, deps, lines_before, srctree): | 86 | def _handle_dependencies(self, d, deps, optdeps, lines_before, srctree): |
87 | import scriptutils | 87 | import scriptutils |
88 | # If this isn't a single module we need to get the dependencies | 88 | # If this isn't a single module we need to get the dependencies |
89 | # and add them to SRC_URI | 89 | # and add them to SRC_URI |
@@ -92,8 +92,17 @@ class NpmRecipeHandler(RecipeHandler): | |||
92 | if not origvalue.startswith('npm://'): | 92 | if not origvalue.startswith('npm://'): |
93 | src_uri = origvalue.split() | 93 | src_uri = origvalue.split() |
94 | changed = False | 94 | changed = False |
95 | for dep, depdata in deps.items(): | 95 | deplist = {} |
96 | version = self.get_node_version(dep, depdata, d) | 96 | for dep, depver in optdeps.items(): |
97 | depdata = self.get_npm_data(dep, depver, d) | ||
98 | if self.check_npm_optional_dependency(depdata): | ||
99 | deplist[dep] = depdata | ||
100 | for dep, depver in deps.items(): | ||
101 | depdata = self.get_npm_data(dep, depver, d) | ||
102 | deplist[dep] = depdata | ||
103 | |||
104 | for dep, depdata in deplist.items(): | ||
105 | version = depdata.get('version', None) | ||
97 | if version: | 106 | if version: |
98 | url = 'npm://registry.npmjs.org;name=%s;version=%s;subdir=node_modules/%s' % (dep, version, dep) | 107 | url = 'npm://registry.npmjs.org;name=%s;version=%s;subdir=node_modules/%s' % (dep, version, dep) |
99 | scriptutils.fetch_uri(d, url, srctree) | 108 | scriptutils.fetch_uri(d, url, srctree) |
@@ -170,8 +179,8 @@ class NpmRecipeHandler(RecipeHandler): | |||
170 | if 'homepage' in data: | 179 | if 'homepage' in data: |
171 | extravalues['HOMEPAGE'] = data['homepage'] | 180 | extravalues['HOMEPAGE'] = data['homepage'] |
172 | 181 | ||
173 | deps = data.get('dependencies', {}) | 182 | deps, optdeps = self.get_npm_package_dependencies(data) |
174 | updated = self._handle_dependencies(tinfoil.config_data, deps, lines_before, srctree) | 183 | updated = self._handle_dependencies(tinfoil.config_data, deps, optdeps, lines_before, srctree) |
175 | if updated: | 184 | if updated: |
176 | # We need to redo the license stuff | 185 | # We need to redo the license stuff |
177 | self._replace_license_vars(srctree, lines_before, handled, extravalues, tinfoil.config_data) | 186 | self._replace_license_vars(srctree, lines_before, handled, extravalues, tinfoil.config_data) |
@@ -251,7 +260,7 @@ class NpmRecipeHandler(RecipeHandler): | |||
251 | 260 | ||
252 | # FIXME this is effectively duplicated from lib/bb/fetch2/npm.py | 261 | # FIXME this is effectively duplicated from lib/bb/fetch2/npm.py |
253 | # (split out from _getdependencies()) | 262 | # (split out from _getdependencies()) |
254 | def get_node_version(self, pkg, version, d): | 263 | def get_npm_data(self, pkg, version, d): |
255 | import bb.fetch2 | 264 | import bb.fetch2 |
256 | pkgfullname = pkg | 265 | pkgfullname = pkg |
257 | if version != '*' and not '/' in version: | 266 | if version != '*' and not '/' in version: |
@@ -261,7 +270,40 @@ class NpmRecipeHandler(RecipeHandler): | |||
261 | fetchcmd = "npm view %s --json" % pkgfullname | 270 | fetchcmd = "npm view %s --json" % pkgfullname |
262 | output, _ = bb.process.run(fetchcmd, stderr=subprocess.STDOUT, env=runenv, shell=True) | 271 | output, _ = bb.process.run(fetchcmd, stderr=subprocess.STDOUT, env=runenv, shell=True) |
263 | data = self._parse_view(output) | 272 | data = self._parse_view(output) |
264 | return data.get('version', None) | 273 | return data |
274 | |||
275 | # FIXME this is effectively duplicated from lib/bb/fetch2/npm.py | ||
276 | # (split out from _getdependencies()) | ||
277 | def get_npm_package_dependencies(self, pdata): | ||
278 | dependencies = pdata.get('dependencies', {}) | ||
279 | optionalDependencies = pdata.get('optionalDependencies', {}) | ||
280 | dependencies.update(optionalDependencies) | ||
281 | depsfound = {} | ||
282 | optdepsfound = {} | ||
283 | for dep in dependencies: | ||
284 | if dep in optionalDependencies: | ||
285 | optdepsfound[dep] = dependencies[dep] | ||
286 | else: | ||
287 | depsfound[dep] = dependencies[dep] | ||
288 | return depsfound, optdepsfound | ||
289 | |||
290 | # FIXME this is effectively duplicated from lib/bb/fetch2/npm.py | ||
291 | # (split out from _getdependencies()) | ||
292 | def check_npm_optional_dependency(self, pdata): | ||
293 | pkg_os = pdata.get('os', None) | ||
294 | if pkg_os: | ||
295 | if not isinstance(pkg_os, list): | ||
296 | pkg_os = [pkg_os] | ||
297 | blacklist = False | ||
298 | for item in pkg_os: | ||
299 | if item.startswith('!'): | ||
300 | blacklist = True | ||
301 | break | ||
302 | if (not blacklist and 'linux' not in pkg_os) or '!linux' in pkg_os: | ||
303 | logger.debug(2, "Skipping %s since it's incompatible with Linux" % pkg) | ||
304 | return False | ||
305 | return True | ||
306 | |||
265 | 307 | ||
266 | def register_recipe_handlers(handlers): | 308 | def register_recipe_handlers(handlers): |
267 | handlers.append((NpmRecipeHandler(), 60)) | 309 | handlers.append((NpmRecipeHandler(), 60)) |