summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-07-09 14:04:52 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-07-10 16:03:41 +0100
commit2da31f418f5769f8c4c52fb8a4bda179066265e4 (patch)
treefef49a99e0193cb30bc6b79efaeabe7605387bee
parentRefactor test options class into its own lib (diff)
downloadicetray-2da31f418f5769f8c4c52fb8a4bda179066265e4.tar.bz2
icetray-2da31f418f5769f8c4c52fb8a4bda179066265e4.tar.xz
icetray-2da31f418f5769f8c4c52fb8a4bda179066265e4.zip
Add tool for self-documenting options available in a given library
-rw-r--r--icetray/icetray/options.cpp7
-rw-r--r--icetray/icetray/options.h1
-rw-r--r--icetray/tool/Jamfile.jam9
-rw-r--r--icetray/tool/icetrayDoc.cpp58
-rw-r--r--icetray/unittests/Jamfile.jam10
5 files changed, 85 insertions, 0 deletions
diff --git a/icetray/icetray/options.cpp b/icetray/icetray/options.cpp
index 6a0b5bf..a12a7d0 100644
--- a/icetray/icetray/options.cpp
+++ b/icetray/icetray/options.cpp
@@ -56,5 +56,12 @@ namespace IceTray {
po::store(result, vm);
po::notify(vm);
}
+
+ std::ostream &
+ OptionsCollation::write(std::ostream & s) const
+ {
+ s << all;
+ return s;
+ }
}
diff --git a/icetray/icetray/options.h b/icetray/icetray/options.h
index 00911d3..15c4740 100644
--- a/icetray/icetray/options.h
+++ b/icetray/icetray/options.h
@@ -42,6 +42,7 @@ namespace IceTray {
~OptionsCollation();
void apply(Ice::PropertiesPtr p);
+ std::ostream & write(std::ostream &) const;
private:
boost::program_options::options_description all;
diff --git a/icetray/tool/Jamfile.jam b/icetray/tool/Jamfile.jam
index 43be3d1..4f8441e 100644
--- a/icetray/tool/Jamfile.jam
+++ b/icetray/tool/Jamfile.jam
@@ -3,6 +3,7 @@ import package ;
lib boost_program_options ;
lib boost_filesystem ;
lib boost_system ;
+lib dl ;
exe icetray-sql :
icetraySql.cpp
@@ -13,6 +14,14 @@ exe icetray-sql :
<include>/usr/include/adhocutil/
;
+exe icetray-doc :
+ icetrayDoc.cpp
+ :
+ <library>boost_program_options
+ <library>../icetray//icetray
+ <library>dl
+ ;
+
explicit install-tools ;
alias install-tools :
install-tools-data
diff --git a/icetray/tool/icetrayDoc.cpp b/icetray/tool/icetrayDoc.cpp
new file mode 100644
index 0000000..4fdda17
--- /dev/null
+++ b/icetray/tool/icetrayDoc.cpp
@@ -0,0 +1,58 @@
+#include <iostream>
+#include <boost/program_options.hpp>
+#include <dlfcn.h>
+#include <compileTimeFormatter.h>
+#include <options.h>
+
+namespace po = boost::program_options;
+
+AdHocFormatter(dlopenFail, "Failed to dlopen(%?): %?\n");
+
+void
+write()
+{
+ IceTray::OptionsCollation oc;
+ oc.write(std::cout);
+}
+
+int
+main(int argc, char ** argv)
+{
+ po::options_description opts("IceTray library documentation");
+ std::vector<std::string> libs;
+
+ opts.add_options()
+ ("help,h", "Show this help message")
+ ("lib", po::value(&libs)->required(), "Library filename (see dlopen(3))")
+ ;
+ po::positional_options_description p;
+ p.add("lib", -1);
+
+ po::variables_map vm;
+ po::store(po::command_line_parser(argc, argv).options(opts).positional(p).run(), vm);
+
+ if (vm.count("help")) {
+ std::cout << opts << std::endl;
+ return 1;
+ }
+ po::notify(vm);
+
+ std::vector<void *> dls;
+ for (const auto & lib : libs) {
+ auto dl = dlopen(lib.c_str(), RTLD_NOW);
+ if (!dl) {
+ dlopenFail::write(std::cerr, lib, dlerror());
+ return 1;
+ }
+ dls.push_back(dl);
+ }
+
+ write();
+
+ for (const auto & dl : dls) {
+ dlclose(dl);
+ }
+
+ return 0;
+}
+
diff --git a/icetray/unittests/Jamfile.jam b/icetray/unittests/Jamfile.jam
index ee2c429..91c9085 100644
--- a/icetray/unittests/Jamfile.jam
+++ b/icetray/unittests/Jamfile.jam
@@ -103,5 +103,15 @@ run
<library>testOptions
;
+run
+ ../tool/icetrayDoc.cpp
+ : :
+ testOptions
+ :
+ <library>..//adhocutil
+ <library>..//icetray
+ <library>../tool//dl
+ ;
+
IMPORT $(__name__) : icetray.c++.sql : : icetray.c++.sql ;