Skip to content

Commit

Permalink
BehaviorTree#2 Conan package support
Browse files Browse the repository at this point in the history
- 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
uilianries committed Nov 24, 2018
1 parent af22b2a commit 733712e
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .conan/CMakeLists.txt
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)
8 changes: 8 additions & 0 deletions .conan/appveyor/install.py
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")
88 changes: 88 additions & 0 deletions .conan/build.py
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()
22 changes: 22 additions & 0 deletions .conan/ci/install.sh
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
11 changes: 11 additions & 0 deletions .conan/test_package/CMakeLists.txt
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)
19 changes: 19 additions & 0 deletions .conan/test_package/conanfile.py
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)
68 changes: 68 additions & 0 deletions .conan/test_package/test_package.cpp
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;
}
59 changes: 59 additions & 0 deletions conanfile.py
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)

0 comments on commit 733712e

Please sign in to comment.