summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-02-01 10:53:31 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-02-01 10:53:31 +0200
commit81b48dc3a7480c3df87d4293722b5a3d5f0de2c2 (patch)
tree3918cba796c8793df16c2cac74639d5f99e97104
parentf0cfd3c7942d27e312d27f5a1d94532516f393aa (diff)
Pass profile paths to plugin; handle profile options
-rw-r--r--odb/makefile2
-rw-r--r--odb/odb.cxx73
-rw-r--r--odb/plugin.cxx31
-rw-r--r--odb/profile.cxx62
-rw-r--r--odb/profile.hxx32
5 files changed, 135 insertions, 65 deletions
diff --git a/odb/makefile b/odb/makefile
index 4cbf071..d73f007 100644
--- a/odb/makefile
+++ b/odb/makefile
@@ -68,7 +68,7 @@ cxx_dtun := odb.cxx
# Common units.
#
-cxx_ctun := database.cxx
+cxx_ctun := database.cxx profile.cxx
# Options file.
#
diff --git a/odb/odb.cxx b/odb/odb.cxx
index d8576d2..d4d719d 100644
--- a/odb/odb.cxx
+++ b/odb/odb.cxx
@@ -25,7 +25,6 @@
# include <fcntl.h> // _O_TEXT
#endif
-#include <set>
#include <string>
#include <vector>
#include <cstddef> // size_t
@@ -38,6 +37,7 @@
#include <odb/version.hxx>
#include <odb/options.hxx>
+#include <odb/profile.hxx>
#ifdef HAVE_CONFIG_H
# include <odb/config.h>
@@ -115,25 +115,9 @@ encode_plugin_option (string const& k, string const& v);
// profile_failure, process_failure and invalid_path exceptions. Name
// is the program name (argv[0]) for diagnostics.
//
-struct profile_failure {};
-
static paths
profile_paths (strings const& args, char const* name);
-// Search for the profile options file.
-//
-struct profile_data
-{
- profile_data (paths const& p, char const* n): search_paths (p), name (n) {}
-
- paths const& search_paths;
- set<path> loaded;
- char const* name;
-};
-
-static string
-profile_search (char const* profile, void* arg);
-
static char const* const db_macro[] =
{
"-DODB_DATABASE_MYSQL",
@@ -483,7 +467,15 @@ main (int argc, char* argv[])
args.push_back (encode_plugin_option (k, v));
}
- // Reserve space for and remember the position of the --svc-file
+ // Pass profile search paths (svc-path option).
+ //
+ for (paths::const_iterator i (prof_paths.begin ());
+ i != prof_paths.end (); ++i)
+ {
+ args.push_back (encode_plugin_option ("svc-path", i->string ()));
+ }
+
+ // Reserve space for and remember the position of the svc-file
// option.
//
size_t svc_file_pos (args.size ());
@@ -824,51 +816,6 @@ profile_paths (strings const& sargs, char const* name)
return r;
}
-static string
-profile_search (char const* prof, void* arg)
-{
- profile_data* pd (static_cast<profile_data*> (arg));
- paths const& ps (pd->search_paths);
-
- path p (prof), odb ("odb"), r;
- p.normalize (); // Convert '/' to the canonical path separator form.
- p += ".options";
-
- struct stat info;
- paths::const_iterator i (ps.begin ()), end (ps.end ());
-
- for (; i != end; ++i)
- {
- // First check in the search directory itself and then try the odb/
- // subdirectory.
- //
- r = *i / p;
-
- // Just check that the file exist without checking for permissions, etc.
- //
- if (stat (r.string ().c_str (), &info) == 0 && S_ISREG (info.st_mode))
- break;
-
- r = *i / odb / p;
-
- if (stat (r.string ().c_str (), &info) == 0 && S_ISREG (info.st_mode))
- break;
- }
-
- if (i == end)
- {
- cerr << pd->name << ": error: unable to locate options file for profile '"
- << prof << "'" << endl;
- throw profile_failure ();
- }
-
- if (pd->loaded.find (r) != pd->loaded.end ())
- return string ();
-
- pd->loaded.insert (r);
- return r.string ();
-}
-
//
// Path manipulation.
//
diff --git a/odb/plugin.cxx b/odb/plugin.cxx
index 5b9efc1..a611dfe 100644
--- a/odb/plugin.cxx
+++ b/odb/plugin.cxx
@@ -11,9 +11,12 @@
#include <cstring> // std::strcpy
#include <iostream>
+#include <cutl/fs/path.hxx>
+
#include <odb/pragma.hxx>
#include <odb/parser.hxx>
#include <odb/options.hxx>
+#include <odb/profile.hxx>
#include <odb/version.hxx>
#include <odb/validator.hxx>
#include <odb/generator.hxx>
@@ -22,8 +25,14 @@
using namespace std;
using namespace semantics;
+using cutl::fs::path;
+using cutl::fs::invalid_path;
+
+typedef vector<path> paths;
+
int plugin_is_GPL_compatible;
auto_ptr<options const> options_;
+paths profile_paths_;
// A prefix of the _cpp_file struct. This struct is not part of the
// public interface so we have to resort to this technique (based on
@@ -154,6 +163,14 @@ plugin_init (plugin_name_args* plugin_info, plugin_gcc_version*)
{
plugin_argument& a (plugin_info->argv[i]);
+ // Handle service options.
+ //
+ if (strcmp (a.key, "svc-path") == 0)
+ {
+ profile_paths_.push_back (path (a.value));
+ continue;
+ }
+
string opt (strlen (a.key) > 1 ? "--" : "-");
opt += a.key;
@@ -168,7 +185,19 @@ plugin_init (plugin_name_args* plugin_info, plugin_gcc_version*)
}
int argc (static_cast<int> (argv.size ()));
- cli::argv_file_scanner scan (argc, &argv[0], "--options-file");
+
+ profile_data pd (profile_paths_, "odb plugin");
+ cli::argv_file_scanner::option_info oi[3];
+ oi[0].option = "--options-file";
+ oi[0].search_func = 0;
+ oi[1].option = "-p";
+ oi[1].search_func = &profile_search;
+ oi[1].arg = &pd;
+ oi[2].option = "--profile";
+ oi[2].search_func = &profile_search;
+ oi[2].arg = &pd;
+
+ cli::argv_file_scanner scan (argc, &argv[0], oi, 3);
options_.reset (
new options (scan, cli::unknown_mode::fail, cli::unknown_mode::fail));
diff --git a/odb/profile.cxx b/odb/profile.cxx
new file mode 100644
index 0000000..393c953
--- /dev/null
+++ b/odb/profile.cxx
@@ -0,0 +1,62 @@
+// file : odb/profile.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#include <unistd.h> // stat
+#include <sys/types.h> // stat
+#include <sys/stat.h> // stat
+
+#include <iostream>
+
+#include <odb/profile.hxx>
+
+using namespace std;
+
+string
+profile_search (char const* prof, void* arg)
+{
+ typedef profile_data::path path;
+ typedef profile_data::paths paths;
+
+ profile_data* pd (static_cast<profile_data*> (arg));
+ paths const& ps (pd->search_paths);
+
+ path p (prof), odb ("odb"), r;
+ p.normalize (); // Convert '/' to the canonical path separator form.
+ p += ".options";
+
+ struct stat info;
+ paths::const_iterator i (ps.begin ()), end (ps.end ());
+
+ for (; i != end; ++i)
+ {
+ // First check in the search directory itself and then try the odb/
+ // subdirectory.
+ //
+ r = *i / p;
+
+ // Just check that the file exist without checking for permissions, etc.
+ //
+ if (stat (r.string ().c_str (), &info) == 0 && S_ISREG (info.st_mode))
+ break;
+
+ r = *i / odb / p;
+
+ if (stat (r.string ().c_str (), &info) == 0 && S_ISREG (info.st_mode))
+ break;
+ }
+
+ if (i == end)
+ {
+ cerr << pd->name << ": error: unable to locate options file for profile '"
+ << prof << "'" << endl;
+ throw profile_failure ();
+ }
+
+ if (pd->loaded.find (r) != pd->loaded.end ())
+ return string ();
+
+ pd->loaded.insert (r);
+ return r.string ();
+}
diff --git a/odb/profile.hxx b/odb/profile.hxx
new file mode 100644
index 0000000..e3c5035
--- /dev/null
+++ b/odb/profile.hxx
@@ -0,0 +1,32 @@
+// file : odb/profile.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
+// license : GNU GPL v3; see accompanying LICENSE file
+
+#ifndef ODB_PROFILE_HXX
+#define ODB_PROFILE_HXX
+
+#include <set>
+#include <vector>
+#include <string>
+
+#include <cutl/fs/path.hxx>
+
+struct profile_data
+{
+ typedef cutl::fs::path path;
+ typedef std::vector<path> paths;
+
+ profile_data (paths const& p, char const* n): search_paths (p), name (n) {}
+
+ paths const& search_paths;
+ std::set<path> loaded;
+ char const* name;
+};
+
+struct profile_failure {};
+
+std::string
+profile_search (char const* profile, void* arg);
+
+#endif // ODB_PROFILE_HXX