| 82 | } |
| 83 | |
| 84 | int install_module(const bmf_sdk::ModuleInfo &info, bool force) { |
| 85 | // check module_path |
| 86 | auto original_path = fs::path(info.module_path); |
| 87 | if (!fs::exists(original_path) || !fs::is_directory(original_path)) { |
| 88 | BMFLOG(BMF_ERROR) << "invalid module_path:" << info.module_path |
| 89 | << std::endl; |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | // check module_type and module_entry |
| 94 | // for c++ and python, check that the entry is correct. |
| 95 | // for go, parse the entry to get the dynamic library name |
| 96 | std::string module_file, _; |
| 97 | auto &M = bmf_sdk::ModuleManager::instance(); |
| 98 | if (info.module_type == "c++" || info.module_type == "python" || |
| 99 | info.module_type == "go") { |
| 100 | auto &M = bmf_sdk::ModuleManager::instance(); |
| 101 | try { |
| 102 | std::tie(module_file, _) = M.parse_entry(info.module_entry, true); |
| 103 | } catch (std::exception &e) { |
| 104 | BMFLOG(BMF_ERROR) << e.what() << std::endl; |
| 105 | BMFLOG(BMF_ERROR) |
| 106 | << "invalid module_entry:" << info.module_entry << std::endl; |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | // check module file |
| 111 | if (info.module_type == "c++" || info.module_type == "go") { |
| 112 | module_file = |
| 113 | (fs::path(info.module_path) / |
| 114 | (module_file + bmf_sdk::SharedLibrary::default_extension())) |
| 115 | .string(); |
| 116 | } else { |
| 117 | module_file = |
| 118 | (fs::path(info.module_path) / (module_file + ".py")).string(); |
| 119 | } |
| 120 | if (!fs::exists(module_file)) { |
| 121 | BMFLOG(BMF_ERROR) |
| 122 | << "cannot find the module file:" << module_file << std::endl; |
| 123 | return -1; |
| 124 | } |
| 125 | } else { |
| 126 | BMFLOG(BMF_ERROR) << "invalid module_type, must be one of c++/python/go" |
| 127 | << std::endl; |
| 128 | return -1; |
| 129 | } |
| 130 | |
| 131 | if (!fs::exists(module_root_path) && |
| 132 | !fs::create_directories(module_root_path)) { |
| 133 | BMFLOG(BMF_ERROR) << "create module root directory failed." |
| 134 | << std::endl; |
| 135 | return -1; |
| 136 | } |
| 137 | |
| 138 | auto installed_path = module_root_path / ("Module_" + info.module_name); |
| 139 | if (fs::exists(installed_path)) { |
| 140 | if (force) { |
| 141 | fs::remove_all(installed_path); |
no test coverage detected