[ostree] Add a --version argument that also outputs features



commit 82f444020e5bd0fd3de4ab4c1445b92902069098
Author: Colin Walters <walters verbum org>
Date:   Wed May 1 19:15:06 2013 -0400

    Add a --version argument that also outputs features
    
    And use it in the tests to skip libarchive tests when the build
    doesn't support it.

 Makefile.am               |    1 +
 configure.ac              |    6 ++++++
 src/ostree/ot-main.c      |   21 +++++++++++++++++++++
 tests/t0006-libarchive.sh |    4 ++++
 4 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index e3ce06c..0ad12e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,7 @@
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 AM_CPPFLAGS = -DDATADIR='"$(datadir)"' -DLIBEXECDIR='"$(libexecdir)"' \
+       -DOSTREE_FEATURES='"$(OSTREE_FEATURES)"' \
        -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_34 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_34 \
        -DSOUP_VERSION_MIN_REQUIRED=SOUP_VERSION_2_40 -DSOUP_VERSION_MAX_ALLOWED=SOUP_VERSION_40
 AM_CFLAGS = $(WARN_CFLAGS)
diff --git a/configure.ac b/configure.ac
index d95f5d8..8acf7da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,9 @@ AC_SUBST(WARN_CFLAGS)
 LT_PREREQ([2.2.4])
 LT_INIT([disable-static])
 
+OSTREE_FEATURES=""
+AC_SUBST([OSTREE_FEATURES])
+
 AC_ARG_ENABLE(triggers-only,
            AS_HELP_STRING([--enable-triggers-only], [Only build and install triggers]),,
            enable_triggers_only=no)
@@ -70,12 +73,14 @@ AS_IF([test x$enable_embedded_dependencies = xyes], [
     ])
     AS_IF([test x$have_soup = xyes], [
        PKG_CHECK_MODULES(OT_DEP_SOUP, $SOUP_DEPENDENCY)
+        AC_DEFINE(HAVE_LIBSOUP, 1, [Define if we have libsoup.pc])
        with_soup=yes
     ], [
        with_soup=no
     ])
   ], [ with_soup=no ])
 ])
+if test x$with_soup != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libsoup"; fi
 AM_CONDITIONAL(USE_LIBSOUP, test x$with_soup != xno)
 
 LIBARCHIVE_DEPENDENCY="libarchive >= 2.8.0"
@@ -117,6 +122,7 @@ AS_IF([ test x$with_libarchive != xno ], [
        with_libarchive=no
     ])
 ], [ with_libarchive=no ])
+if test x$with_libarchive != xno; then OSTREE_FEATURES="$OSTREE_FEATURES +libarchive"; fi
 AM_CONDITIONAL(USE_LIBARCHIVE, test $with_libarchive != no)
 
 AS_IF([test x$cross_compiling != xyes && test -d /etc/kernel && test x$enable_triggers_only != xyes ],
diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c
index 7e9699e..43fda01 100644
--- a/src/ostree/ot-main.c
+++ b/src/ostree/ot-main.c
@@ -29,6 +29,13 @@
 #include "ot-main.h"
 #include "otutil.h"
 
+static gboolean opt_version;
+
+static GOptionEntry main_options[] = {
+  { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Display version", NULL },
+  { NULL }
+};
+
 int
 ostree_usage (char **argv,
               OstreeCommand *commands,
@@ -80,6 +87,7 @@ ostree_run (int    argc,
             OstreeCommand *commands,
             GError **res_error)
 {
+  GOptionContext *optcontext;
   OstreeCommand *command;
   GError *error = NULL;
   int cmd_argc;
@@ -104,6 +112,19 @@ ostree_run (int    argc,
   if (argc < 2)
     return ostree_usage (argv, commands, TRUE);
 
+  optcontext = g_option_context_new ("COMMAND [OPTIONS...]");
+  g_option_context_add_main_entries (optcontext, main_options, NULL);
+  g_option_context_set_ignore_unknown_options (optcontext, TRUE);
+
+  if (!g_option_context_parse (optcontext, &argc, &argv, &error))
+    goto out;
+
+  if (opt_version)
+    {
+      g_print ("%s\n  %s\n", PACKAGE_STRING, OSTREE_FEATURES);
+      return 0;
+    }
+
   have_repo_arg = g_str_has_prefix (argv[1], "--repo=");
 
   if (have_repo_arg)
diff --git a/tests/t0006-libarchive.sh b/tests/t0006-libarchive.sh
index 4936389..38c9aff 100755
--- a/tests/t0006-libarchive.sh
+++ b/tests/t0006-libarchive.sh
@@ -19,6 +19,10 @@
 
 set -e
 
+if ! ostree --version | grep -q -e '\+libarchive'; then
+    exit 77
+fi
+
 echo "1..7"
 
 . $(dirname $0)/libtest.sh


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