debmaker, py2ips: make optional dependencies (Suggests in terms of Debian)
authorIgor Pashev <igor.pashev@nexenta.com>
Wed, 26 Oct 2011 19:04:45 +0400
changeset 469 d39d97f5335c
parent 468 ba6c4262c8df
child 470 c5031b1e4d64
debmaker, py2ips: make optional dependencies (Suggests in terms of Debian)
tools/debmaker.pl
tools/py2ips.pl
--- a/tools/debmaker.pl	Wed Oct 26 16:51:40 2011 +0400
+++ b/tools/debmaker.pl	Wed Oct 26 19:04:45 2011 +0400
@@ -518,6 +518,7 @@
     my @depends = ();
     my @predepends = ();
     my @recommends = ();
+    my @suggests = ();
     my @conflicts = ();
     blab "Getting dependencies ...";
     foreach my $dep (@{$$manifest_data{'depend'}}) {
@@ -526,7 +527,7 @@
             blab "Dependency: $dep_pkg ($$dep{'type'})";
             push @depends,    $dep_pkg if $$dep{'type'} eq 'require';
             push @predepends, $dep_pkg if $$dep{'type'} eq 'origin';
-            # push @recommends, $dep_pkg if $$dep{'type'} eq 'optional';
+            push @suggests,   $dep_pkg if $$dep{'type'} eq 'optional';
             push @conflicts,  $dep_pkg if $$dep{'type'} eq 'exclude';
         }
     }
@@ -537,6 +538,7 @@
     uniq \@provides;
     uniq \@predepends;
     uniq \@recommends;
+    uniq \@suggests;
     uniq \@conflicts;
     # When a program and a library are in the same package:
     @depends = grep {$_ ne $debname} @depends;
@@ -558,12 +560,14 @@
     $control .= wrap(' ', ' ', $$manifest_data{'pkg.description'}) . "\n"
         if exists $$manifest_data{'pkg.description'};
 
-    $control .= 'Provides: ' . join(', ', @provides) . "\n" if @provides;
-    $control .= 'Depends: ' . join(', ', @depends) . "\n" if @depends;
+    $control .= 'Provides: '    . join(', ', @provides)   . "\n" if @provides;
+    $control .= 'Depends: '     . join(', ', @depends)    . "\n" if @depends;
     $control .= 'Pre-Depends: ' . join(', ', @predepends) . "\n" if @predepends;
-    $control .= 'Recommends: ' . join(', ', @recommends) . "\n" if @recommends;
-    $control .= 'Conflicts: ' . join(', ', @conflicts) . "\n" if @conflicts;
-    $control .= 'Replaces: ' . join(', ', @replaces) . "\n" if @replaces;
+    $control .= 'Recommends: '  . join(', ', @recommends) . "\n" if @recommends;
+    $control .= 'Suggests: '    . join(', ', @suggests)   . "\n" if @suggests;
+    $control .= 'Conflicts: '   . join(', ', @conflicts)  . "\n" if @conflicts;
+    $control .= 'Replaces: '    . join(', ', @replaces)   . "\n" if @replaces;
+
     $control .= "Installed-Size: $installed_size\n";
 
     $control .= "Origin: $$manifest_data{'info.upstream_url'}\n"
--- a/tools/py2ips.pl	Wed Oct 26 16:51:40 2011 +0400
+++ b/tools/py2ips.pl	Wed Oct 26 19:04:45 2011 +0400
@@ -139,23 +139,27 @@
     my_chdir '../__srcdir__';
     shell_exec 'python setup.py install --root=../__destdir__ --prefix=/usr';
 
-    # FIXME: versions (kid >= 0.9.6)
-    my @pkg_deps = ();
+    my %pkg_deps = ();
     if ( -f "$pkg_name.egg-info/requires.txt") {
-        @pkg_deps =
-         map { s/^([-\w]+).*/$1/; lc $_ }
-         grep { /^\w/ }
-         @{get_output "cat $pkg_name.egg-info/requires.txt"}
+        my $type = 'require'; # All deps before the first section ([...])
+                               # are mandatory; others are optional
+        foreach (@{get_output "cat $pkg_name.egg-info/requires.txt"}) {
+            $type = 'optional' if /^\[.+\]/;
+            next unless /^\w/;
+            s/^([-.\w]+).*/$1/;
+            my $pkg = lc;
+            $pkg = 'distribute' if $pkg eq 'setuptools';
+            if (! exists $pkg_deps{$pkg}) {
+                $pkg_deps{$pkg} = $type;
+            } else {
+                warning "Dependency on `$pkg' already set to $pkg_deps{$pkg}"
+                    if $pkg_deps{$pkg} ne $type
+            }
+        }
     }
-    uniq \@pkg_deps;
-    if (grep {$_ eq 'setuptools'} @pkg_deps) {
-        @pkg_deps = map {$_ eq 'setuptools' ? 'distribute' : $_} @pkg_deps;
-        warning "Dependencies: 'setuptools' replaced with 'distribute'"
-    }
-    blab 'Dependencies: ', (join ', ', @pkg_deps);
 
     my $pkg_summary = '';
-    for my $dir ( ("$pkg_name.egg-info", '.') ) {
+    for my $dir ( ("lib/$pkg_name.egg-info", "$pkg_name.egg-info", '.') ) {
         if ( -f "$dir/PKG-INFO") {
            $pkg_summary = get_output_line "grep Summary: $dir/PKG-INFO | sed 's/Summary: *//'";
            last;
@@ -173,8 +177,8 @@
     $ips_manifest .= "\n";
 
     $ips_manifest .= "depend fmri=pkg:/runtime/python-$pyversion type=require\n";
-    $ips_manifest .= "depend fmri=pkg:/library/python-2/${_}-$pyversion type=require\n"
-        foreach @pkg_deps;
+    $ips_manifest .= "depend fmri=pkg:/library/python-2/${_}-$pyversion type=$pkg_deps{$_}\n"
+        foreach keys %pkg_deps;
 
     $ips_manifest .= "\n";