From 25fa6e040f425eafa8839399921fb4e2d72faa13 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Mon, 23 Jan 2006 04:50:40 +0000 Subject: [PATCH] Add support for architecture wildcards, but for now they will only be exposed in debian/control files, not in binary nor source packages. Closes: #291939 --- ChangeLog | 36 ++++++ debian/changelog | 3 + man/C/dpkg-architecture.1 | 19 ++- scripts/Makefile.am | 5 + scripts/Makefile.in | 5 + scripts/{controllib.pl => controllib.pl.in} | 136 ++++++++++++++++++-- scripts/dpkg-architecture.pl | 61 +++------ scripts/dpkg-genchanges.pl | 12 +- scripts/dpkg-gencontrol.pl | 9 +- scripts/dpkg-source.pl | 9 +- 10 files changed, 225 insertions(+), 70 deletions(-) rename scripts/{controllib.pl => controllib.pl.in} (80%) diff --git a/ChangeLog b/ChangeLog index d9556020..4758b0c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,39 @@ +2006-01-23 Guillem Jover + + Support for architecture wildcards. + + * scripts/controllib.pl: Rename to ... + * scripts/controllib.pl.in: ... this. + * scripts/dpkg-architecture.pl: Add new actions '-e' and '-i' that + call debian_arch_eq and debian_arch_is, to check for architecture + equality and identity respectively. Use debian_arch_fix instead of + the duplicated code. + (pkgdatadir, read_cputable, read_ostable): Move to ... + * scripts/controllib.pl.in: ... here. + (debian_arch_fix): New function. Fix normalized kernel-cpu input to + legacy Debian architecture output. + (debian_arch_split): New function. Normalize and split input into + kernel and cpu components. + (debian_arch_eq): New function. Compare two tuples for equality after + having normalized them with debian_arch_split. + (debian_arch_is): New function. Check two tuples for identity after + having normalized them with debian_arch_split. + (debian_arch_expand): New function. Expand the normalized input + into all possible legacy Debian architectures matching the wildcard. + (parsedep): Use debian_arch_is to check if the host architecture is + part of the architecture listed in the dependency relationship. + (showdep): Use debian_arch_expand to normalize the architectures for + binary and source packages, so generated packages will be backward + compatible in regard to architecture format. + * scripts/dpkg-genchanges.pl: Use new dpkg_arch_is and dpkg_arch_eq + instead of the hardcoded checks. + * scripts/dpkg-gencontrol.pl: Likewise. + * scripts/dpkg-source.pl: Likewise. Use dpkg_arch_expand to fill + the Architecture field with the legacy Debian architecures. + * scripts/Makefile.am: New rule to generate .pl from .pl.in files. + * man/C/dpkg-architecture.1: Update. Add new options, and few words + about the format of the wildcards. + 2006-01-23 Guillem Jover * scripts/dpkg-source.pl: Add a missing '+' in the architecture diff --git a/debian/changelog b/debian/changelog index 966d7eca..26e6a27c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -77,6 +77,9 @@ dpkg (1.13.12~) unstable; urgency=low transitive library. The proper fix should come with a pkg-config file. Based on a patch by Bart Martens . Closes: #347744, #348659 + * Add support for architecture wildcards, but for now they will only be + exposed in debian/control files, not in binary nor source packages. + Closes: #291939 -- diff --git a/man/C/dpkg-architecture.1 b/man/C/dpkg-architecture.1 index 9b2e0b62..12688a85 100644 --- a/man/C/dpkg-architecture.1 +++ b/man/C/dpkg-architecture.1 @@ -1,4 +1,4 @@ -.TH DPKG-ARCHITECTURE 1 "2005-01-10" "Debian GNU/Linux" +.TH DPKG-ARCHITECTURE 1 "2006-01-23" "Debian GNU/Linux" .SH "NAME" dpkg\-architecture \- set and determine the architecture for package building .SH "SYNOPSIS" @@ -11,8 +11,8 @@ Valid options: \&\fB\-f\fR .PP Valid actions: -\&\fB\-l\fR, \fB\-q\fRVariable\-Name, \fB\-s\fR, \fB\-u\fR, \fB\-c\fR Command, -\fB\-L\fR +\&\fB\-l\fR, \fB\-e\fRDebian\-Architecture, \fB\-i\fRArchitecture\-Alias, +\fB\-q\fRVariable\-Name, \fB\-s\fR, \fB\-u\fR, \fB\-c\fR Command, \fB\-L\fR .SH "DESCRIPTION" .IX Header "DESCRIPTION" dpkg-architecture does provide a facility to determine and set the build and @@ -30,8 +30,12 @@ Indeed, it is often better to only specify one, because dpkg-architecture will warn you if your choice doesn't match the default. .PP The default action is \fB\-l\fR, which prints the environment variables, one each line, -in the format VARIABLE=value. If you are only interested in the value of a -single variable, you can use \fB\-q\fR. If you specify \fB\-s\fR, it will output an export +in the format VARIABLE=value. If you want to check for equality between two +Debian Architectures, you can use \fB\-e\fR, by default it will compare against +the currect Debian Architecture, being it the host. If you want to check for +identity of the current Debian Architecture against an Architecture Alias, you +can use \fB\-i\fR. If you are only interested in the value of a single variable, +you can use \fB\-q\fR. If you specify \fB\-s\fR, it will output an export command. This can be used to set the environment variables using eval. \fB\-u\fR does return a similar command to unset all variables. \fB\-c\fR does execute a command in an environment which has all variables set to the determined @@ -55,6 +59,11 @@ The machine the package is built for. .IX Item "Debian Architecture" The Debian architecture string, which specifies the binary tree in the \s-1FTP\s0 archive. Examples: i386, sparc, hurd\-i386. +.IP "Architecture Alias" 4 +.IX Item "Architecture Alias" +An architecture alias is a wildcard architecture that will match any real +architecture being part of it. The general form is \-. +Examples: linux\-any, linux\-alpha, any\-i386, hurd\-any. .IP "\s-1GNU\s0 System Type" 4 .IX Item "GNU System Type" An architecture specification string consisting of two parts, diff --git a/scripts/Makefile.am b/scripts/Makefile.am index d900d87a..5034a735 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -70,6 +70,11 @@ do_shell_subst = sed -e "s:version=\"[^\"]*\":version=\"$(PACKAGE_VERSION)\":" $(do_perl_subst) <$< >$@ chmod +x $@ +%.pl: %.pl.in Makefile + @test -d `dirname $@` || $(mkdir_p) `dirname $@` + $(do_perl_subst) <$< >$@ + chmod +x $@ + %: %.sh Makefile @test -d `dirname $@` || $(mkdir_p) `dirname $@` $(do_shell_subst) <$< >$@ diff --git a/scripts/Makefile.in b/scripts/Makefile.in index 3ad010b4..8b175215 100644 --- a/scripts/Makefile.in +++ b/scripts/Makefile.in @@ -509,6 +509,11 @@ uninstall-am: uninstall-binSCRIPTS uninstall-changelogSCRIPTS \ $(do_perl_subst) <$< >$@ chmod +x $@ +%.pl: %.pl.in Makefile + @test -d `dirname $@` || $(mkdir_p) `dirname $@` + $(do_perl_subst) <$< >$@ + chmod +x $@ + %: %.sh Makefile @test -d `dirname $@` || $(mkdir_p) `dirname $@` $(do_shell_subst) <$< >$@ diff --git a/scripts/controllib.pl b/scripts/controllib.pl.in similarity index 80% rename from scripts/controllib.pl rename to scripts/controllib.pl.in index 5385cff8..eed73958 100755 --- a/scripts/controllib.pl +++ b/scripts/controllib.pl.in @@ -11,6 +11,8 @@ # "S key" where S is the source and key is the packagename # %substvar - map with substitution variables +$pkgdatadir="."; + $parsechangelog= 'dpkg-parsechangelog'; @pkg_dep_fields = qw(Replaces Provides Depends Pre-Depends Recommends Suggests @@ -76,6 +78,114 @@ sub findarch { $substvar{'Arch'}= $arch; } +sub read_cputable { + open CPUTABLE, "$pkgdatadir/cputable" + or &syserr("unable to open cputable"); + while () { + if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) { + $cputable{$1} = $2; + $cputable_re{$1} = $3; + push @cpu, $1; + } + } + close CPUTABLE; +} + +sub read_ostable { + open OSTABLE, "$pkgdatadir/ostable" + or &syserr("unable to open ostable"); + while () { + if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) { + $ostable{$1} = $2; + $ostable_re{$1} = $3; + push @os, $1; + } + } + close OSTABLE; +} + +sub debian_arch_fix +{ + local ($os, $cpu) = @_; + + if ($os eq "linux") { + return $cpu; + } else { + return "$os-$cpu"; + } +} + +sub debian_arch_split { + local ($_) = @_; + + if (/^([^-]*)-(.*)/) { + return ($1, $2); + } elsif (/any/ || /all/) { + return ($_, $_); + } else { + return ("linux", $_); + } +} + +sub debian_arch_eq { + my ($a, $b) = @_; + my ($a_os, $a_cpu) = debian_arch_split($a); + my ($b_os, $b_cpu) = debian_arch_split($b); + + return ("$a_os-$a_cpu" eq "$b_os-$b_cpu"); +} + +sub debian_arch_is { + my ($real, $alias) = @_; + my ($real_os, $real_cpu) = debian_arch_split($real); + my ($alias_os, $alias_cpu) = debian_arch_split($alias); + + if ("$real_os-$real_cpu" eq "$alias_os-$alias_cpu") { + return 1; + } elsif ("$alias_os-$alias_cpu" eq "any-any") { + return 1; + } elsif ("$alias_os-$alias_cpu" eq "any-$real_cpu") { + return 1; + } elsif ("$alias_os-$alias_cpu" eq "$real_os-any") { + return 1; + } + + return 0; +} + +&read_cputable; +&read_ostable; + +sub debian_arch_expand +{ + local ($_) = @_; + + /^(!)?(.*)/; + + local $not = $1 || ''; + local $arch = $2; + local ($os, $cpu) = debian_arch_split($arch); + local @list; + + if ("$os-$cpu" eq 'any-any') { + @list = 'any'; + } elsif ($os eq 'all' or $cpu eq 'all') { + @list = 'all'; + } elsif ($cpu eq 'any') { + foreach my $_cpu (@cpu) { + push @list, $not.debian_arch_fix($os, $_cpu); + } + } elsif ($os eq 'any') { + foreach my $_os (@os) { + push @list, $not.debian_arch_fix($_os, $cpu); + } + } else { + push @list, $not.debian_arch_fix($os, $cpu); + } + + return @list; +} + sub substvars { my ($v) = @_; my ($lhs,$vn,$rhs,$count); @@ -186,17 +296,21 @@ ALTERNATE: my $seen_arch=''; foreach my $arch (@arches) { $arch=lc($arch); - if ($arch eq $host_arch) { + if (debian_arch_is($host_arch, $arch)) { $seen_arch=1; next; - } elsif ($arch eq "!$host_arch") { - next ALTERNATE; - } elsif ($arch =~ /!/) { - # This is equivilant to - # having seen the current arch, - # unless the current arch - # is also listed.. - $seen_arch=1; + } elsif ($arch =~ /^!/) { + ($not_arch = $arch) =~ s/^!//; + + if (debian_arch_is($host_arch, $not_arch)) { + next ALTERNATE; + } else { + # This is equivilant to + # having seen the current arch, + # unless the current arch + # is also listed.. + $seen_arch=1; + } } } if (! $seen_arch) { @@ -221,7 +335,9 @@ sub showdep { my @or_list = (); foreach my $dep_or (@$dep_and) { my ($package, $relation, $version, $arch_list) = @$dep_or; - push @or_list, $package . ($relation && $version ? " ($relation $version)" : '') . ($show_arch && @$arch_list ? " [@$arch_list]" : ''); + my @arches = map(debian_arch_expand($_), @$arch_list); + chomp @arches; + push @or_list, $package . ($relation && $version ? " ($relation $version)" : '') . ($show_arch && @arches ? " [@arches]" : ''); } push @and_list, join(' | ', @or_list); } diff --git a/scripts/dpkg-architecture.pl b/scripts/dpkg-architecture.pl index 81f429af..13804751 100755 --- a/scripts/dpkg-architecture.pl +++ b/scripts/dpkg-architecture.pl @@ -26,8 +26,6 @@ $dpkglibdir="/usr/lib/dpkg"; push(@INC,$dpkglibdir); require 'controllib.pl'; -$pkgdatadir="."; - sub usageversion { print STDERR "Debian $0 $version. @@ -39,12 +37,14 @@ version 2 or later for copying conditions. There is NO warranty. Usage: $0 [