forked from BehaviorTree/BehaviorTree.CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BehaviorTree#2 Conan package support
- Add conan recipe for BehaviorTree.CPP - Add build script for Appveyor - Add build script for Travis CI - Add dummy test package Signed-off-by: Uilian Ries <uilianries@gmail.com>
- Loading branch information
1 parent
af22b2a
commit 733712e
Showing
8 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
project(cmake_wrapper) | ||
|
||
include(conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import os | ||
|
||
if os.getenv("APPVEYOR_REPO_TAG") != "true": | ||
print("Skip step. It's not TAG") | ||
else: | ||
os.system("pip install conan conan-package-tools") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import re | ||
from cpt.packager import ConanMultiPackager | ||
from cpt.ci_manager import CIManager | ||
from cpt.printer import Printer | ||
|
||
|
||
class BuilderSettings(object): | ||
@property | ||
def username(self): | ||
""" Set catchorg as package's owner | ||
""" | ||
return os.getenv("CONAN_USERNAME", "BehaviorTree") | ||
|
||
@property | ||
def login_username(self): | ||
""" Set Bintray login username | ||
""" | ||
return os.getenv("CONAN_LOGIN_USERNAME", "facontidavide") | ||
|
||
@property | ||
def upload(self): | ||
""" Set Catch2 repository to be used on upload. | ||
The upload server address could be customized by env var | ||
CONAN_UPLOAD. If not defined, the method will check the branch name. | ||
Only master or CONAN_STABLE_BRANCH_PATTERN will be accepted. | ||
The master branch will be pushed to testing channel, because it does | ||
not match the stable pattern. Otherwise it will upload to stable | ||
channel. | ||
""" | ||
return os.getenv("CONAN_UPLOAD", "https://api.bintray.com/conan/facontidavide/conan") | ||
|
||
@property | ||
def remotes(self): | ||
""" cppzmq is not approved on Conan center yet | ||
""" | ||
return os.getenv("CONAN_REMOTES", "https://api.bintray.com/conan/bincrafters/public-conan") | ||
|
||
@property | ||
def upload_only_when_stable(self): | ||
""" Force to upload when running over tag branch | ||
""" | ||
return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", "True").lower() in ["true", "1", "yes"] | ||
|
||
@property | ||
def stable_branch_pattern(self): | ||
""" Only upload the package the branch name is like a tag | ||
""" | ||
return os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+") | ||
|
||
@property | ||
def reference(self): | ||
""" Read project version from branch create Conan referece | ||
""" | ||
return os.getenv("CONAN_REFERENCE", "BehaviorTree.CPP/{}@{}/{}".format(self._branch, self.username, self.channel)) | ||
|
||
@property | ||
def channel(self): | ||
""" Default Conan package channel when not stable | ||
""" | ||
return os.getenv("CONAN_CHANNEL", "testing") | ||
|
||
@property | ||
def _branch(self): | ||
""" Get branch name from CI manager | ||
""" | ||
printer = Printer(None) | ||
ci_manager = CIManager(printer) | ||
return ci_manager.get_branch() | ||
|
||
|
||
if __name__ == "__main__": | ||
settings = BuilderSettings() | ||
builder = ConanMultiPackager( | ||
reference=settings.reference, | ||
channel=settings.channel, | ||
upload=settings.upload, | ||
remotes=settings.remotes, | ||
upload_only_when_stable=settings.upload_only_when_stable, | ||
stable_branch_pattern=settings.stable_branch_pattern, | ||
login_username=settings.login_username, | ||
username=settings.username, | ||
test_folder=os.path.join(".conan", "test_package")) | ||
builder.add() | ||
builder.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -x | ||
|
||
if [[ "$(uname -s)" == 'Darwin' ]]; then | ||
brew update || brew update | ||
brew outdated pyenv || brew upgrade pyenv | ||
brew install pyenv-virtualenv | ||
brew install cmake || true | ||
|
||
if which pyenv > /dev/null; then | ||
eval "$(pyenv init -)" | ||
fi | ||
|
||
pyenv install 3.7.1 | ||
pyenv virtualenv 3.7.1 conan | ||
pyenv rehash | ||
pyenv activate conan | ||
fi | ||
|
||
pip install -U conan_package_tools conan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
project(test_package CXX) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
find_package(BehaviorTree REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) | ||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import os | ||
from conans import ConanFile, CMake | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
assert os.path.isfile(os.path.join(self.deps_cpp_info["BehaviorTree.CPP"].rootpath, "licenses", "LICENSE")) | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "behaviortree_cpp/behavior_tree.h" | ||
#include "behaviortree_cpp/bt_factory.h" | ||
|
||
using namespace BT; | ||
|
||
NodeStatus SayHello() | ||
{ | ||
printf("hello\n"); | ||
return NodeStatus::SUCCESS; | ||
} | ||
|
||
class ActionTestNode : public ActionNode | ||
{ | ||
public: | ||
ActionTestNode(const std::string& name) : ActionNode(name) | ||
{ | ||
} | ||
|
||
NodeStatus tick() override | ||
{ | ||
time_ = 5; | ||
stop_loop_ = false; | ||
int i = 0; | ||
while (!stop_loop_ && i++ < time_) | ||
{ | ||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
} | ||
return NodeStatus::SUCCESS; | ||
} | ||
|
||
virtual void halt() override | ||
{ | ||
stop_loop_ = true; | ||
setStatus(NodeStatus::IDLE); | ||
} | ||
|
||
private: | ||
int time_; | ||
std::atomic_bool stop_loop_; | ||
}; | ||
|
||
int main() | ||
{ | ||
BT::SequenceNode root("root"); | ||
BT::SimpleActionNode action1("say_hello", std::bind(SayHello)); | ||
ActionTestNode action2("async_action"); | ||
|
||
root.addChild(&action1); | ||
root.addChild(&action2); | ||
|
||
int count = 0; | ||
|
||
NodeStatus status = NodeStatus::RUNNING; | ||
|
||
while (status == NodeStatus::RUNNING) | ||
{ | ||
status = root.executeTick(); | ||
|
||
std::cout << count++ << " : " << root.status() << " / " << action1.status() << " / " | ||
<< action2.status() << std::endl; | ||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
} | ||
|
||
haltAllActions(&root); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Conan recipe package for Google FlatBuffers | ||
""" | ||
from conans import ConanFile, CMake, tools | ||
|
||
|
||
class FlatbuffersConan(ConanFile): | ||
name = "BehaviorTree.CPP" | ||
license = "MIT" | ||
url = "https://github.com/BehaviorTree/BehaviorTree.CPP" | ||
author = "Davide Faconti <davide.faconti@gmail.com>" | ||
topics = ("conan", "behaviortree", "ai", "robotics", "games", "coordination") | ||
description = "This C++ library provides a framework to create BehaviorTrees. It was designed to be flexible, easy to use and fast." | ||
settings = "os", "compiler", "build_type", "arch" | ||
options = {"zmq": [True, False]} | ||
default_options = {"zmq": True} | ||
generators = "cmake" | ||
exports = "LICENSE" | ||
exports_sources = ("cmake/*", "include/*", "src/*", "3rdparty/*", "CMakeLists.txt") | ||
|
||
def requirements(self): | ||
"""Install ZMQ when required | ||
""" | ||
if self.options.zmq: | ||
self.requires("cppzmq/4.3.0@bincrafters/stable") | ||
|
||
def _configure_cmake(self): | ||
"""Create CMake instance and execute configure step | ||
""" | ||
cmake = CMake(self) | ||
cmake.definitions["BUILD_EXAMPLES"] = False | ||
cmake.definitions["BUILD_UNIT_TESTS"] = False | ||
cmake.configure() | ||
return cmake | ||
|
||
def build(self): | ||
"""Configure, build and install FlatBuffers using CMake. | ||
""" | ||
tools.replace_in_file("CMakeLists.txt", | ||
"project(behaviortree_cpp)", | ||
"""project(behaviortree_cpp) | ||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup()""") | ||
cmake = self._configure_cmake() | ||
cmake.build() | ||
|
||
def package(self): | ||
"""Copy Flatbuffers' artifacts to package folder | ||
""" | ||
self.copy(pattern="LICENSE", dst="licenses") | ||
cmake = self._configure_cmake() | ||
cmake.install() | ||
|
||
def package_info(self): | ||
"""Collect built libraries names and solve flatc path. | ||
""" | ||
self.cpp_info.libs = tools.collect_libs(self) |