Skip to content

Commit

Permalink
Created debug ruby build
Browse files Browse the repository at this point in the history
  • Loading branch information
wsobel committed Mar 4, 2022
1 parent f5261e5 commit 71da59e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ include(cmake/ide_integration.cmake)

create_clangformat_target()

if(NOT WITHOUT_RUBY)
file(GLOB_RECURSE files RELATIVE ${CONAN_USER_RUBY_RICE_RUBY_LIBRARIES} "${CONAN_USER_RUBY_RICE_RUBY_LIBRARIES}/*")
foreach(file ${files})
get_filename_component(dir ${file} DIRECTORY)
file(COPY "${CONAN_USER_RUBY_RICE_RUBY_LIBRARIES}/${file}" DESTINATION "${CMAKE_BINARY_DIR}/lib/${dir}")
endforeach()
endif()

# For Visual Studio generators it is now possible (since V3.6) to set a default startup project.
# We will set this to the agent_test project.
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT agent_test)
Expand All @@ -113,4 +121,3 @@ set(CPACK_PACKAGE_NAME "cppagent")
set(CPACK_PACKAGE_VENDOR "MTConnect.org")

include(CPack)

8 changes: 7 additions & 1 deletion conan/ruby_rice/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def source(self):

def build(self):
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
conf_args = ["--with-static-linked-ext", "--enable-install-static-library", '--without-rdoc']
conf_args = ["--with-static-linked-ext", "--enable-install-static-library", '--without-rdoc',
"--enable-load-relative"]
if self.settings.build_type =='Debug':
conf_args.append('optflags=-O3')
conf_args.append('--enable-debug-env')

build = None

self._autotools.configure(args=conf_args, configure_dir=self._ruby_source, build=build)
Expand Down Expand Up @@ -68,4 +73,5 @@ def package_info(self):
pass

self.cpp_info.exelinkflags = config['LDFLAGS'].split() + libflags
self.user_info.RUBY_LIBRARIES = self.package_folder + "/lib"

2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class CppAgentConan(ConanFile):
name = "mtconnect_cppagent"
version = "1.7"
version = "2.0"
generators = "cmake"
url = "https://github.com/mtconnect/cppagent_dev.git"
license = "Apache License 2.0"
Expand Down
33 changes: 14 additions & 19 deletions src/ruby/embedded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace mtconnect::ruby {
public:
RubyTransform(const std::string &name,
Rice::Module &module,
const Rice::Identifier function,
const std::string &function,
pipeline::PipelineContextPtr context)
: Transform(name), m_contract(context->m_contract.get()),
m_module(module), m_function(function)
Expand Down Expand Up @@ -206,40 +206,35 @@ namespace mtconnect::ruby {
ruby_init();
ruby_init_loadpath();

static Module mtc = define_module("MTConnect");
m_module = make_unique<Module>(define_module("MTConnect"));

static Class entity = define_class_under<entity::Entity>(mtc, "Entity").
define_class_under<entity::Entity>(*m_module, "Entity").
define_method("value", [](entity::Entity &entity) { return entity.getValue(); }).
define_method("property", [](entity::Entity &entity, std::string name) {
return entity.getProperty(name);
}, Arg("name"));

static Class observation = define_class_under<observation::Observation, entity::Entity>(mtc, "Observation");
define_class_under<observation::Observation, entity::Entity>(*m_module, "Observation");

static Class dataItem = define_class_under<device_model::data_item::DataItem, entity::Entity>(mtc, "DataItem");
define_class_under<device_model::data_item::DataItem, entity::Entity>(*m_module, "DataItem");

mtc.instance_eval("def transform(obs); p obs.value; end");
mtc.instance_eval("p $:");
mtc.instance_eval("p constants");
rb_eval_string("p Object.constants.sort");

auto dev = agent->getDeviceByName("Mazak");
auto di = dev->getDeviceDataItem("Ypos");
Timestamp time = date::sys_days(2021_y / jan / 19_d) + 10h + 1min;

ErrorList errors;
auto obs = Observation::make(di, {{"VALUE", 1.23}}, time, errors);

mtc.call(Identifier("transform"), obs);
m_module->instance_eval("def transform(obs); p obs.value; end");

rb_eval_string("p $:; require 'irb'; IRB.start");

for (auto &adp : agent->getSources()) {
auto pipeline = adp->getPipeline();
auto trans = make_shared<RubyTransform>("test", mtc, Identifier("transform"),
auto trans = make_shared<RubyTransform>("test", *m_module, "transform",
pipeline->getContext());
pipeline->spliceAfter("DuplicateFilter", trans);
}
}

Embedded::~Embedded()
{
}


void *runWithoutGil(void *context)
{
boost::asio::io_context *ctx = static_cast<boost::asio::io_context*>(context);
Expand Down
8 changes: 7 additions & 1 deletion src/ruby/embedded.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#include "utilities.hpp"

#include <boost/asio.hpp>
#include <memory>

namespace Rice {
class Module;
}

namespace mtconnect {
class Agent;
Expand All @@ -28,13 +33,14 @@ namespace mtconnect {
{
public:
Embedded(Agent *agent, const ConfigOptions &options);
~Embedded() {}
~Embedded();

void start(boost::asio::io_context &context, int threads);

protected:
Agent *m_agent;
ConfigOptions m_options;
std::unique_ptr<Rice::Module> m_module;
};
}
}

0 comments on commit 71da59e

Please sign in to comment.