[bitbake-devel] [PATCH v3 5/7] fetch2/npm.py: unpack the dependencies in a node_modules directory

Jean-Marie LEMETAYER jean-marie.lemetayer at savoirfairelinux.com
Wed Nov 20 09:34:10 UTC 2019


This commit unpacks the dependencies in a node_modules directory in the
source tree. This is needed to allow license file management for all the
dependencies. This way the license files of the dependencies can be
tracked in the LIC_FILES_CHKSUM variable.

Signed-off-by: Jean-Marie LEMETAYER <jean-marie.lemetayer at savoirfairelinux.com>
---
 lib/bb/fetch2/npm.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py
index bd6e32ca..9beb84bf 100644
--- a/lib/bb/fetch2/npm.py
+++ b/lib/bb/fetch2/npm.py
@@ -325,16 +325,27 @@ def unpack_dependencies(d, shrinkwrap_file=None):
         unpacked in the source tree and added to the npm cache.
     """
     bb.utils.remove(d.getVar("NPM_CACHE_DIR"), recurse=True)
+    bb.utils.remove(d.expand("${S}/node_modules/"), recurse=True)
 
     def cache_dependency(tarball):
         cmd = "npm cache add '{}'".format(tarball)
         cmd += d.expand(" --cache=${NPM_CACHE_DIR}")
         runfetchcmd(cmd, d)
 
-    def handle_dependency(name, version, *unused):
+    def unpack_dependency(tarball, srctree):
+        cmd = "tar --extract --gzip --file='{}'".format(tarball)
+        cmd += " --no-same-owner"
+        cmd += " --transform 's:^package/::'"
+        bb.utils.mkdirhier(srctree)
+        runfetchcmd(cmd, d, workdir=srctree)
+
+    def handle_dependency(name, version, deptree):
         url = _get_url(d, name, version)
         fetcher = bb.fetch2.Fetch([url], d)
         tarball = fetcher.localpath(url)
         cache_dependency(tarball)
+        relpath = os.path.join(*[os.path.join("node_modules", d) for d in deptree])
+        abspath = os.path.join(d.getVar("S"), relpath)
+        unpack_dependency(tarball, abspath)
 
     foreach_dependencies(d, handle_dependency, shrinkwrap_file)
-- 
2.20.1



More information about the bitbake-devel mailing list