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

Submitted by Jean-Marie LEMETAYER on Nov. 20, 2019, 9:34 a.m. | Patch ID: 167184

Details

Message ID 20191120093412.11519-6-jean-marie.lemetayer@savoirfairelinux.com
State New
Headers show

Commit Message

Jean-Marie LEMETAYER Nov. 20, 2019, 9:34 a.m.
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@savoirfairelinux.com>
---
 lib/bb/fetch2/npm.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

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)