Skip to content

Commit

Permalink
SMCE: autodetect CMake in PATH
Browse files Browse the repository at this point in the history
Signed-off-by: AeroStun <24841307+AeroStun@users.noreply.github.com>
  • Loading branch information
AeroStun committed Jan 22, 2021
1 parent 4827f2e commit fb0204b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
2 changes: 2 additions & 0 deletions include/SMCE/ExecutionContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ namespace smce {

class ExecutionContext {
stdfs::path m_res_dir;
std::string m_cmake_path = "cmake";

public:
explicit ExecutionContext(stdfs::path resources_dir) : m_res_dir{std::move(resources_dir)} {};
[[nodiscard]] const stdfs::path& resource_dir() const noexcept { return m_res_dir; }
[[nodiscard]] const std::string& cmake_path() const noexcept { return m_cmake_path; }
[[nodiscard]] bool check_suitable_environment() noexcept;
};

Expand Down
33 changes: 1 addition & 32 deletions src/SMCE/BoardRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ LONG NTAPI NtResumeProcess(HANDLE ProcessHandle);
#include <boost/interprocess/managed_shared_memory.hpp>
#include <SMCE/BoardConf.hpp>
#include <SMCE/BoardView.hpp>
#include <SMCE/internal/BoardData.hpp>
#include <SMCE/internal/SharedBoardData.hpp>

using namespace std::literals;
Expand Down Expand Up @@ -107,41 +106,11 @@ bool BoardRunner::configure(std::string_view pp_fqbn, const BoardConfig& bconf)
m_internal->sbdata.configure("SMCE-Runner-" + std::to_string(m_internal->sketch_id), pp_fqbn, bconf);
m_status = Status::configured;
return true;

#if 0
#pragma region move_me_to_check_suitable_env
if(std::error_code ec; stdfs::is_empty(res_path, ec) || ec)
return false;

std::string cmake_path = []{ const auto env = std::getenv("SMCE_CMAKE_PATH"); return env ? env : ""; }();
if(!cmake_path.empty()) {
if(std::error_code ec; stdfs::is_empty(cmake_path, ec) || ec)
return false;
} else {
cmake_path = bp::search_path(cmake_path).string();
if(cmake_path.empty())
return false;
}
bp::ipstream cmake_out;
bp::child cmake_child{cmake_path, "--version", bp::std_out > cmake_out};
std::string line;
while (cmake_child.running() && std::getline(cmake_out, line) && !line.empty()) {
if(line.starts_with("cmake")) {
cmake_child.join();
return false;
}
break;
}
cmake_child.join();
#pragma endregion
#endif
}

bool BoardRunner::build(const stdfs::path& sketch_src, [[maybe_unused]] const SketchConfig& skonf) noexcept {

const auto& res_path = m_exectx.resource_dir();
// const auto& cmake_path = m_exectx.cmake_path();
const auto cmake_path = "/usr/local/bin/cmake";
const auto& cmake_path = m_exectx.cmake_path();

std::string dir_arg = "-DSMCE_DIR=" + res_path.string();
std::string fqbn_arg = "-DSKETCH_FQBN="s + m_internal->sbdata.get_board_data()->fqbn.c_str();
Expand Down
36 changes: 35 additions & 1 deletion src/SMCE/ExecutionContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,38 @@
*
*/

#include <SMCE/ExecutionContext.hpp>
#include <SMCE/ExecutionContext.hpp>

#include <boost/process.hpp>

namespace bp = boost::process;

namespace smce {

[[nodiscard]] bool ExecutionContext::check_suitable_environment() noexcept {
if(std::error_code ec; stdfs::is_empty(m_res_dir, ec) || ec)
return false;

if(m_cmake_path != "cmake") {
if(std::error_code ec; stdfs::is_empty(m_cmake_path, ec) || ec)
return false;
} else {
m_cmake_path = bp::search_path(m_cmake_path).string();
if(m_cmake_path.empty())
return false;
}
bp::ipstream cmake_out;
bp::child cmake_child{m_cmake_path, "--version", bp::std_out > cmake_out};
std::string line;
while (cmake_child.running() && std::getline(cmake_out, line) && !line.empty()) {
if(!line.starts_with("cmake")) {
cmake_child.join();
return false;
}
break;
}
cmake_child.join();
return cmake_child.native_exit_code() == 0;
}

}

0 comments on commit fb0204b

Please sign in to comment.