unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [Patch v5 03/11] lib/cli: add library API / CLI for compile time options
Date: Fri, 13 May 2016 07:38:05 -0300	[thread overview]
Message-ID: <1463135893-7471-4-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1463135893-7471-1-git-send-email-david@tethera.net>

This is intentionally low tech; if we have more than two options it may
make sense to build up what infrastructure is provided.
---
 doc/man1/notmuch-config.rst |  5 +++++
 lib/Makefile.local          |  1 +
 lib/built-with.c            | 34 ++++++++++++++++++++++++++++++++++
 lib/notmuch.h               |  5 +++++
 notmuch-config.c            | 23 +++++++++++++++++++++++
 test/T030-config.sh         |  6 ++++--
 test/T040-setup.sh          |  6 ++++--
 test/test-lib.sh            |  6 ++++++
 8 files changed, 82 insertions(+), 4 deletions(-)
 create mode 100644 lib/built-with.c

diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index 40c1272..26a8eb1 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -132,6 +132,11 @@ The available configuration items are described below.
     
         Default: ``gpg``.
 
+    **built_with.<name>**
+
+	Compile time feature <name>. Current possibilities include
+	"compact" (see **notmuch-compact(1)**)
+	and "field_processor" (see **notmuch-search-terms(7)**).
 
 ENVIRONMENT
 ===========
diff --git a/lib/Makefile.local b/lib/Makefile.local
index 3a07090..36c3924 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -39,6 +39,7 @@ libnotmuch_c_srcs =		\
 	$(dir)/message-file.c	\
 	$(dir)/messages.c	\
 	$(dir)/sha1.c		\
+	$(dir)/built-with.c	\
 	$(dir)/tags.c
 
 libnotmuch_cxx_srcs =		\
diff --git a/lib/built-with.c b/lib/built-with.c
new file mode 100644
index 0000000..7ea1d7f
--- /dev/null
+++ b/lib/built-with.c
@@ -0,0 +1,34 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright © 2016 David Bremner
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ * Author: David Bremner <david@tethera.net>
+ */
+
+#include "notmuch.h"
+#include "notmuch-private.h"
+
+notmuch_bool_t
+notmuch_built_with (const char *name)
+{
+    if (STRNCMP_LITERAL (name, "compact") == 0) {
+	return HAVE_XAPIAN_COMPACT;
+    } else if (STRNCMP_LITERAL (name, "field_processor") == 0) {
+	return HAVE_XAPIAN_FIELD_PROCESSOR;
+    } else {
+	return FALSE;
+    }
+}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index cb46fc0..3a092ef 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1838,6 +1838,11 @@ notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);
 void
 notmuch_filenames_destroy (notmuch_filenames_t *filenames);
 
+/**
+ * interrogate the library for compile time features
+ */
+notmuch_bool_t
+notmuch_built_with (const char *name);
 /* @} */
 
 NOTMUCH_END_DECLS
diff --git a/notmuch-config.c b/notmuch-config.c
index d252bb2..01bb185 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -750,6 +750,8 @@ _item_split (char *item, char **group, char **key)
     return 0;
 }
 
+#define BUILT_WITH_PREFIX "built_with."
+
 static int
 notmuch_config_command_get (notmuch_config_t *config, char *item)
 {
@@ -773,6 +775,9 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)
 	tags = notmuch_config_get_new_tags (config, &length);
 	for (i = 0; i < length; i++)
 	    printf ("%s\n", tags[i]);
+    } else if (STRNCMP_LITERAL (item, BUILT_WITH_PREFIX) == 0) {
+	printf ("%s\n",
+		notmuch_built_with (item + strlen (BUILT_WITH_PREFIX)) ? "true" : "false");
     } else {
 	char **value;
 	size_t i, length;
@@ -804,6 +809,11 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char
 {
     char *group, *key;
 
+    if (STRNCMP_LITERAL (item, BUILT_WITH_PREFIX) == 0) {
+	fprintf (stderr, "Error: read only option: %s\n", item);
+	return 1;
+    }
+
     if (_item_split (item, &group, &key))
 	return 1;
 
@@ -830,6 +840,18 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char
     return notmuch_config_save (config);
 }
 
+static
+void
+_notmuch_config_list_built_with ()
+{
+    printf("%scompact=%s\n",
+	   BUILT_WITH_PREFIX,
+	   notmuch_built_with ("compact") ? "true" : "false");
+    printf("%sfield_processor=%s\n",
+	   BUILT_WITH_PREFIX,
+	   notmuch_built_with ("field_processor") ? "true" : "false");
+}
+
 static int
 notmuch_config_command_list (notmuch_config_t *config)
 {
@@ -865,6 +887,7 @@ notmuch_config_command_list (notmuch_config_t *config)
 
     g_strfreev (groups);
 
+    _notmuch_config_list_built_with ();
     return 0;
 }
 
diff --git a/test/T030-config.sh b/test/T030-config.sh
index f404908..437269f 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -44,7 +44,7 @@ test_expect_equal "$(notmuch config get foo.nonexistent)" ""
 
 test_begin_subtest "List all items"
 notmuch config set database.path "/canonical/path"
-output=$(notmuch config list)
+output=$(notmuch config list | notmuch_built_with_sanitize)
 test_expect_equal "$output" "\
 database.path=/canonical/path
 user.name=Notmuch Test Suite
@@ -56,7 +56,9 @@ search.exclude_tags=
 maildir.synchronize_flags=true
 crypto.gpg_path=gpg
 foo.string=this is another string value
-foo.list=this;is another;list value;"
+foo.list=this;is another;list value;
+built_with.compact=something
+built_with.field_processor=something"
 
 test_begin_subtest "Top level --config=FILE option"
 cp "${NOTMUCH_CONFIG}" alt-config
diff --git a/test/T040-setup.sh b/test/T040-setup.sh
index cf0c00b..be2f0db 100755
--- a/test/T040-setup.sh
+++ b/test/T040-setup.sh
@@ -19,7 +19,7 @@ another.suite@example.com
 foo bar
 baz
 EOF
-output=$(notmuch --config=new-notmuch-config config list)
+output=$(notmuch --config=new-notmuch-config config list | notmuch_built_with_sanitize)
 test_expect_equal "$output" "\
 database.path=/path/to/maildir
 user.name=Test Suite
@@ -29,6 +29,8 @@ new.tags=foo;bar;
 new.ignore=
 search.exclude_tags=baz;
 maildir.synchronize_flags=true
-crypto.gpg_path=gpg"
+crypto.gpg_path=gpg
+built_with.compact=something
+built_with.field_processor=something"
 
 test_done
diff --git a/test/test-lib.sh b/test/test-lib.sh
index ac04b15..09f8731 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -733,6 +733,12 @@ notmuch_uuid_sanitize ()
 {
     sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'
 }
+
+notmuch_built_with_sanitize ()
+{
+    sed 's/^built_with[.]\(.*\)=.*$/built_with.\1=something/'
+}
+
 # End of notmuch helper functions
 
 # Use test_set_prereq to tell that a particular prerequisite is available.
-- 
2.8.1

  parent reply	other threads:[~2016-05-13 10:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-13 10:38 version 5 of libconfig / single argument date / named query patches David Bremner
2016-05-13 10:38 ` [Patch v5 01/11] configure: detect Xapian:FieldProcessor David Bremner
2016-05-13 10:38 ` [Patch v5 02/11] lib: optionally support single argument date: queries David Bremner
2016-05-13 10:38 ` David Bremner [this message]
2016-05-13 10:38 ` [Patch v5 04/11] configure: check directly for xapian compaction API David Bremner
2016-05-14  0:12   ` David Bremner
2016-05-13 10:38 ` [Patch v5 05/11] lib: provide config API David Bremner
2016-05-24 11:48   ` David Bremner
2016-05-13 10:38 ` [Patch v5 06/11] lib: config list iterators David Bremner
2016-05-24 11:54   ` David Bremner
2016-05-13 10:38 ` [Patch v5 07/11] CLI: add optional config data to dump output David Bremner
2016-05-13 10:38 ` [Patch v5 08/11] CLI: optionally restore config data David Bremner
2016-05-13 10:38 ` [Patch v5 09/11] CLI: add notmuch-config support for named queries David Bremner
2016-05-13 10:38 ` [Patch v5 10/11] lib: make a global constant for query parser flags David Bremner
2016-05-13 10:38 ` [Patch v5 11/11] lib: add support for named queries David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463135893-7471-4-git-send-email-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).