aboutsummaryrefslogtreecommitdiff
path: root/odb/profile.cxx
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 /odb/profile.cxx
parentf0cfd3c7942d27e312d27f5a1d94532516f393aa (diff)
Pass profile paths to plugin; handle profile options
Diffstat (limited to 'odb/profile.cxx')
-rw-r--r--odb/profile.cxx62
1 files changed, 62 insertions, 0 deletions
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 ();
+}