[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#268377: Bug#291939: Support for arch aliases (Was: Split System/Cpu for architecture handling)



Hi,

I've been thinking on implementing this for a long time. As
Robert has presented an implementation to the Architecture
handling problem that does not convince me at all, so instead
of just sitting here and criticize his design I've coded mine.

The idea is to introduce architecture aliases, they will only take
effect on the source package and will get expanded when building
the binary package so there's not need to touch major infrastructure
to support this, also they respect current syntax. They can be used
on Build-Depends and friends and on Architecture fields on specific
packages.

The aliases are of the form:

  Alias         Example         Expansion

  <kernel>-any  hurd-any        hurd-i386
                linux-any       i386 powerpc alpha arm ...
  any-<cpu>     any-i386        hurd-i386 kfreebsd-i386 i386 ...

There are two other cases just for consistency:

  linux-<cpu>   linux-i386      i386
                any-any         any

I've a added as well a new option (-n normalize) to dpkg-architecture
so Maintainers can use it to get the alias expansions. Try it to see
the results.

regards,
guillem
Package: dpkg
Version: 1.10.26
Author: Guillem Jover <guillem@debian.org>
Status: not-applied
Description:
 Implement Debian architecture alias support, and normalization via the new
 dpkg-architecture -n option.
 .
 Will take a virtual arch like <kernel>-any or any-<cpu> and expand to all
 available arches. And will also normalize linux-<cpu> to <cpu> for
 consistency.

diff -Naur dpkg-1.10.26/scripts/controllib.pl dpkg-1.10.26.alias/scripts/controllib.pl
--- dpkg-1.10.26/scripts/controllib.pl	2005-01-11 17:55:11.000000000 +0100
+++ dpkg-1.10.26.alias/scripts/controllib.pl	2005-01-24 09:21:44.000000000 +0100
@@ -79,6 +79,14 @@
     $substvar{'Arch'}= $arch;
 }
 
+sub normalize_archlist {
+    my ($archstr) = @_;
+    my @archlist = map(split(/\s+/, `dpkg-architecture -n$_`),
+                       split(/\s+/, $archstr));
+    chomp @archlist;
+    return @archlist;
+}
+
 sub substvars {
     my ($v) = @_;
     my ($lhs,$vn,$rhs,$count);
@@ -181,7 +189,7 @@
             my ($package, $relation, $version);
             $package = $1 if ($dep_or =~ s/^([a-zA-Z0-9][a-zA-Z0-9+._-]*)\s*//m);
             ($relation, $version) = ($1, $2) if ($dep_or =~ s/^\((=|<=|>=|<<?|>>?)\s*([^)]+).*\)\s*//m);
-            my @arches = split(/\s+/m, $1) if ($use_arch && $dep_or =~ s/^\[([^]]+)\]\s*//m);
+            my @arches = normalize_archlist($1) if ($use_arch && $dep_or =~ s/^\[([^]]+)\]\s*//m);
             if ($reduce_arch && @arches) {
 
                 my $seen_arch='';
diff -Naur dpkg-1.10.26/scripts/dpkg-architecture.pl dpkg-1.10.26.alias/scripts/dpkg-architecture.pl
--- dpkg-1.10.26/scripts/dpkg-architecture.pl	2005-01-11 17:55:11.000000000 +0100
+++ dpkg-1.10.26.alias/scripts/dpkg-architecture.pl	2005-01-24 09:06:45.000000000 +0100
@@ -92,6 +92,7 @@
        -s                 print command to set environment variables
        -u                 print command to unset environment variables
        -c <command>       set environment and run the command in it.
+       -n<debian-arch>    normalize Debian architecture
 
 Known Debian Architectures are ".join(", ",keys %archtable)."
 Known GNU System Types are ".join(", ",map ($archtable{$_},keys %archtable))."
@@ -122,6 +123,39 @@
 	return @list;
 }
 
+sub debian_arch_linux_normalize
+{
+  local ($_) = @_;
+  $_ = "linux-$_" if !/-/;
+  return $_;
+}
+
+sub debian_arch_normalize
+{
+  my ($arch) = @_;
+  my @list;
+
+  if ($arch =~ /^any(-any)?$/) {
+    @list = keys %archtable;
+  } elsif ($arch =~ /^any-(.*)/) {
+    my $cpu = $1;
+    foreach my $a (keys %archtable) {
+      push @list, $a if debian_arch_linux_normalize($a) =~ /-$cpu$/;
+    }
+  } elsif ($arch =~ /(.*)-any$/) {
+    my $system = $1;
+    foreach my $a (keys %archtable) {
+      push @list, $a if debian_arch_linux_normalize($a) =~ /^$system-/;
+    }
+  } else {
+    $arch =~ s/^linux-//;
+    push @list, $arch;
+  }
+
+  return @list;
+}
+
+
 # Set default values:
 
 $deb_build_arch = `dpkg --print-installation-architecture`;
@@ -169,6 +203,7 @@
 
 $req_host_arch = '';
 $req_host_gnu_type = '';
+$req_normalize_arch = '';
 $action='l';
 $force=0;
 
@@ -178,6 +213,9 @@
 	$req_host_arch = $';
     } elsif (m/^-t/) {
 	$req_host_gnu_type = &rewrite_gnu($');
+    } elsif (m/^-n/) {
+	$req_normalize_arch = $';
+	$action = 'n';
     } elsif (m/^-[lsu]$/) {
 	$action = $_;
 	$action =~ s/^-//;
@@ -270,6 +308,9 @@
     } else {
         die "$req_variable_to_print is not a supported variable name";
     }
+} elsif ($action eq 'n') {
+  @arch_list = debian_arch_normalize($req_normalize_arch);
+  print "@arch_list\n";
 }
 
 __END__
diff -Naur dpkg-1.10.26/scripts/dpkg-gencontrol.pl dpkg-1.10.26.alias/scripts/dpkg-gencontrol.pl
--- dpkg-1.10.26/scripts/dpkg-gencontrol.pl	2005-01-11 17:55:11.000000000 +0100
+++ dpkg-1.10.26.alias/scripts/dpkg-gencontrol.pl	2005-01-24 09:02:47.000000000 +0100
@@ -138,7 +138,7 @@
             } elsif ($v eq 'any') {
                 $f{$_}= $arch;
             } else {
-                @archlist= split(/\s+/,$v);
+                @archlist= normalize_archlist($v);
                 grep($arch eq $_, @archlist) ||
                     &error("current build architecture $arch does not".
                            " appear in package's list (@archlist)");
diff -Naur dpkg-1.10.26/scripts/dpkg-source.pl dpkg-1.10.26.alias/scripts/dpkg-source.pl
--- dpkg-1.10.26/scripts/dpkg-source.pl	2005-01-11 17:55:11.000000000 +0100
+++ dpkg-1.10.26.alias/scripts/dpkg-source.pl	2005-01-24 09:03:40.000000000 +0100
@@ -175,7 +175,7 @@
 		    if (grep($sourcearch[0] eq $_, 'any','all'))  {
 			@sourcearch= ('any');
 		    } else {
-                        for $a (split(/\s+/,$v)) {
+                        for $a (normalize_archlist($v)) {
                             &error("architecture $a only allowed on its own".
                                    " (list for package $p is \`$a')")
                                    if grep($a eq $_, 'any','all');

Reply to: