Skip to content

Commit

Permalink
Merge pull request #8 from mudream4869/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mudream4869 authored Mar 7, 2021
2 parents 620eeb0 + 09870db commit 1000d70
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 58 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,8 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Install yaml-cpp
run: sudo apt update && sudo apt install -y libyaml-cpp-dev

- name: Install gtest
run: >
sudo apt update &&
sudo apt install -y libgtest-dev &&
cd /usr/src/gtest &&
sudo cmake CMakeLists.txt &&
sudo make &&
sudo cp ./lib/*.a /usr/lib &&
sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a &&
sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
with:
submodules: recursive

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "third_party/googletest"]
path = tests/third_party/googletest
url = [email protected]:google/googletest.git
[submodule "third_party/yaml-cpp"]
path = third_party/yaml-cpp
url = [email protected]:jbeder/yaml-cpp.git
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
cmake_minimum_required(VERSION 3.6.2)
project(mukyu_cablin)

find_package(yaml-cpp REQUIRED)
if (MSVC)
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_MINSIZEREL ${CMAKE_CXX_FLAGS_MINSIZEREL})
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
add_definitions("/wd4267 /wd4244 /wd4305 /Zc:strictStrings /utf-8")
endif()

add_subdirectory(third_party/yaml-cpp)
include_directories(third_party/yaml-cpp/include)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

include_directories(${YAML_CPP_INCLUDE_DIRS})

include_directories(include)

set(CMAKE_CXX_STANDARD 17)
Expand All @@ -16,6 +23,9 @@ set(cablin_core_src
src/core/controller.cpp
"src/core/script.cpp")

set(cablin_common_src
src/common/yamlutil.cpp)

set(cablin_command_src
"src/command/factory.cpp"
"src/command/if.cpp"
Expand Down Expand Up @@ -45,12 +55,14 @@ set(cablin_package_src
add_library(cablin
${cablin_core_src}
${cablin_command_src}
${cablin_common_src}
${cablin_function_src}
${cablin_package_src}
${cablin_expr_src})

target_link_libraries(cablin
${YAML_CPP_LIBRARIES}
PRIVATE
yaml-cpp
Threads::Threads)

# ----------
Expand Down
26 changes: 3 additions & 23 deletions include/mukyu/cablin/common/yamlutil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,10 @@ inline std::optional<std::string> getSingleKey(const YAML::Node& node) {
return {};
}

inline mukyu::cablin::core::Value valueNodeToValue(
mukyu::cablin::core::ValueType type, const YAML::Node& valueNode) {
if (valueNode == nullptr) {
// return zero value of the type
return mukyu::cablin::core::Value(type);
}

switch (type) {
case mukyu::cablin::core::ValueType::BOOL:
return valueNode.as<bool>();
case mukyu::cablin::core::ValueType::FLOAT:
return valueNode.as<float>();
case mukyu::cablin::core::ValueType::INT:
return valueNode.as<int>();
case mukyu::cablin::core::ValueType::INT64:
return valueNode.as<int64_t>();
case mukyu::cablin::core::ValueType::STRING:
return valueNode.as<std::string>();
case mukyu::cablin::core::ValueType::NONE:
return {};
}
}
mukyu::cablin::core::Value valueNodeToValue(mukyu::cablin::core::ValueType type,
const YAML::Node& valueNode);


} // namespace common
} // namespace cablin
} // namespace mukyu
} // namespace mukyu
53 changes: 53 additions & 0 deletions src/common/yamlutil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <mukyu/cablin/common/yamlutil.hpp>

#include <mukyu/cablin/core/error.hpp>

#include <mukyu/cablin/core/value.hpp>

#include <yaml-cpp/yaml.h>

#include <optional>
#include <string>


namespace mukyu {
namespace cablin {
namespace common {


namespace mccore = mukyu::cablin::core;


mccore::Value valueNodeToValue(mccore::ValueType type,
const YAML::Node& valueNode) {
if (valueNode == nullptr) {
// return zero value of the type
return mccore::Value(type);
}

switch (type) {
case mccore::ValueType::BOOL:
return valueNode.as<bool>();
case mccore::ValueType::FLOAT:
return valueNode.as<float>();
case mccore::ValueType::INT:
return valueNode.as<int>();
case mccore::ValueType::INT64:
return valueNode.as<int64_t>();
case mccore::ValueType::STRING:
return valueNode.as<std::string>();
case mccore::ValueType::NONE:
return {};
}

std::string msg =
"valueNodeToValue: " + std::to_string(static_cast<int>(type)) +
" is not an value type";

throw mccore::makeParsingException(msg, valueNode.Mark());
}


} // namespace common
} // namespace cablin
} // namespace mukyu
15 changes: 2 additions & 13 deletions src/core/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ namespace core {
namespace mcpkg = mukyu::cablin::package;


namespace {


std::string removeFileExt(const std::string& filename) {
std::filesystem::path p(filename);
return p.stem();
}


} // namespace


const std::string MAINFUNCTION_NAME = "main";
const std::string YAML_FILEEXT = ".yaml";

Expand All @@ -43,7 +31,8 @@ class Script::Impl {

void addFile(const std::string& filename) {
auto stem = std::filesystem::path(filename).stem();
auto pkg = std::make_shared<mcpkg::UserPackage>(stem, filename);
auto pkg =
std::make_shared<mcpkg::UserPackage>(stem.string(), filename);
addPackage(std::move(pkg));
}

Expand Down
2 changes: 1 addition & 1 deletion src/function/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class FunctionNode::Impl {
}

private:
mccore::ValueType returnType_;
mccore::ValueType returnType_ = mccore::ValueType::NONE;
std::string name_;
std::vector<mccore::CommandPtr> body_;
std::vector<Parameter> params_;
Expand Down
7 changes: 4 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.6.2)

find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIR})
add_subdirectory(third_party/googletest)

include_directories(third_party/googletest/googletest/include)

include_directories(../include/)

Expand All @@ -24,7 +25,7 @@ add_executable(unit_tests
${cablin_test_function_src})

add_dependencies(unit_tests cablin)
target_link_libraries(unit_tests cablin ${GTEST_BOTH_LIBRARIES})
target_link_libraries(unit_tests cablin gtest gtest_main)

add_test(NAME unit_tests
COMMAND unit_tests)
1 change: 1 addition & 0 deletions tests/third_party/googletest
Submodule googletest added at 703bd9
1 change: 1 addition & 0 deletions third_party/yaml-cpp
Submodule yaml-cpp added at 9a3624

0 comments on commit 1000d70

Please sign in to comment.