Skip to content

Commit

Permalink
(#14011) Add Canary recipe - wrapper over the SocketCAN API
Browse files Browse the repository at this point in the history
* Add Canary recipe - wrapper over the SocketCAN API

* Add test_v1_package

* Silence warning about the empty build()

* Validate c++11 requirement

* Validate c++11 requirement

* Fix missing import

* Fix missing imports

* Use new imports

* Canary only supports Linux

* Update recipes/canary/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/canary/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/canary/all/test_package/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/canary/all/test_package/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/canary/all/test_v1_package/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Fix missing imports

* Remove compiler check, since the recipe is only for Linux

* Update recipes/canary/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Fix test binary path

* Update recipes/canary/all/conandata.yml

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/canary/config.yml

Co-authored-by: Chris Mc <[email protected]>

* Revert "Update recipes/canary/config.yml"

This reverts commit d57647f.

* Revert "Update recipes/canary/all/conandata.yml"

This reverts commit 82c6c41.

* Add missing upstream component

* Update recipes/canary/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Use original version tag

Co-authored-by: Chris Mc <[email protected]>
  • Loading branch information
klimkin and prince-chrismc authored Nov 29, 2022
1 parent 113e38a commit 7113f33
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/canary/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"v1":
url: "https://github.com/djarek/canary/archive/refs/tags/v1.tar.gz"
sha256: "f3e2e80f5c01b4d60aed4b5ec73663158b495caa4f9324a10d05e55ea8f3938c"
61 changes: 61 additions & 0 deletions recipes/canary/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain
from conan.tools.files import copy, get, rmdir

required_conan_version = ">=1.53.0"


class SocketcanCanaryConan(ConanFile):
name = "canary"
description = "A lightweight implementation of Linux SocketCAN bindings for ASIO/Boost.ASIO"
url = "https://github.com/conan-io/conan-center-index"
license = "BSL-1.0"
homepage = "https://github.com/djarek/canary"
topics = ("socketcan", "can-bus", "can")

settings = "os", "compiler", "build_type", "arch"
no_copy_source = True

@property
def _min_cppstd(self):
return 11

def validate(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration(f"{self.ref} only supports Linux.")
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)

def requirements(self):
self.requires("boost/1.74.0", transitive_headers=True)

def source(self):
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
pass

def package(self):
copy(self, "LICENSE_1_0.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.configure()
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib"))

def package_id(self):
self.info.clear()

def package_info(self):
self.cpp_info.requires = ["boost::headers", "boost::system"]
self.cpp_info.set_property("cmake_file_name", "canary")
self.cpp_info.set_property("cmake_target_name", "canary::canary")
8 changes: 8 additions & 0 deletions recipes/canary/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

find_package(canary REQUIRED)

add_executable(test_package test_package.cpp)
target_link_libraries(test_package PUBLIC canary::canary)
target_compile_features(test_package PRIVATE cxx_std_11)
27 changes: 27 additions & 0 deletions recipes/canary/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout


class TestPackage(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
15 changes: 15 additions & 0 deletions recipes/canary/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <iostream>
#include <canary/interface_index.hpp>

int main()
{
try {
auto index = canary::get_interface_index("vcan0");
std::cout << "vcan0 interface index: " << index << "\n";
}
catch (std::exception& exc) {
std::cout << "unable to find vcan0: " << exc.what() << "\n";
}

return 0;
}
8 changes: 8 additions & 0 deletions recipes/canary/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

find_package(canary REQUIRED)

add_executable(test_package test_package.cpp)
target_link_libraries(test_package PUBLIC canary::canary)
target_compile_features(test_package PRIVATE cxx_std_11)
18 changes: 18 additions & 0 deletions recipes/canary/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

from conans import CMake, ConanFile, tools


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

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join(".", "test_package")
self.run(bin_path, run_environment=True)
15 changes: 15 additions & 0 deletions recipes/canary/all/test_v1_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <iostream>
#include <canary/interface_index.hpp>

int main()
{
try {
auto index = canary::get_interface_index("vcan0");
std::cout << "vcan0 interface index: " << index << "\n";
}
catch (std::exception& exc) {
std::cout << "unable to find vcan0: " << exc.what() << "\n";
}

return 0;
}
3 changes: 3 additions & 0 deletions recipes/canary/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"v1":
folder: all

0 comments on commit 7113f33

Please sign in to comment.