Browse Source

dpkg-deb, scripts: Make the Architecture field mandatory on package builds

We still accept source and binary packages with missing or empty
Architecture fields, but when building either of these, we require
the field to be present.
Guillem Jover 10 years ago
parent
commit
09300f0f87
5 changed files with 13 additions and 17 deletions
  1. 1 0
      debian/changelog
  2. 5 10
      dpkg-deb/build.c
  3. 2 2
      scripts/Dpkg/Source/Package.pm
  4. 1 1
      scripts/dpkg-genchanges.pl
  5. 4 4
      scripts/dpkg-gencontrol.pl

+ 1 - 0
debian/changelog

@@ -50,6 +50,7 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
     is very simple, and a simple hand-written parser is smaller and avoids a
     build dependency.
   * Be more strict when parsing the COLUMNS environment variable in dpkg-query.
+  * Make the Architecture field mandatory on package builds.
   * Portability:
     - Move DPKG_ADMINDIR environment variable name out from update-alternatives
       code, to make life easier for non-dpkg-based systems.

+ 5 - 10
dpkg-deb/build.c

@@ -325,6 +325,9 @@ check_control_file(const char *ctrldir)
   if (strspn(pkg->set->name, "abcdefghijklmnopqrstuvwxyz0123456789+-.") !=
       strlen(pkg->set->name))
     ohshit(_("package name has characters that aren't lowercase alphanums or '-+.'"));
+  if (pkg->available.arch->type == DPKG_ARCH_NONE ||
+      pkg->available.arch->type == DPKG_ARCH_EMPTY)
+    ohshit(_("package architecture is missing or empty"));
   if (pkg->priority == PKG_PRIO_OTHER)
     warning(_("'%s' contains user-defined Priority value '%s'"),
             controlfile, pkg->otherpriority);
@@ -405,17 +408,9 @@ gen_dest_pathname(const char *dir, const char *dest)
 static char *
 gen_dest_pathname_from_pkg(const char *dir, struct pkginfo *pkg)
 {
-  const char *arch_sep;
-
-  if (pkg->available.arch->type == DPKG_ARCH_NONE ||
-      pkg->available.arch->type == DPKG_ARCH_EMPTY)
-    arch_sep = "";
-  else
-    arch_sep = "_";
-
-  return str_fmt("%s/%s_%s%s%s%s", dir, pkg->set->name,
+  return str_fmt("%s/%s_%s_%s%s", dir, pkg->set->name,
                  versiondescribe(&pkg->available.version, vdew_never),
-                 arch_sep, pkg->available.arch->name, DEBEXT);
+                 pkg->available.arch->name, DEBEXT);
 }
 
 typedef void filenames_feed_func(const char *dir, int fd_out);

+ 2 - 2
scripts/Dpkg/Source/Package.pm

@@ -609,12 +609,12 @@ sub write_dsc {
     }
 
     unless ($opts{nocheck}) {
-        foreach my $f (qw(Source Version)) {
+        foreach my $f (qw(Source Version Architecture)) {
             unless (defined($fields->{$f})) {
                 error(g_('missing information for critical output field %s'), $f);
             }
         }
-        foreach my $f (qw(Maintainer Architecture Standards-Version)) {
+        foreach my $f (qw(Maintainer Standards-Version)) {
             unless (defined($fields->{$f})) {
                 warning(g_('missing information for output field %s'), $f);
             }

+ 1 - 1
scripts/dpkg-genchanges.pl

@@ -310,7 +310,7 @@ if (build_has(BUILD_BINARY)) {
 # Scan control info of all binary packages
 foreach my $pkg ($control->get_packages()) {
     my $p = $pkg->{'Package'};
-    my $a = $pkg->{'Architecture'} // '';
+    my $a = $pkg->{'Architecture'};
     my $bp = $pkg->{'Build-Profiles'};
     my $d = $pkg->{'Description'} || 'no description available';
     $d = $1 if $d =~ /^(.*)\n/;

+ 4 - 4
scripts/dpkg-gencontrol.pl

@@ -305,11 +305,11 @@ foreach my $field (field_list_pkg_dep()) {
 
 $fields->{'Built-For-Profiles'} = join ' ', get_build_profiles();
 
-for my $f (qw(Package Version)) {
+for my $f (qw(Package Version Architecture)) {
     error(g_('missing information for output field %s'), $f)
         unless defined $fields->{$f};
 }
-for my $f (qw(Maintainer Description Architecture)) {
+for my $f (qw(Maintainer Description)) {
     warning(g_('missing information for output field %s'), $f)
         unless defined $fields->{$f};
 }
@@ -374,7 +374,7 @@ for my $f (keys %remove) {
 my $sversion = $fields->{'Version'};
 $sversion =~ s/^\d+://;
 $forcefilename //= sprintf('%s_%s_%s.%s', $fields->{'Package'}, $sversion,
-                           $fields->{'Architecture'} || '', $pkg_type);
+                           $fields->{'Architecture'}, $pkg_type);
 $forcefilename = $substvars->substvars($forcefilename);
 my $section = $substvars->substvars($fields->{'Section'} || '-');
 my $priority = $substvars->substvars($fields->{'Priority'} || '-');
@@ -396,7 +396,7 @@ foreach my $file ($dist->get_files()) {
     if (defined $file->{package} &&
         ($file->{package} eq $fields->{'Package'}) &&
         ($file->{package_type} eq $pkg_type) &&
-        (debarch_eq($file->{arch}, $fields->{'Architecture'} || '') ||
+        (debarch_eq($file->{arch}, $fields->{'Architecture'}) ||
          debarch_eq($file->{arch}, 'all'))) {
         $dist->del_file($file->{filename});
     }