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

nmos-cpp/cci.20221203: new release and conan v2 migration #14553

Merged
merged 1 commit into from
Dec 5, 2022
Merged
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
10 changes: 0 additions & 10 deletions recipes/nmos-cpp/all/CMakeLists.txt

This file was deleted.

42 changes: 28 additions & 14 deletions recipes/nmos-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
sources:
# see https://github.com/conan-io/conan-center-index/blob/master/docs/faqs.md#what-version-should-packages-use-for-libraries-without-official-releases
"cci.20210902":
url: "https://github.com/sony/nmos-cpp/archive/d3a8c7935f80ce5de6d4727c307ddcef667b5d57.tar.gz"
sha256: "f5bd0b96542810ac1ed3ebaf7237d7471f3c42e68d966ae8b2d39db2601a38f9"
"cci.20211015":
url: "https://github.com/sony/nmos-cpp/archive/d115866f8f1d2c1c55bb64d05d34aa7d61c039e3.tar.gz"
sha256: "74e48497d6d7cc76a97b5a6331f88a58b2c96ce2f24b78176d3631051caceb6a"
"cci.20220120":
url: "https://github.com/sony/nmos-cpp/archive/46750381f33d19ce6b12a2f760db2f2f5faf2818.tar.gz"
sha256: "cd6fd81b1a5a10fd0a917fec362aae517a72f13889ec4418c29beb3ec8996df7"
"cci.20220208":
url: "https://github.com/sony/nmos-cpp/archive/7ca64c4fb5604fb8a3e0c05db2e8f8ffe7ef3857.tar.gz"
sha256: "751e7a35501cdada0e3943dcfd23a4e4f5caa02661d7f961204e8f9fea567c42"
"cci.20221203":
url: "https://github.com/sony/nmos-cpp/archive/0fb6b51737f737ae011cbcc39cdfb2c5236ec59f.tar.gz"
sha256: "9e811b2707afe084c4470fcaa5664f57468fd03e86b1eebd03ec9216cf31cac1"
"cci.20220620":
url: "https://github.com/sony/nmos-cpp/archive/3a904a3fcc39057a8db74656a697f0d97d8a3651.tar.gz"
sha256: "49a16ad5c8b1cf45cd519b96c880340b369a737c6814f8c533fff1cf49439fda"
"cci.20220428":
url: "https://github.com/sony/nmos-cpp/archive/07b8742d5e3413c903a0b0e74d0c87a76e9ecdfa.tar.gz"
sha256: "be305ea343822f0aa76376955b7adcbf61807b2fe54084c067daa837ef37b0cd"
"cci.20220208":
url: "https://github.com/sony/nmos-cpp/archive/7ca64c4fb5604fb8a3e0c05db2e8f8ffe7ef3857.tar.gz"
sha256: "751e7a35501cdada0e3943dcfd23a4e4f5caa02661d7f961204e8f9fea567c42"
"cci.20220120":
url: "https://github.com/sony/nmos-cpp/archive/46750381f33d19ce6b12a2f760db2f2f5faf2818.tar.gz"
sha256: "cd6fd81b1a5a10fd0a917fec362aae517a72f13889ec4418c29beb3ec8996df7"
patches:
"cci.20220620":
url: "https://github.com/sony/nmos-cpp/archive/3a904a3fcc39057a8db74656a697f0d97d8a3651.tar.gz"
sha256: "49a16ad5c8b1cf45cd519b96c880340b369a737c6814f8c533fff1cf49439fda"
- patch_file: "patches/cmakedeps-targets.patch"
patch_type: "conan"
patch_description: "Fix upstream/CMakeDeps target names"
"cci.20220428":
- patch_file: "patches/cmakedeps-targets.patch"
patch_type: "conan"
patch_description: "Fix upstream/CMakeDeps target names"
"cci.20220208":
- patch_file: "patches/cmakedeps-targets.patch"
patch_type: "conan"
patch_description: "Fix upstream/CMakeDeps target names"
"cci.20220120":
- patch_file: "patches/cmakedeps-targets.patch"
patch_type: "conan"
patch_description: "Fix upstream/CMakeDeps target names"
111 changes: 57 additions & 54 deletions recipes/nmos-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools import build, files
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
import json
import os
import re
from conans import ConanFile, CMake, tools

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.52.0"

class NmosCppConan(ConanFile):
name = "nmos-cpp"
Expand All @@ -25,23 +28,10 @@ class NmosCppConan(ConanFile):
"with_dnssd": "mdnsresponder",
}

# wrapper CMakeLists.txt to call conan_basic_setup()
exports_sources = ["CMakeLists.txt"]
# use cmake_find_package_multi and prefer config-file packages
generators = "cmake", "cmake_find_package_multi"

short_paths = True

_cmake = None

# for out-of-source build, cf. wrapper CMakeLists.txt
@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"
def export_sources(self):
files.export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -56,11 +46,13 @@ def config_options(self):

def requirements(self):
# for now, consistent with project's conanfile.txt
self.requires("boost/1.79.0")
self.requires("boost/1.80.0")
self.requires("cpprestsdk/2.10.18")
self.requires("websocketpp/0.8.2")
self.requires("openssl/1.1.1o")
self.requires("json-schema-validator/2.1.0")
self.requires("openssl/1.1.1s")
self.requires("json-schema-validator/2.2.0")
self.requires("nlohmann_json/3.11.2")
self.requires("zlib/1.2.13")

if self.options.get_safe("with_dnssd") == "mdnsresponder":
self.requires("mdnsresponder/878.200.35")
Expand All @@ -73,57 +65,65 @@ def requirements(self):

def build_requirements(self):
# nmos-cpp needs CMake 3.17 or higher but CCI doesn't allow version ranges
self.build_requires("cmake/3.23.2")
self.build_requires("cmake/3.24.2")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
if self.info.settings.os in ["Macos"]:
raise ConanInvalidConfiguration(f"{self.ref} is not currently supported on {self.info.settings.os}. Contributions welcomed.")
if self.info.settings.compiler.get_safe("cppstd"):
build.check_min_cppstd(self, 11)

def package_id(self):
self.info.requires["boost"].minor_mode()
self.info.requires["nlohmann_json"].patch_mode()

def layout(self):
cmake_layout(self, src_folder="src")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
files.get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
files.rm(self, "conanfile.txt", os.path.join(self.source_folder, "Development"))

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
def generate(self):
tc = CMakeToolchain(self)
# prefer config-file packages created by cmake_find_package_multi
# over any system-installed find-module packages
self._cmake.definitions["CMAKE_FIND_PACKAGE_PREFER_CONFIG"] = True
tc.cache_variables["CMAKE_FIND_PACKAGE_PREFER_CONFIG"] = True
# disable cmake-conan, consume conan packages in local cache to avoid incompatible requirements
# between this recipe and project's conanfile.txt
tc.cache_variables["CONAN_EXPORTED"] = True
# (on Linux) select Avahi or mDNSResponder
self._cmake.definitions["NMOS_CPP_USE_AVAHI"] = self.options.get_safe("with_dnssd") == "avahi"
tc.variables["NMOS_CPP_USE_AVAHI"] = self.options.get_safe("with_dnssd") == "avahi"
# (on Windows) use the Conan package for DNSSD (mdnsresponder), not the project's own DLL stub library
self._cmake.definitions["NMOS_CPP_USE_BONJOUR_SDK"] = True
tc.variables["NMOS_CPP_USE_BONJOUR_SDK"] = True
# no need to build unit tests
self._cmake.definitions["NMOS_CPP_BUILD_TESTS"] = False
tc.variables["NMOS_CPP_BUILD_TESTS"] = False
# the examples (nmos-cpp-registry and nmos-cpp-node) are useful utilities for users
self._cmake.definitions["NMOS_CPP_BUILD_EXAMPLES"] = True
# out-of-source build
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
tc.variables["NMOS_CPP_BUILD_EXAMPLES"] = True
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = self._configure_cmake()
files.apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure(build_script_folder="Development")
cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
files.copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
cmake_folder = os.path.join(self.package_folder, "lib", "cmake")
self._create_components_file_from_cmake_target_file(os.path.join(cmake_folder, "nmos-cpp", "nmos-cpp-targets.cmake"))
# remove the project's own generated config-file package
tools.rmdir(cmake_folder)
files.rmdir(self, cmake_folder)

# based on abseil recipe
# see https://github.com/conan-io/conan-center-index/blob/master/recipes/abseil/all/conanfile.py
def _create_components_file_from_cmake_target_file(self, target_file_path):
components = {}

target_content = tools.load(target_file_path)
target_content = files.load(self, target_file_path)

cmake_functions = re.findall(r"(?P<func>add_library|set_target_properties)[\n|\s]*\([\n|\s]*(?P<args>[^)]*)\)", target_content)
for (cmake_function_name, cmake_function_args) in cmake_functions:
Expand Down Expand Up @@ -162,21 +162,22 @@ def _create_components_file_from_cmake_target_file(self, target_file_path):
match_private = re.fullmatch(r"\$<LINK_ONLY:(.+)>", dependency)
if match_private:
dependency = match_private.group(1)
if "::" in dependency:
# target dependencies can be treated fairly consistently
if "::" in dependency or dependency in ["nlohmann_json_schema_validator"]:
dependency = dependency.replace("nmos-cpp::", "")
# Conan component name cannot be the same as the package name
if dependency == "nmos-cpp":
dependency = "nmos-cpp-lib"
# Conan packages for Boost, cpprestsdk, websocketpp, OpenSSL and Avahi have component names that (except for being lowercase) match the CMake targets
# json-schema-validator overrides cmake_find_package[_multi] names
elif dependency == "nlohmann_json_schema_validator::nlohmann_json_schema_validator":
# json-schema-validator overrides cmake_find_package[_multi] names and v2 cmake_target_name
elif dependency == "nlohmann_json_schema_validator":
dependency = "json-schema-validator::json-schema-validator"
# mdnsresponder overrides cmake_find_package[_multi] names
elif dependency == "DNSSD::DNSSD":
dependency = "mdnsresponder::mdnsresponder"
components[component_name].setdefault("requires" if not match_private else "requires_private", []).append(dependency.lower())
elif "${_IMPORT_PREFIX}/lib/" in dependency:
self.output.warn("{} recipe does not handle {} {} (yet)".format(self.name, property_type, dependency))
self.output.warn(f"{self.name} recipe does not handle {property_type} {dependency} (yet)")
else:
components[component_name].setdefault("system_libs", []).append(dependency)
elif property_type == "INTERFACE_COMPILE_DEFINITIONS":
Expand All @@ -185,7 +186,7 @@ def _create_components_file_from_cmake_target_file(self, target_file_path):
elif property_type == "INTERFACE_COMPILE_FEATURES":
for property_value in property_values:
if property_value not in ["cxx_std_11"]:
self.output.warn("{} recipe does not handle {} {} (yet)".format(self.name, property_type, property_value))
self.output.warn(f"{self.name} recipe does not handle {property_type} {property_value} (yet)")
elif property_type == "INTERFACE_COMPILE_OPTIONS":
for property_value in property_values:
# handle forced include (Visual Studio /FI, gcc -include) by relying on includedirs containing "include"
Expand All @@ -194,7 +195,7 @@ def _create_components_file_from_cmake_target_file(self, target_file_path):
elif property_type == "INTERFACE_INCLUDE_DIRECTORIES":
for property_value in property_values:
if property_value not in ["${_IMPORT_PREFIX}/include"]:
self.output.warn("{} recipe does not handle {} {} (yet)".format(self.name, property_type, property_value))
self.output.warn(f"{self.name} recipe does not handle {property_type} {property_value} (yet)")
elif property_type == "INTERFACE_LINK_OPTIONS":
for property_value in property_values:
# workaround required because otherwise "/ignore:4099" gets converted to "\ignore:4099.obj"
Expand All @@ -206,10 +207,10 @@ def _create_components_file_from_cmake_target_file(self, target_file_path):
property_value = re.sub(r"^/", r"-", property_value)
components[component_name].setdefault("linkflags", []).append(property_value)
else:
self.output.warn("{} recipe does not handle {} (yet)".format(self.name, property_type))
self.output.warn(f"{self.name} recipe does not handle {property_type} (yet)")

# Save components informations in json file
with open(self._components_helper_filepath, "w") as json_file:
with open(self._components_helper_filepath, "w", encoding="utf-8") as json_file:
json.dump(components, json_file, indent=4)

@property
Expand All @@ -224,9 +225,11 @@ def package_info(self):
config_install_dir = "Debug" if self.settings.build_type == "Debug" else "Release"
bindir = os.path.join(bindir, config_install_dir)
libdir = os.path.join(libdir, config_install_dir)
self.cpp_info.bindirs = [bindir]
self.cpp_info.libdirs = [libdir]

def _register_components():
components_json_file = tools.load(self._components_helper_filepath)
components_json_file = files.load(self, self._components_helper_filepath)
components = json.loads(components_json_file)
for component_name, values in components.items():
cmake_target = values["cmake_target"]
Expand All @@ -249,5 +252,5 @@ def _register_components():

# add nmos-cpp-registry and nmos-cpp-node to the path
bin_path = os.path.join(self.package_folder, bindir)
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.output.info(f"Appending PATH environment variable: {bin_path}")
self.env_info.PATH.append(bin_path)
20 changes: 20 additions & 0 deletions recipes/nmos-cpp/all/patches/cmakedeps-targets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- a/Development/cmake/NmosCppDependencies.cmake
+++ b/Development/cmake/NmosCppDependencies.cmake
@@ -197,7 +197,7 @@
endif()

add_library(json_schema_validator INTERFACE)
- target_link_libraries(json_schema_validator INTERFACE nlohmann_json_schema_validator::nlohmann_json_schema_validator)
+ target_link_libraries(json_schema_validator INTERFACE nlohmann_json_schema_validator)
else()
set(JSON_SCHEMA_VALIDATOR_SOURCES
third_party/nlohmann/json-patch.cpp
@@ -264,7 +264,7 @@
message(STATUS "Found Avahi version " ${Avahi_VERSION})
endif()

- target_link_libraries(DNSSD INTERFACE Avahi::compat-libdns_sd)
+ target_link_libraries(DNSSD INTERFACE avahi::compat-libdns_sd)
else()
find_package(DNSSD REQUIRED)
if(NOT DNSSD_VERSION)
14 changes: 6 additions & 8 deletions recipes/nmos-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
cmake_minimum_required(VERSION 3.1)
project(NmosCppTestPackage CXX)
cmake_minimum_required(VERSION 3.8)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package CXX)

find_package(nmos-cpp REQUIRED)
find_package(nmos-cpp REQUIRED CONFIG)

add_executable(test_package main.cpp)
target_link_libraries(test_package nmos-cpp::compile-settings nmos-cpp::nmos-cpp)
set_target_properties(test_package PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE nmos-cpp::compile-settings nmos-cpp::nmos-cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
33 changes: 22 additions & 11 deletions recipes/nmos-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os
import shutil
import subprocess
from six import StringIO
from conans import ConanFile, CMake, tools


class NmosCppTestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
# use cmake_find_package_multi because the project installs a config-file package
generators = "cmake", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "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 not tools.cross_building(self):
with open("registry-config.json", "w") as config:
if can_run(self):
with open("registry-config.json", "w", encoding="utf-8") as config:
config.write('{"http_port": 10000, "domain": "local.", "pri": 51967}')
with open("node-config.json", "w") as config:
with open("node-config.json", "w", encoding="utf-8") as config:
config.write('{"http_port": 20000, "domain": "local.", "highest_pri": 51967, "lowest_pri": 51967}')

# start up the installed nmos-cpp-registry to check it works
registry = subprocess.Popen(["nmos-cpp-registry", "registry-config.json"],
# find and start up the installed nmos-cpp-registry to check it works
registry_path = shutil.which("nmos-cpp-registry", path=os.pathsep.join(self.env["PATH"]))
registry = subprocess.Popen([registry_path, "registry-config.json"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)

# run the test_package node which should have time to register and then exit
node_out = StringIO()
try:
bin_path = os.path.join("bin", "test_package")
self.run(bin_path + " node-config.json", run_environment=True, output=node_out)
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path + " node-config.json", env="conanrun", output=node_out)
finally:
registry.terminate()
if "Adopting registered operation" not in node_out.getvalue():
Expand Down
8 changes: 8 additions & 0 deletions recipes/nmos-cpp/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.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Loading