Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

++ #3

Merged
merged 1 commit into from
Jun 16, 2024
Merged

++ #3

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 57 additions & 17 deletions mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "maiken/module/init.hpp"

#include "mkn/kul/io.hpp"
#include "mkn/kul/string.hpp"
#include <string>

namespace mkn {
namespace mod {
namespace conan_io {
Expand Down Expand Up @@ -71,6 +75,32 @@ class InstallModule : public maiken::Module {
}
std::string python_exe = "python";

auto parse_cmake_var(std::string const& find, std::string const& s){
std::vector<std::string> data;
std::size_t const offset = s.find(find) + find.size() + 1;
auto const line = s.substr(offset, s.size() - offset);
for(auto const& b: kul::String::ESC_SPLIT(line, ' '))
data.emplace_back(b.substr(1, b.size() - 2));
for(auto& l : data)
if(l[l.size() - 1] == '"') l = l.substr(0, l.size() - 1);
return data;
}

auto parse_for_lib_and_incs(kul::File const& toolChainFile){
kul::io::Reader r(toolChainFile);
std::vector<std::string> inc, lib;
char const* c = nullptr;
while ((c = r.readLine())) {
std::string str = c;
if(inc.size() == 0 && str.find("CMAKE_INCLUDE_PATH") != std::string::npos)
inc = parse_cmake_var("CMAKE_INCLUDE_PATH", str);
if(lib.size() == 0 && str.find("CMAKE_LIBRARY_PATH") != std::string::npos)
lib = parse_cmake_var("CMAKE_LIBRARY_PATH", str);
if(inc.size() && lib.size()) break;
}
return std::make_tuple(inc, lib);
}

public:
InstallModule() {
std::string py(kul::env::GET("PYTHON"));
Expand All @@ -84,6 +114,11 @@ class InstallModule : public maiken::Module {
kul::File conanFile("conanfile.txt", a.project().dir());
if (!conanFile)
return;

kul::Dir buildDir{"build", a.project().dir()};
kul::Dir generatorDir{"generators", buildDir};
kul::File conanToolChainFile("conan_toolchain.cmake", generatorDir);

ConanFile &cFile(cfm.get_or_create(conanFile));
kul::io::Reader rdr(conanFile);

Expand All @@ -104,30 +139,35 @@ class InstallModule : public maiken::Module {
KEXCEPTION("conanFile is invalid");
auto bits = kul::String::SPLIT(s, "/");
kul::Dir conan_dir = kul::user::home(".conan/data");
kul::Dir req_dir(bits[0] + "/" + bits[1] + "/package", conan_dir);
if (!req_dir) {

if (!conanToolChainFile) {
std::string install = node["install"] ? node["install"].Scalar() : "";
kul::os::PushDir pdir(a.project().dir());
kul::Process p(python_exe);
p << "-m conans.conan install" << install << ".";
p << "-m conans.conan install" << install << ". --build=missing";
p.start();
}
auto req_dirs(req_dir.dirs());
if (req_dirs.size() != 1)
KEXCEPTION("conan data is inconsistent");
kul::Dir req_home(req_dirs[0]);
kul::Dir req_include("include", req_home);
kul::Dir req_lib("lib", req_home);
if (req_include) {
a.addInclude(req_include.escr());
for (auto *rep : a.revendencies())
rep->addInclude(req_include.escr());

auto const& [inc, lib] = parse_for_lib_and_incs(conanToolChainFile);

for(auto const& d : inc){
kul::Dir req_include(d);
if (req_include) {
a.addInclude(req_include.escr());
for (auto *rep : a.revendencies())
rep->addInclude(req_include.escr());
}
}
if (req_lib) {
a.addLibpath(req_lib.escr());
for (auto *rep : a.revendencies())
rep->addLibpath(req_lib.escr());

for(auto const& d : lib){
kul::Dir req_lib(d);
if (req_lib) {
a.addLibpath(req_lib.escr());
for (auto *rep : a.revendencies())
rep->addLibpath(req_lib.escr());
}
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


#include "kul/signal.hpp"
#include "mkn/kul/signal.hpp"

#include <maiken.hpp>

Expand Down