Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[conan] Add header-only style conan support #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .ci/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# Copyright (c) 2018 Bincrafters

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

set -ex

if [[ "$(uname -s)" == 'Darwin' ]]; then
Fohlen marked this conversation as resolved.
Show resolved Hide resolved
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 conan --upgrade
pip install conan_package_tools bincrafters_package_tools

conan user
18 changes: 18 additions & 0 deletions .ci/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# Copyright (c) 2018 Bincrafters

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

set -ex

if [[ "$(uname -s)" == 'Darwin' ]]; then
Fohlen marked this conversation as resolved.
Show resolved Hide resolved
if which pyenv > /dev/null; then
eval "$(pyenv init -)"
fi
pyenv activate conan
fi

python build.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ project/*.vcxproj.user

# Ignore build directory for tests
test/build
build/

# Ignore built examples
example/*
Expand Down
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2018 Bincrafters
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

linux: &linux
os: linux
sudo: required
language: python
python: "3.6"
services:
- docker
matrix:
include:
- <<: *linux
env: CONAN_CLANG_VERSIONS=5.0 CONAN_DOCKER_IMAGE=conanio/clang50

install:
- chmod +x .ci/install.sh
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still learning conan and travis, but it seems like it would be simpler (and less fraught with license complications) to do this without the shell scripts. Something like:

language: cpp
os: linux
dist: trusty
sudo: required
addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - g++-8
env: CC=gcc-8 CXX=g++-8
before_install: pip install conan
install: conan user
script: conan create . user/channel

But I'm probably missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory this could be done. However the xenial and trusty images comes with libstdc5 (or earlier) and it is cumbersome and error prone to upgrade to any more recent version (which is needed for C++17). Using a pre-backed docker with all the tools makes life much easier.

- ./.ci/install.sh

script:
- chmod +x .ci/run.sh
- ./.ci/run.sh
14 changes: 0 additions & 14 deletions CMakeLists.txt

This file was deleted.

10 changes: 10 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bincrafters import build_template_header_only

if __name__ == "__main__":

builder = build_template_header_only.get_builder()

builder.run()
71 changes: 47 additions & 24 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
from conans import ConanFile, CMake, tools

class GraphConan(ConanFile):
name = "Graph"
version = "0.1"
settings = "os", "compiler", "arch", "build_type"
exports_sources = "include/*", "CMakeLists.txt" #, "test/*"
no_copy_source = True

requires = "range-v3/0.4.0@ericniebler/stable"
build_requires = "Catch2/2.5.0@catchorg/stable"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
# if tools.get_env("CONAN_RUN_TESTS", True):
# cmake.test()

def package(self):
self.copy("*.h")

def package_id(self):
self.info.header_only()
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2018 Bincrafters

# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

from conans import ConanFile, tools
import os

class GraphConan(ConanFile):
name = "graph"
version = "0.1.0"
description = "Efficient, header-only graph library for C++17 with a pleasant interface."
topics = ("graph-algorithms", "generic", "graph")
url = "https://github.com/cbbowen/graph/"
homepage = "https://github.com/cbbowen/graph/"
author = "Chris Bowen"
license = "MIT"
no_copy_source = True

# Packages the license for the conanfile.py
exports = ["LICENSE.md"]

# Requirements
requires = "range-v3/0.4.0@ericniebler/stable"

# Custom attributes for Bincrafters recipe conventions
_source_subfolder = "source_subfolder"

def source(self):
source_url = "https://github.com/cbbowen/graph/"
tools.get("{0}/archive/v{1}.tar.gz".format(source_url, self.version), sha256="Please-provide-a-checksum")
extracted_dir = self.name + "-" + self.version

#Rename to "source_folder" is a convention to simplify later steps
os.rename(extracted_dir, self._source_subfolder)

def package(self):
include_folder = os.path.join(self._source_subfolder, "include")
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="include/*", dst="include", src=include_folder)

def package_id(self):
self.info.header_only()
12 changes: 12 additions & 0 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project(test_package)
cmake_minimum_required(VERSION 2.8.11)

set(CMAKE_VERBOSE_MAKEFILE TRUE)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

file(GLOB SOURCE_FILES *.cpp)

add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
19 changes: 19 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
Fohlen marked this conversation as resolved.
Show resolved Hide resolved
# -*- coding: utf-8 -*-

from conans import ConanFile, CMake, tools, RunEnvironment
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
with tools.environment_append(RunEnvironment(self).vars):
self.run(os.path.join("bin", "test_package"))
31 changes: 31 additions & 0 deletions test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <graph/Out_adjacency_list.hpp>
using namespace graph;

int main(int argc, char* argv[])
{
// Build a random graph
std::mt19937_64 random;
Out_adjacency_list g;

for (int i = 0; i < 8; ++i)
g.insert_vert();

for (int i = 0; i < 32; ++i) {
auto u = g.random_vert(random), v = g.random_vert(random);
g.insert_edge(u, v);
}

// Assign edge weights
auto weight = g.edge_map<double>();
for (auto e : g.edges())
weight[e] = std::uniform_real_distribution(1.0, 2.0)(random);

// Run Dijkstra's algorithm
auto [tree, distance] = g.shortest_paths_from(g.random_vert(random), weight);

// Output result in dot format
using namespace graph::attributes; // for `_of_vert`
std::cout << tree.dot_format("distance"_of_vert = distance) << std::endl;

return 0;
}