Przeglądaj źródła

dpkg: Add --foreign-architecture and --print-foreign-architectures options

Two new options to dpkg, needed for multiarch:

* --foreign-architecture lets you specify that packages for the
  named architecture should be installable without the use of
  --force-architecture.

* --print-foreign-architectures prints out a space-separated list of all
  architectures so configured, so that front-ends can query the list.

Sponsored-by: Linaro Limited

[guillem@debian.org:
 - Move dpkg option to the correct section in the man page.
 - Add --help output for both options.
 - Handle arch_foreign and arch_unknown separately in set_foreign_arch().
 - Be consistent with naming of arch plural with the rest of the code.
 - Rename act_foreignarches to act_printforeignarches. ]

Based-on-patch-by: Steve Langasek <steve.langasek@canonical.com>
Signed-off-by: Guillem Jover <guillem@debian.org>
Raphaël Hertzog 17 lat temu
rodzic
commit
dc6ae081c2
4 zmienionych plików z 59 dodań i 0 usunięć
  1. 10 0
      man/dpkg.1
  2. 23 0
      src/enquiry.c
  3. 24 0
      src/main.c
  4. 2 0
      src/main.h

+ 10 - 0
man/dpkg.1

@@ -235,6 +235,10 @@ reason still haven't been installed.
 .B \-\-print\-architecture
 Print architecture of packages \fBdpkg\fP installs (for example, "i386").
 .TP
+.B \-\-print\-foreign\-architectures
+Print a space-separated list of the extra architectures \fBdpkg\fP is
+configured to allow packages to be installed for.
+.TP
 .B \-\-compare\-versions \fIver1 op ver2\fP
 Compare version numbers, where \fIop\fP is a binary operator. \fBdpkg\fP
 returns success (zero result) if the specified condition is satisfied,
@@ -568,6 +572,12 @@ each other. Both are processed in the given order, with the last rule that
 matches a file name making the decision.
 .RE
 .TP
+.B \-\-foreign\-architecture \fIarchitecture\fP
+Add \fIarchitecture\fP to the list of architectures for which packages can
+be installed without using \fB\-\-force\-architecture\fP, in addition to
+the architecture \fBdpkg\fP is built for (i.e.: the output of
+\fB\-\-print\-architecture\fP).
+.TP
 \fB\-\-status\-fd \fR\fIn\fR
 Send machine-readable package status and progress information to file
 descriptor \fIn\fP. This option can be specified multiple times. The

+ 23 - 0
src/enquiry.c

@@ -39,6 +39,7 @@
 #include <dpkg/i18n.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
+#include <dpkg/arch.h>
 #include <dpkg/pkg-show.h>
 #include <dpkg/options.h>
 
@@ -474,6 +475,28 @@ printinstarch(const char *const *argv)
   return printarch(argv);
 }
 
+int
+print_foreign_arches(const char *const *argv)
+{
+  struct dpkg_arch *arch;
+  const char *sep = "";
+
+  if (*argv)
+    badusage(_("--%s takes no arguments"), cipaction->olong);
+
+  for (arch = dpkg_arch_get_list(); arch; arch = arch->next) {
+    if (arch->type != arch_foreign)
+      continue;
+    printf("%s%s", sep, arch->name);
+    sep = " ";
+  }
+  printf("\n");
+
+  m_output(stdout, _("<standard output>"));
+
+  return 0;
+}
+
 int
 cmpversions(const char *const *argv)
 {

+ 24 - 0
src/main.c

@@ -46,6 +46,7 @@
 #include <dpkg/i18n.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
+#include <dpkg/arch.h>
 #include <dpkg/subproc.h>
 #include <dpkg/command.h>
 #include <dpkg/options.h>
@@ -104,6 +105,7 @@ usage(const struct cmdinfo *ci, const char *value)
 "  -S|--search <pattern> ...        Find package(s) owning file(s).\n"
 "  -C|--audit                       Check for broken package(s).\n"
 "  --print-architecture             Print dpkg architecture.\n"
+"  --print-foreign-architectures    Print allowed foreign architectures.\n"
 "  --compare-versions <a> <op> <b>  Compare version numbers - see below.\n"
 "  --force-help                     Show help on forcing.\n"
 "  -Dh|--debug=help                 Show help on debugging.\n"
@@ -131,6 +133,8 @@ usage(const struct cmdinfo *ci, const char *value)
 "  --instdir=<directory>      Change installation dir without changing admin dir.\n"
 "  --path-exclude=<pattern>   Do not install paths which match a shell pattern.\n"
 "  --path-include=<pattern>   Re-include a pattern after a previous exclusion.\n"
+"  --foreign-architecture=<arch>\n"
+"                             Add <arch> to the list of foreign architectures.\n"
 "  -O|--selected-only         Skip packages not selected for install/upgrade.\n"
 "  -E|--skip-same-version     Skip packages whose same version is installed.\n"
 "  -G|--refuse-downgrade      Skip packages with earlier version than installed.\n"
@@ -469,6 +473,24 @@ run_status_loggers(struct invoke_hook *hook_head)
   }
 }
 
+static void
+set_foreign_arch(const struct cmdinfo *cip, const char *value)
+{
+  struct dpkg_arch *arch;
+
+  arch = dpkg_arch_find(value);
+  if (arch->type == arch_foreign)
+    return;
+  else if (arch->type == arch_unknown)
+    arch->type = arch_foreign;
+  else if (arch->type == arch_illegal)
+    warning(_("ignoring option --%s=%s: %s"), cip->olong, value,
+            dpkg_arch_name_is_illegal(value));
+  else
+    warning(_("ignoring option --%s=%s: %s"), cip->olong, value,
+            _("this architecture cannot be foreign"));
+}
+
 static void setforce(const struct cmdinfo *cip, const char *value) {
   const char *comma;
   size_t l;
@@ -554,6 +576,7 @@ static const struct cmdinfo cmdinfos[]= {
   ACTION( "assert-multi-conrep",             0,  act_assertmulticonrep,    assertmulticonrep ),
   ACTION( "print-architecture",              0,  act_printarch,            printarch   ),
   ACTION( "print-installation-architecture", 0,  act_printinstarch,        printinstarch  ),
+  ACTION( "print-foreign-architectures",     0,  act_printforeignarches,   print_foreign_arches ),
   ACTION( "predep-package",                  0,  act_predeppackage,        predeppackage   ),
   ACTION( "compare-versions",                0,  act_cmpversions,          cmpversions     ),
 /*
@@ -564,6 +587,7 @@ static const struct cmdinfo cmdinfos[]= {
   { "post-invoke",       0,   1, NULL,          NULL,      set_invoke_hook, 0, &post_invoke_hooks_tail },
   { "path-exclude",      0,   1, NULL,          NULL,      setfilter,     0 },
   { "path-include",      0,   1, NULL,          NULL,      setfilter,     1 },
+  { "foreign-architecture", 0, 1, NULL,         NULL,      set_foreign_arch, 0 },
   { "status-logger",     0,   1, NULL,          NULL,      set_invoke_hook, 0, &status_loggers_tail },
   { "status-fd",         0,   1, NULL,          NULL,      setpipe, 0 },
   { "log",               0,   1, NULL,          &log_file, NULL,    0 },

+ 2 - 0
src/main.h

@@ -80,6 +80,7 @@ enum action {
 
 	act_printarch,
 	act_printinstarch,
+	act_printforeignarches,
 
 	act_assertpredep,
 	act_assertepoch,
@@ -169,6 +170,7 @@ int assertmulticonrep(const char *const *argv);
 int predeppackage(const char *const *argv);
 int printarch(const char *const *argv);
 int printinstarch(const char *const *argv);
+int print_foreign_arches(const char *const *argv);
 int cmpversions(const char *const *argv);
 
 /* from select.c */