[packages/rpm/nodejs: 3/5] add supplementary files

glen glen at pld-linux.org
Sun Apr 28 23:07:01 CEST 2013


commit eae3da68e87186c73d06d61b28ceb2c51d66f754
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Sun Apr 28 23:41:34 2013 +0300

    add supplementary files

 nodejs-autodeps.patch |  87 +++++++++++++++++++++++++++++
 nodejs.macros         |  12 ++++
 nodejs.prov           |  45 +++++++++++++++
 nodejs.req            | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 292 insertions(+)
---
diff --git a/nodejs-autodeps.patch b/nodejs-autodeps.patch
new file mode 100644
index 0000000..1fc90e4
--- /dev/null
+++ b/nodejs-autodeps.patch
@@ -0,0 +1,87 @@
+--- rpm-5.4.10/lib/rpmfc.h~	2013-04-28 23:05:05.000000000 +0300
++++ rpm-5.4.10/lib/rpmfc.h	2013-04-28 23:08:27.668453931 +0300
+@@ -48,6 +48,7 @@
+     RPMFC_MANPAGE		= (7 << 16),
+     RPMFC_TEXT			= (8 << 16),
+     RPMFC_DOCUMENT		= (9 << 16),
++    RPMFC_NODEJS		= (10 << 16),
+ 
+     RPMFC_ARCHIVE		= (1 << 20),
+     RPMFC_COMPRESSED		= (1 << 21),
+--- rpm-5.4.10/lib/rpmfc.c	2013-04-28 23:10:48.781649157 +0300
++++ rpm-5.4.10/lib/rpmfc.c	2013-04-28 23:24:04.738348320 +0300
+@@ -618,6 +618,8 @@
+   { "ruby script text",		RPMFC_RUBY|RPMFC_INCLUDE },
+   { "Ruby script text",		RPMFC_RUBY|RPMFC_INCLUDE },
+ 
++  { "Node.js script",		RPMFC_NODEJS|RPMFC_INCLUDE },
++
+   { "current ar archive",	RPMFC_STATIC|RPMFC_LIBRARY|RPMFC_ARCHIVE|RPMFC_INCLUDE },
+ 
+   { "Zip archive data",		RPMFC_COMPRESSED|RPMFC_ARCHIVE|RPMFC_INCLUDE },
+@@ -864,6 +866,8 @@
+ 	    fc->fcolor->vals[fc->ix] |= RPMFC_PHP;
+ 	else if (!strncmp(bn, "ruby", sizeof("ruby")-1))
+ 	    fc->fcolor->vals[fc->ix] |= RPMFC_RUBY;
++	else if (!strncmp(bn, "node", sizeof("node")-1) || !strncmp(bn, "nodejs", sizeof("nodejs")-1))
++	    fc->fcolor->vals[fc->ix] |= RPMFC_NODEJS;
+ 
+ 	break;
+     }
+@@ -921,6 +925,13 @@
+ #endif
+ 	    xx = rpmfcHelper(fc, 'R', "ruby");
+     } else
++    if (fc->fcolor->vals[fc->ix] & RPMFC_NODEJS) {
++	xx = rpmfcHelper(fc, 'P', "nodejs");
++#ifdef	NOTYET
++	if (is_executable)
++#endif
++	    xx = rpmfcHelper(fc, 'R', "nodejs");
++    } else
+     if ((fc->fcolor->vals[fc->ix] & RPMFC_FONT) == RPMFC_FONT) {
+        xx = rpmfcHelper(fc, 'P', "font");
+        /* XXX: currently of no use, but for the sake of consistency... */
+@@ -1081,7 +1092,7 @@
+ /*@unchecked@*/
+ static struct rpmfcApplyTbl_s rpmfcApplyTable[] = {
+     { rpmfcELF,		RPMFC_ELF },
+-    { rpmfcSCRIPT,	(RPMFC_SCRIPT|RPMFC_FONT|RPMFC_HASKELL|RPMFC_RUBY|RPMFC_PERL|RPMFC_PYTHON|RPMFC_LIBTOOL|RPMFC_PKGCONFIG|RPMFC_BOURNE|RPMFC_JAVA|RPMFC_PHP|RPMFC_MONO|RPMFC_TYPELIB|RPMFC_DESKTOP_FILE) },
++    { rpmfcSCRIPT,	(RPMFC_SCRIPT|RPMFC_FONT|RPMFC_HASKELL|RPMFC_RUBY|RPMFC_NODEJS|RPMFC_PERL|RPMFC_PYTHON|RPMFC_LIBTOOL|RPMFC_PKGCONFIG|RPMFC_BOURNE|RPMFC_JAVA|RPMFC_PHP|RPMFC_MONO|RPMFC_TYPELIB|RPMFC_DESKTOP_FILE) },
+ #if defined(RPM_VENDOR_MANDRIVA)
+     { rpmfcSYMLINK,	RPMFC_SYMLINK },
+ #endif
+@@ -1096,6 +1107,7 @@
+     char * se;
+     rpmds ds;
+     const char * fn;
++    char * bn;
+     const char * N;
+     const char * EVR;
+     evrFlags Flags;
+@@ -1152,6 +1164,12 @@
+ 		    fn += 2;
+ 		if (!strncmp(fn, "/python", sizeof("/python")-1))
+ 		    fc->fcolor->vals[fc->ix] |= RPMFC_PYTHON;
++		else if (!strncmp(fn, "/node", sizeof("/node")-1) || !strncmp(fn, "/node_modules", sizeof("/node_modules")-1)) {
++		    fc->fcolor->vals[fc->ix] |= RPMFC_NODEJS;
++		    bn = basename(fn);
++		    if (!strcmp(bn, "package.json")) {
++			fc->fcolor->vals[fc->ix] |= RPMFC_MODULE;
++		    }
+ 		else if (!strncmp(fn, "/ruby", sizeof("/ruby")-1)) {
+ 		    fc->fcolor->vals[fc->ix] |= RPMFC_RUBY;
+ 		    if ((strstr(fn, ".gemspec") || strstr(fn, "rbconfig.rb"))) {
+--- rpm-5.4.10/macros/macros.in~	2013-04-28 23:35:06.000000000 +0300
++++ rpm-5.4.10/macros/macros.in	2013-04-28 23:38:01.383900982 +0300
+@@ -1068,6 +1068,10 @@
+ %{load:%{_usrlibrpm}/macros.d/mono}
+ 
+ #------------------------------------------------------------------------
++# nodejs(...) configuration.
++%{load:%{_usrlibrpm}/macros.d/nodejs}
++
++#------------------------------------------------------------------------
+ # ruby(...) configuration.
+ %{load:%{_usrlibrpm}/macros.d/ruby}
+ 
diff --git a/nodejs.macros b/nodejs.macros
new file mode 100644
index 0000000..18bf017
--- /dev/null
+++ b/nodejs.macros
@@ -0,0 +1,12 @@
+# Node.js specific macro definitions.
+# To make use of these macros insert the following line into your spec file:
+# %{load:%{_usrlibrpm}/macros.d/nodejs}
+
+%__nodejs	/usr/bin/nodejs
+
+# Path to scripts to autogenerate Node.js package dependencies,
+#
+# Note: Used if _use_internal_dependency_generator is non-zero. The
+# helpers are also used by %{_rpmhome}/rpmdeps {--provides|--requires}.
+%__nodejs_provides	%{_rpmhome}/nodejs.prov
+%__nodejs_requires	%{_rpmhome}/nodejs.req
diff --git a/nodejs.prov b/nodejs.prov
new file mode 100755
index 0000000..7c8dac2
--- /dev/null
+++ b/nodejs.prov
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+
+"""
+Automatic provides generator for Node.js libraries.
+
+Taken from package.json.  See `man npm-json` for details.
+"""
+# Copyright 2012 T.C. Hollingsworth <tchollingsworth at gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+import json
+import sys
+
+paths = [path.rstrip() for path in sys.stdin.readlines()]
+
+for path in paths:
+    if path.endswith('package.json'):
+        fh = open(path)
+        metadata = json.load(fh)
+        fh.close()
+
+        if 'name' in metadata and not ('private' in metadata and metadata['private']):
+            print 'npm(' + metadata['name'] + ')',
+
+            if 'version' in metadata:
+                print '= ' + metadata['version']
+            else:
+                print
diff --git a/nodejs.req b/nodejs.req
new file mode 100755
index 0000000..8130276
--- /dev/null
+++ b/nodejs.req
@@ -0,0 +1,148 @@
+#!/usr/bin/python
+
+"""
+Automatic dependency generator for Node.js libraries.
+
+Parsed from package.json.  See `man npm-json` for details.
+"""
+
+# Copyright 2012 T.C. Hollingsworth <tchollingsworth at gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+from __future__ import unicode_literals
+import json
+import re
+import sys
+
+RE_VERSION = re.compile(r'\s*v?([<>=~]{0,2})\s*([0-9][0-9\.\-]*)\s*')
+
+def main():
+    #npm2rpm uses functions here to write BuildRequires so don't print anything
+    #until the very end
+    deps = []
+
+    #it's highly unlikely that we'll ever get more than one file but we handle
+    #this like all RPM automatic dependency generation scripts anyway
+    paths = [path.rstrip() for path in sys.stdin.readlines()]
+
+    for path in paths:
+        if path.endswith('package.json'):
+            fh = open(path)
+            metadata = json.load(fh)
+            fh.close()
+
+            #write out the node.js interpreter dependency
+            req = 'nodejs(engine)'
+            
+            if 'engines' in metadata and 'node' in metadata['engines']:
+                deps += process_dep(req, metadata['engines']['node'])
+            else:
+                deps.append(req)
+
+            if 'dependencies' in metadata:
+                for name, version in metadata['dependencies'].iteritems():
+                    req = 'npm(' + name + ')'
+                    deps += process_dep(req, version)
+
+    print '\n'.join(deps)
+
+def process_dep(req, version):
+    """Converts an individual npm dependency into RPM dependencies"""
+    
+    deps = []
+    
+    #there's no way RPM can do anything like an OR dependency
+    if '||' in version:
+        sys.stderr.write("WARNING: The {0} dependency contains an ".format(req) +
+            "OR (||) dependency: '{0}.\nPlease manually include ".format(version) +
+            "a versioned dependency in your spec file if necessary")
+        deps.append(req)
+            
+    elif ' - ' in version:
+        gt, lt = version.split(' - ')
+        deps.append(req + ' >= ' + gt)
+        deps.append(req + ' <= ' + lt)
+        
+    else:
+        m = re.match(RE_VERSION, version)
+
+        if m:
+            deps += convert_dep(req, m.group(1), m.group(2))
+
+            #There could be up to two versions here (e.g.">1.0 <3.1")
+            if len(version) > m.end():
+                m = re.match(RE_VERSION, version[m.end():])
+
+                if m:
+                    deps += convert_dep(req, m.group(1), m.group(2))
+        else:
+            deps.append(req)
+
+    return deps
+            
+def convert_dep(req, operator, version):
+    """Converts one of the two possibly listed versions into an RPM dependency"""
+    
+    deps = []
+
+    #any version will do
+    if not version or version == '*':
+        deps.append(req)
+
+    #any prefix but ~ makes things dead simple
+    elif operator in ['>', '<', '<=', '>=', '=']:
+        deps.append(' '.join([req, operator, version]))
+
+    #oh boy, here we go...
+    else:
+        #split the dotted portions into a list (handling trailing dots properly)
+        parts = [part if part else 'x' for part in version.split('.')]
+        parts = [int(part) if part != 'x' and not '-' in part
+                                                    else part for part in parts]
+
+        # 1 or 1.x or 1.x.x or ~1
+        if len(parts) == 1 or parts[1] == 'x':
+            if parts[0] != 0:
+                deps.append('{0} >= {1}'.format(req, parts[0]))
+            deps.append('{0} < {1}'.format(req, parts[0]+1))
+
+        # 1.2.3 or 1.2.3-4 or 1.2.x or ~1.2.3 or 1.2
+        elif len(parts) == 3 or operator != '~':
+            # 1.2.x or 1.2
+            if len(parts) == 2 or parts[2] == 'x':
+                deps.append('{0} >= {1}.{2}'.format(req, parts[0], parts[1]))
+                deps.append('{0} < {1}.{2}'.format(req, parts[0], parts[1]+1))
+            # ~1.2.3
+            elif operator == '~':
+                deps.append('{0} >= {1}'.format(req, version))
+                deps.append('{0} < {1}.{2}'.format(req, parts[0], parts[1]+1))
+            # 1.2.3 or 1.2.3-4
+            else:
+                deps.append('{0} = {1}'.format(req, version))
+
+        # ~1.2
+        else:
+            deps.append('{0} >= {1}'.format(req, version))
+            deps.append('{0} < {1}'.format(req, parts[0]+1))
+
+    return deps
+            
+if __name__ == '__main__':
+    main()
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/rpm.git/commitdiff/a6170955991f542eaf1cf303a5912538f85374ed



More information about the pld-cvs-commit mailing list