Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit acaac99

Browse files
uilianriesfacontidavide
authored andcommitted
Conan package distribution (BehaviorTree#39)
1 parent 7f862d0 commit acaac99

File tree

8 files changed

+277
-5
lines changed

8 files changed

+277
-5
lines changed

.travis.yml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@ os:
1111
compiler:
1212
- gcc
1313

14+
conan-linux: &conan-linux
15+
os: linux
16+
dist: xenial
17+
language: python
18+
python: "3.7"
19+
services:
20+
- docker
21+
before_install:
22+
- true
23+
install:
24+
- ./conan/travis/install.sh
25+
script:
26+
- ./conan/travis/build.sh
27+
28+
conan-osx: &conan-osx
29+
os: osx
30+
language: generic
31+
before_install:
32+
- true
33+
install:
34+
- ./conan/travis/install.sh
35+
script:
36+
- ./conan/travis/build.sh
37+
1438
matrix:
1539
include:
1640
- bare_linux:
@@ -21,10 +45,38 @@ matrix:
2145
env: ROS_DISTRO="kinetic"
2246
- ros_melodic:
2347
env: ROS_DISTRO="melodic"
48+
- <<: *conan-linux
49+
env: CONAN_GCC_VERSIONS=5 CONAN_DOCKER_IMAGE=conanio/gcc5
50+
- <<: *conan-linux
51+
env: CONAN_GCC_VERSIONS=6 CONAN_DOCKER_IMAGE=conanio/gcc6
52+
- <<: *conan-linux
53+
env: CONAN_GCC_VERSIONS=7 CONAN_DOCKER_IMAGE=conanio/gcc7
54+
- <<: *conan-linux
55+
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
56+
- <<: *conan-linux
57+
env: CONAN_CLANG_VERSIONS=3.9 CONAN_DOCKER_IMAGE=conanio/clang39
58+
- <<: *conan-linux
59+
env: CONAN_CLANG_VERSIONS=4.0 CONAN_DOCKER_IMAGE=conanio/clang40
60+
- <<: *conan-linux
61+
env: CONAN_CLANG_VERSIONS=5.0 CONAN_DOCKER_IMAGE=conanio/clang50
62+
- <<: *conan-linux
63+
env: CONAN_CLANG_VERSIONS=6.0 CONAN_DOCKER_IMAGE=conanio/clang60
64+
- <<: *conan-osx
65+
osx_image: xcode8.3
66+
env: CONAN_APPLE_CLANG_VERSIONS=8.1
67+
- <<: *conan-osx
68+
osx_image: xcode9
69+
env: CONAN_APPLE_CLANG_VERSIONS=9.0
70+
- <<: *conan-osx
71+
osx_image: xcode9.4
72+
env: CONAN_APPLE_CLANG_VERSIONS=9.1
73+
- <<: *conan-osx
74+
osx_image: xcode10.1
75+
env: CONAN_APPLE_CLANG_VERSIONS=10.0
2476
fast_finish: false
2577

2678
before_install:
27-
- sudo apt-get update && sudo apt-get --reinstall install -qq build-essential
79+
- sudo apt-get update && sudo apt-get --reinstall install -qq build-essential
2880
- if [ "$ROS_DISTRO" = "none" ]; then sudo apt-get --reinstall install -qq libzmq3-dev; fi
2981
# GTest: see motivation here https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
3082
- sudo apt-get --reinstall install -qq libgtest-dev cmake
@@ -40,7 +92,7 @@ install:
4092
before_script:
4193
# Prepare build directory
4294
- mkdir -p build
43-
95+
4496
script:
4597
- if [ "$ROS_DISTRO" = "none" ]; then (cd build; cmake .. ; sudo cmake --build . --target install; ./bin/behaviortree_cpp_test); fi
4698
- if [ "$ROS_DISTRO" != "none" ]; then (.ci_config/travis.sh); fi

conan/build.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
import re
6+
from cpt.packager import ConanMultiPackager
7+
from cpt.ci_manager import CIManager
8+
from cpt.printer import Printer
9+
10+
11+
class BuilderSettings(object):
12+
13+
@property
14+
def branch(self):
15+
""" Get branch name
16+
"""
17+
printer = Printer(None)
18+
ci_manager = CIManager(printer)
19+
return ci_manager.get_branch()
20+
21+
@property
22+
def username(self):
23+
""" Set BehaviorTree as package's owner
24+
"""
25+
return os.getenv("CONAN_USERNAME", "BehaviorTree")
26+
27+
@property
28+
def upload(self):
29+
""" Set BehaviorTree repository to be used on upload.
30+
The upload server address could be customized by env var
31+
CONAN_UPLOAD. If not defined, the method will check the branch name.
32+
Only master or CONAN_STABLE_BRANCH_PATTERN will be accepted.
33+
The master branch will be pushed to testing channel, because it does
34+
not match the stable pattern. Otherwise it will upload to stable
35+
channel.
36+
"""
37+
if os.getenv("CONAN_UPLOAD", None) is not None:
38+
return os.getenv("CONAN_UPLOAD")
39+
40+
prog = re.compile(self.stable_branch_pattern)
41+
if self.branch and prog.match(self.branch):
42+
return "https://api.bintray.com/conan/BehaviorTree/conan"
43+
44+
return None
45+
46+
@property
47+
def upload_only_when_stable(self):
48+
""" Force to upload when match stable pattern branch
49+
"""
50+
return os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
51+
52+
@property
53+
def stable_branch_pattern(self):
54+
""" Only upload the package the branch name is like a tag
55+
"""
56+
return os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"\d+\.\d+\.\d+")
57+
58+
@property
59+
def version(self):
60+
return self.branch if re.match(self.stable_branch_pattern, self.branch) else "latest"
61+
62+
@property
63+
def reference(self):
64+
""" Read project version from branch name to create Conan referece
65+
"""
66+
return os.getenv("CONAN_REFERENCE", "BehaviorTree.CPP/{}".format(self.version))
67+
68+
if __name__ == "__main__":
69+
settings = BuilderSettings()
70+
builder = ConanMultiPackager(
71+
reference=settings.reference,
72+
username=settings.username,
73+
upload=settings.upload,
74+
upload_only_when_stable=settings.upload_only_when_stable,
75+
stable_branch_pattern=settings.stable_branch_pattern,
76+
test_folder=os.path.join("conan", "test_package"))
77+
builder.add_common_builds(pure_c=False)
78+
builder.run()

conan/test_package/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project(test_package CXX)
2+
cmake_minimum_required(VERSION 2.8.11)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup()
6+
7+
add_executable(${PROJECT_NAME} test_package.cpp)
8+
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
9+
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

conan/test_package/conanfile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
import os
4+
from conans import ConanFile, CMake
5+
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "compiler", "build_type", "arch"
9+
generators = "cmake"
10+
11+
def build(self):
12+
cmake = CMake(self)
13+
cmake.configure()
14+
cmake.build()
15+
16+
def test(self):
17+
assert os.path.isfile(os.path.join(self.deps_cpp_info["BehaviorTree.CPP"].rootpath, "licenses", "LICENSE"))
18+
bin_path = os.path.join("bin", "test_package")
19+
self.run(bin_path, run_environment=True)

conan/test_package/test_package.cpp

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "behaviortree_cpp/behavior_tree.h"
2+
#include "behaviortree_cpp/bt_factory.h"
3+
4+
using namespace BT;
5+
6+
NodeStatus SayHello()
7+
{
8+
printf("hello\n");
9+
return NodeStatus::SUCCESS;
10+
}
11+
12+
class ActionTestNode : public ActionNode
13+
{
14+
public:
15+
ActionTestNode(const std::string& name) : ActionNode(name)
16+
{
17+
}
18+
19+
NodeStatus tick() override
20+
{
21+
time_ = 5;
22+
stop_loop_ = false;
23+
int i = 0;
24+
while (!stop_loop_ && i++ < time_)
25+
{
26+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
27+
}
28+
return NodeStatus::SUCCESS;
29+
}
30+
31+
virtual void halt() override
32+
{
33+
stop_loop_ = true;
34+
setStatus(NodeStatus::IDLE);
35+
}
36+
37+
private:
38+
int time_;
39+
std::atomic_bool stop_loop_;
40+
};
41+
42+
int main()
43+
{
44+
BT::SequenceNode root("root");
45+
BT::SimpleActionNode action1("say_hello", std::bind(SayHello));
46+
ActionTestNode action2("async_action");
47+
48+
root.addChild(&action1);
49+
root.addChild(&action2);
50+
51+
int count = 0;
52+
53+
NodeStatus status = NodeStatus::RUNNING;
54+
55+
while (status == NodeStatus::RUNNING)
56+
{
57+
status = root.executeTick();
58+
59+
std::cout << count++ << " : " << root.status() << " / " << action1.status() << " / "
60+
<< action2.status() << std::endl;
61+
62+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
63+
}
64+
65+
haltAllActions(&root);
66+
67+
return 0;
68+
}

conan/travis/build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -x
5+
6+
if [[ "$(uname -s)" == 'Darwin' ]]; then
7+
if which pyenv > /dev/null; then
8+
eval "$(pyenv init -)"
9+
fi
10+
pyenv activate conan
11+
fi
12+
13+
conan user
14+
python conan/build.py

conan/travis/install.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
if [[ "$(uname -s)" == 'Darwin' ]]; then
6+
brew update || brew update
7+
brew outdated pyenv || brew upgrade pyenv
8+
brew install pyenv-virtualenv
9+
brew install cmake || true
10+
11+
if which pyenv > /dev/null; then
12+
eval "$(pyenv init -)"
13+
fi
14+
15+
pyenv install 3.7.1
16+
pyenv virtualenv 3.7.1 conan
17+
pyenv rehash
18+
pyenv activate conan
19+
fi
20+
21+
pip install -U conan_package_tools conan

conanfile.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"""Conan recipe package for BehaviorTree.CPP
55
"""
66
from conans import ConanFile, CMake, tools
7+
from conans.model.version import Version
8+
from conans.errors import ConanInvalidConfiguration
79

810

911
class BehaviorTreeConan(ConanFile):
@@ -19,10 +21,15 @@ class BehaviorTreeConan(ConanFile):
1921
generators = "cmake"
2022
exports = "LICENSE"
2123
exports_sources = ("cmake/*", "include/*", "src/*", "3rdparty/*", "CMakeLists.txt")
24+
requires = "cppzmq/4.3.0@bincrafters/stable"
2225

23-
def requirements(self):
24-
25-
self.requires("cppzmq/4.3.0@bincrafters/stable")
26+
def configure(self):
27+
if self.settings.os == "Linux" and \
28+
self.settings.compiler == "gcc" and \
29+
Version(self.settings.compiler.version.value) < "5":
30+
raise ConanInvalidConfiguration("BehaviorTree.CPP can not be built by GCC < 5")
31+
if self.settings.os == "Windows":
32+
raise ConanInvalidConfiguration("BehaviorTree.CPP is not prepared to be built on Windows yet")
2633

2734
def _configure_cmake(self):
2835
"""Create CMake instance and execute configure step
@@ -41,6 +48,10 @@ def build(self):
4148
"""project(behaviortree_cpp)
4249
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
4350
conan_basic_setup()""")
51+
# INFO (uilian): zmq could require libsodium
52+
tools.replace_in_file("CMakeLists.txt",
53+
"BEHAVIOR_TREE_EXTERNAL_LIBRARIES zmq",
54+
"BEHAVIOR_TREE_EXTERNAL_LIBRARIES ${CONAN_LIBS}")
4455
cmake = self._configure_cmake()
4556
cmake.build()
4657

0 commit comments

Comments
 (0)