Commit 9e84ef59 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

uploading changes to inject internal plugin path at init time


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 7d6147fd
......@@ -59,12 +59,26 @@ void Initialize(int arc, char** arv) {
argc = arc;
argv = arv;
// Do a little preprocessing on the
// command line args to see if we have
// been given a custom internal plugin path
using namespace boost::program_options;
variables_map vm;
options_description desc;
desc.add_options()("internal-plugin-path", value<std::string>(), "");
store(command_line_parser(argc, argv).options(desc).allow_unregistered().run(), vm);
notify(vm);
XACCLogger::instance()->enqueueLog("Creating XACC ServiceRegistry");
// Get reference to the service registry
auto serviceRegistry = xacc::ServiceRegistry::instance();
try {
XACCLogger::instance()->enqueueLog("Initializing the ServiceRegistry");
serviceRegistry->initialize();
if (vm.count("internal-plugin-path")) {
serviceRegistry->initialize(vm["internal-plugin-path"].as<std::string>());
} else {
serviceRegistry->initialize();
}
} catch (std::exception& e) {
XACCLogger::instance()->error("Failure initializing XACC Plugin Registry - " +
std::string(e.what()));
......
......@@ -82,7 +82,8 @@ public:
// Parse the command line options
variables_map clArgs;
store(parse_command_line(argc, argv, *xaccOptions.get()), clArgs);
store(command_line_parser(argc, argv).options(*xaccOptions.get()).allow_unregistered().run(), clArgs);
notify(clArgs);
if (clArgs.count("help")) {
XACCLogger::instance()->dumpQueue();
std::cout << *xaccOptions.get() << "\n";
......
......@@ -6,7 +6,7 @@
namespace xacc {
void ServiceRegistry::initialize() {
void ServiceRegistry::initialize(const std::string internalPath) {
if (!initialized) {
framework = FrameworkFactory().NewFramework();
......@@ -20,61 +20,92 @@ void ServiceRegistry::initialize() {
}
// Get the paths/files we'll be searching
const std::string xaccLibDir = std::string(XACC_INSTALL_DIR) + std::string("/lib");
const std::string xaccLibDir = std::string(XACC_INSTALL_DIR)
+ std::string("/lib");
const std::string xaccPluginPath = std::getenv("HOME")
+ std::string("/.xacc/plugins");
+ std::string("/.xacc/plugins");
std::stringstream s;
s << std::getenv("HOME") << "/.xacc/.internal_plugins";
const std::string internalFileStr = s.str();
// Search in the .internal_plugins file first
if (boost::filesystem::exists(internalFileStr)) {
std::ifstream internalFile(internalFileStr);
std::string contents((std::istreambuf_iterator<char>(internalFile)), std::istreambuf_iterator<char>());
std::vector<std::string> split;
boost::split(split, contents, boost::is_any_of("\n"));
for (auto& s : split) {
if (!boost::contains(s, "#") && boost::filesystem::exists(s)) {
try {
context.InstallBundles(s);
boost::filesystem::path p(s);
auto name = p.filename().string();
boost::replace_all(name, "lib", "");
boost::replace_all(name, ".so", "");
boost::replace_all(name, ".dy", "");
installed.insert({name, p.string()});
if (!internalPath.empty()) {
XACCLogger::instance()->enqueueLog(
"Searching User Provided Directory: " + internalPath);
for (auto &entry : boost::filesystem::directory_iterator(
internalPath)) {
// We want the gate and aqc bundles that come with XACC
if (boost::contains(entry.path().filename().string(),
"libxacc-quantum")) {
auto name = entry.path().filename().string();
boost::replace_all(name, "lib", "");
boost::replace_all(name, ".so", "");
boost::replace_all(name, ".dy", "");
if (installed.find(name) == installed.end()) {
context.InstallBundles(entry.path().string());
XACCLogger::instance()->enqueueLog(
"Installed base plugin " + name);
} catch(std::exception& e) {
// do nothing if we failed
installed.insert( { name, entry.path().string() });
}
}
}
}
// If not found, see if we have access to the installation directory
if (!installed.count("xacc-quantum-gate")
|| !installed.count("xacc-quantum-aqc")) {
if (boost::filesystem::exists(xaccLibDir)) {
XACCLogger::instance()->enqueueLog(
"Searching XACC Library Directory: " + xaccLibDir);
for (auto &entry : boost::filesystem::directory_iterator(
xaccLibDir)) {
// We want the gate and aqc bundles that come with XACC
if (boost::contains(entry.path().filename().string(),
"libxacc-quantum")) {
auto name = entry.path().filename().string();
boost::replace_all(name, "lib", "");
boost::replace_all(name, ".so", "");
boost::replace_all(name, ".dy", "");
if (installed.find(name) == installed.end()) {
context.InstallBundles(entry.path().string());
}
else {
// Search in the .internal_plugins file first
if (boost::filesystem::exists(internalFileStr)) {
std::ifstream internalFile(internalFileStr);
std::string contents(
(std::istreambuf_iterator<char>(internalFile)),
std::istreambuf_iterator<char>());
std::vector<std::string> split;
boost::split(split, contents, boost::is_any_of("\n"));
for (auto& s : split) {
if (!boost::contains(s, "#")
&& boost::filesystem::exists(s)) {
try {
context.InstallBundles(s);
boost::filesystem::path p(s);
auto name = p.filename().string();
boost::replace_all(name, "lib", "");
boost::replace_all(name, ".so", "");
boost::replace_all(name, ".dy", "");
installed.insert( { name, p.string() });
XACCLogger::instance()->enqueueLog(
"Installed base plugin " + name);
installed.insert({name, entry.path().string()});
} catch (std::exception& e) {
// do nothing if we failed
}
}
}
}
// If not found, see if we have access to the installation directory
if (!installed.count("xacc-quantum-gate")
|| !installed.count("xacc-quantum-aqc")) {
if (boost::filesystem::exists(xaccLibDir)) {
XACCLogger::instance()->enqueueLog(
"Searching XACC Library Directory: " + xaccLibDir);
for (auto &entry : boost::filesystem::directory_iterator(
xaccLibDir)) {
// We want the gate and aqc bundles that come with XACC
if (boost::contains(entry.path().filename().string(),
"libxacc-quantum")) {
auto name = entry.path().filename().string();
boost::replace_all(name, "lib", "");
boost::replace_all(name, ".so", "");
boost::replace_all(name, ".dy", "");
if (installed.find(name) == installed.end()) {
context.InstallBundles(entry.path().string());
XACCLogger::instance()->enqueueLog(
"Installed base plugin " + name);
installed.insert(
{ name, entry.path().string() });
}
}
}
}
......
......@@ -70,7 +70,7 @@ protected:
public:
void initialize();
void initialize(const std::string internalPath = "");
// Overriding here so we can have a custom constructor
static ServiceRegistry* instance() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment