From 81b48dc3a7480c3df87d4293722b5a3d5f0de2c2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 1 Feb 2011 10:53:31 +0200 Subject: Pass profile paths to plugin; handle profile options --- odb/profile.cxx | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 odb/profile.cxx (limited to 'odb/profile.cxx') 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 +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v3; see accompanying LICENSE file + +#include // stat +#include // stat +#include // stat + +#include + +#include + +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 (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 (); +} -- cgit v1.1