From 9c61a198d4fbab57163c29d19595e5d76824feca Mon Sep 17 00:00:00 2001 From: Lennard Berger Date: Wed, 9 Jan 2019 13:05:02 +0100 Subject: [PATCH 1/3] [conan] Add header-only style conan support --- .ci/install.sh | 24 +++++++++++++ .ci/run.sh | 12 +++++++ .github/settings.yml | 42 ++++++++++++++++++++++ .travis.yml | 19 ++++++++++ CMakeLists.txt | 14 -------- appveyor.yml | 19 ++++++++++ build.py | 10 ++++++ conanfile.py | 65 ++++++++++++++++++++++------------- test_package/CMakeLists.txt | 12 +++++++ test_package/conanfile.py | 19 ++++++++++ test_package/test_package.cpp | 31 +++++++++++++++++ 11 files changed, 229 insertions(+), 38 deletions(-) create mode 100644 .ci/install.sh create mode 100644 .ci/run.sh create mode 100644 .github/settings.yml create mode 100644 .travis.yml delete mode 100644 CMakeLists.txt create mode 100644 appveyor.yml create mode 100644 build.py create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py create mode 100644 test_package/test_package.cpp diff --git a/.ci/install.sh b/.ci/install.sh new file mode 100644 index 0000000..6902fe5 --- /dev/null +++ b/.ci/install.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -ex + +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 conan --upgrade +pip install conan_package_tools bincrafters_package_tools + +conan user diff --git a/.ci/run.sh b/.ci/run.sh new file mode 100644 index 0000000..3e39a35 --- /dev/null +++ b/.ci/run.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -ex + +if [[ "$(uname -s)" == 'Darwin' ]]; then + if which pyenv > /dev/null; then + eval "$(pyenv init -)" + fi + pyenv activate conan +fi + +python build.py diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..7aff5e2 --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,42 @@ +repository: + # See https://developer.github.com/v3/repos/#edit for all available settings. + + # Either `true` to enable issues for this repository, `false` to disable them. + has_issues: false + + # Either `true` to enable the wiki for this repository, `false` to disable it. + has_wiki: false + + # Either `true` to enable the wiki for this repository, `false` to disable it. + has_projects: false + +branches: + - name: "stable/*" + # https://developer.github.com/v3/repos/branches/#update-branch-protection + # Branch Protection settings. Set to null to disable + protection: + # Required. Require at least one approving review on a pull request, before merging. Set to null to disable. + required_pull_request_reviews: + # The number of approvals required. (1-6) + required_approving_review_count: 1 + # Dismiss approved reviews automatically when a new commit is pushed. + dismiss_stale_reviews: false + # Blocks merge until code owners have reviewed. + require_code_owner_reviews: false + # Specify which users and teams can dismiss pull request reviews. Pass an empty dismissal_restrictions object to disable. User and team dismissal_restrictions are only available for organization-owned repositories. Omit this parameter for personal repositories. + dismissal_restrictions: + users: [] + teams: [] + + # Required. Require status checks to pass before merging. Set to null to disable + required_status_checks: + # Required. Require branches to be up to date before merging. + strict: true + # Required. The list of status checks to require in order to merge into this branch + contexts: [] + # Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable. + enforce_admins: false + # Required. Restrict who can push to this branch. Team and user restrictions are only available for organization-owned repositories. Set to null to disable. + restrictions: + users: [] + teams: [] diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a7c45b6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +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 + - ./.ci/install.sh + +script: + - chmod +x .ci/run.sh + - ./.ci/run.sh diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index cd710cb..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -project(Graph CXX) -cmake_minimum_required(VERSION 3.1) - -# include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -# conan_basic_setup() - -include_directories("include") - -# enable_testing() -# add_executable(all_tests test/main.cpp test/Adjacency_list.cpp test/Atomic_adjacency_list.cpp test/Dot_format.cpp test/Edge_list.cpp test/Stable_adjacency_list.cpp test/Stable_edge_list.cpp test/Stable_node_list.cpp) -# add_test( -# NAME all_tests -# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin -# COMMAND example) \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..b0befae --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,19 @@ +build: false + +environment: + PYTHON: "C:\\Python27" + PYTHON_VERSION: "2.7.15" + PYTHON_ARCH: "32" + + matrix: + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + CONAN_VISUAL_VERSIONS: 15 + +install: + - set PATH=%PYTHON%;%PYTHON%/Scripts/;%PATH% + - pip.exe install conan --upgrade + - pip.exe install conan_package_tools bincrafters_package_tools + - conan user # It creates the conan data directory + +test_script: + - python build.py diff --git a/build.py b/build.py new file mode 100644 index 0000000..8d99e06 --- /dev/null +++ b/build.py @@ -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() diff --git a/conanfile.py b/conanfile.py index 990f524..8a0c27a 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,24 +1,41 @@ -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 -*- + +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 = "Christian 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() diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..9027c08 --- /dev/null +++ b/test_package/CMakeLists.txt @@ -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}) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..1a17054 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python +# -*- 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")) diff --git a/test_package/test_package.cpp b/test_package/test_package.cpp new file mode 100644 index 0000000..197e220 --- /dev/null +++ b/test_package/test_package.cpp @@ -0,0 +1,31 @@ +#include +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(); + 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; +} From 983b6eb478913cdf6f3b5ceb56069b5bd3eb5c4c Mon Sep 17 00:00:00 2001 From: Lennard Berger Date: Fri, 18 Jan 2019 11:16:50 +0100 Subject: [PATCH 2/3] Cleanup CI PR - remove uneccesary GitHub settings - remove AppVeyor for now since MSVC cannot build this - add copyright notice where needed - adjust author --- .ci/install.sh | 6 ++++++ .ci/run.sh | 6 ++++++ .github/settings.yml | 42 ------------------------------------------ .gitignore | 1 + appveyor.yml | 19 ------------------- conanfile.py | 8 +++++++- 6 files changed, 20 insertions(+), 62 deletions(-) delete mode 100644 .github/settings.yml delete mode 100644 appveyor.yml diff --git a/.ci/install.sh b/.ci/install.sh index 6902fe5..cf96596 100644 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -1,5 +1,11 @@ #!/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 diff --git a/.ci/run.sh b/.ci/run.sh index 3e39a35..84b8041 100644 --- a/.ci/run.sh +++ b/.ci/run.sh @@ -1,5 +1,11 @@ #!/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 diff --git a/.github/settings.yml b/.github/settings.yml deleted file mode 100644 index 7aff5e2..0000000 --- a/.github/settings.yml +++ /dev/null @@ -1,42 +0,0 @@ -repository: - # See https://developer.github.com/v3/repos/#edit for all available settings. - - # Either `true` to enable issues for this repository, `false` to disable them. - has_issues: false - - # Either `true` to enable the wiki for this repository, `false` to disable it. - has_wiki: false - - # Either `true` to enable the wiki for this repository, `false` to disable it. - has_projects: false - -branches: - - name: "stable/*" - # https://developer.github.com/v3/repos/branches/#update-branch-protection - # Branch Protection settings. Set to null to disable - protection: - # Required. Require at least one approving review on a pull request, before merging. Set to null to disable. - required_pull_request_reviews: - # The number of approvals required. (1-6) - required_approving_review_count: 1 - # Dismiss approved reviews automatically when a new commit is pushed. - dismiss_stale_reviews: false - # Blocks merge until code owners have reviewed. - require_code_owner_reviews: false - # Specify which users and teams can dismiss pull request reviews. Pass an empty dismissal_restrictions object to disable. User and team dismissal_restrictions are only available for organization-owned repositories. Omit this parameter for personal repositories. - dismissal_restrictions: - users: [] - teams: [] - - # Required. Require status checks to pass before merging. Set to null to disable - required_status_checks: - # Required. Require branches to be up to date before merging. - strict: true - # Required. The list of status checks to require in order to merge into this branch - contexts: [] - # Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable. - enforce_admins: false - # Required. Restrict who can push to this branch. Team and user restrictions are only available for organization-owned repositories. Set to null to disable. - restrictions: - users: [] - teams: [] diff --git a/.gitignore b/.gitignore index b2eb8d0..6ce35b5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ project/*.vcxproj.user # Ignore build directory for tests test/build +build/ # Ignore built examples example/* diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index b0befae..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,19 +0,0 @@ -build: false - -environment: - PYTHON: "C:\\Python27" - PYTHON_VERSION: "2.7.15" - PYTHON_ARCH: "32" - - matrix: - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - CONAN_VISUAL_VERSIONS: 15 - -install: - - set PATH=%PYTHON%;%PYTHON%/Scripts/;%PATH% - - pip.exe install conan --upgrade - - pip.exe install conan_package_tools bincrafters_package_tools - - conan user # It creates the conan data directory - -test_script: - - python build.py diff --git a/conanfile.py b/conanfile.py index 8a0c27a..e610432 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,6 +1,12 @@ #!/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 @@ -11,7 +17,7 @@ class GraphConan(ConanFile): topics = ("graph-algorithms", "generic", "graph") url = "https://github.com/cbbowen/graph/" homepage = "https://github.com/cbbowen/graph/" - author = "Christian Bowen" + author = "Chris Bowen" license = "MIT" no_copy_source = True From 83f58242c2f6478eff67459e1cfcb9c4e1270ef6 Mon Sep 17 00:00:00 2001 From: Lennard Berger Date: Fri, 18 Jan 2019 11:27:59 +0100 Subject: [PATCH 3/3] Forgot to add copyright to Travis config --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index a7c45b6..505d1e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,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. + linux: &linux os: linux sudo: required