diff --git a/.ci/install.sh b/.ci/install.sh new file mode 100644 index 0000000..cf96596 --- /dev/null +++ b/.ci/install.sh @@ -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 + 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..84b8041 --- /dev/null +++ b/.ci/run.sh @@ -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 + if which pyenv > /dev/null; then + eval "$(pyenv init -)" + fi + pyenv activate conan +fi + +python build.py 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/.travis.yml b/.travis.yml new file mode 100644 index 0000000..505d1e3 --- /dev/null +++ b/.travis.yml @@ -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 + - ./.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/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..e610432 100644 --- a/conanfile.py +++ b/conanfile.py @@ -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() 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; +}