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

ignition-tools: migrate to Conan v2 #19074

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
9 changes: 0 additions & 9 deletions recipes/ignition-tools/all/CMakeLists.txt

This file was deleted.

6 changes: 1 addition & 5 deletions recipes/ignition-tools/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
sources:
"1.4.0":
url: "https://github.com/ignitionrobotics/ign-tools/archive/refs/tags/ignition-tools_1.4.0.tar.gz"
sha256: "fa3f7984ebb8f412133ea93368395adce426ae36c715a9f94f9509af7dac3b03"
patches:
"1.4.0":
- base_path: "source_subfolder"
patch_file: "patches/0003-ign-tools-1.4.0-cmake-fixes.patch"
sha256: "8ceebefcd1977dc2e26beede347a9c06d851b89ec0fd7d5c86126f43a49ac178"
147 changes: 83 additions & 64 deletions recipes/ignition-tools/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import os
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.29.1"
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, cmake_layout
from conan.tools.files import copy, get, rm, rmdir, replace_in_file, load, save
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class IgnitionToolsConan(ConanFile):
name = "ignition-tools"
description = "Ignition entry point for using all the suite of ignition tools."
license = "Apache-2.0"
homepage = "https://ignitionrobotics.org/libs/tools"
url = "https://github.com/conan-io/conan-center-index"
description = "Provides general purpose classes and functions designed for robotic applications.."
topics = ("ignition", "robotics", "tools")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
generators = "cmake", "cmake_find_package_multi"
exports_sources = "CMakeLists.txt", "patches/**"
_cmake = None
homepage = "https://ignitionrobotics.org/libs/tools"
topics = ("ignition", "robotics", "tools", "gazebo")

package_type = "application"
valgur marked this conversation as resolved.
Show resolved Hide resolved
settings = "os", "arch", "compiler", "build_type"

@property
def _minimum_cpp_standard(self):
Expand All @@ -27,79 +29,96 @@ def _minimum_cpp_standard(self):
def _minimum_compilers_version(self):
return {
"Visual Studio": "16",
"msvc": "192",
"gcc": "7",
"clang": "5",
"apple-clang": "10",
}

@property
def _source_subfolder(self):
return "source_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def layout(self):
cmake_layout(self, src_folder="src")

def configure(self):
if self.options.shared:
del self.options.fPIC
def requirements(self):
self.requires("backward-cpp/1.6")
valgur marked this conversation as resolved.
Show resolved Hide resolved

def validate(self):
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, self._minimum_cpp_standard)
check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if not min_version:
self.output.warn(
"{} recipe lacks information about the {} compiler support.".format(
self.name, self.settings.compiler
)
if min_version and Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
f"{self.name} requires c++17 support. "
f"The current compiler {self.settings.compiler} {self.settings.compiler.version} does not support it."
)
else:
if tools.Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
"{} requires c++17 support. The current compiler {} {} does not support it.".format(
self.name,
self.settings.compiler,
self.settings.compiler.version,
)
)

def source(self):
tools.get(**self.conan_data["sources"][self.version],destination=self._source_subfolder, strip_root=True)
def build_requirements(self):
# FIXME: Ruby is required as a transitive dependency for the `ign` Ruby script
# FIXME: The ign script has additional Ruby dependencies
# self.tool_requires("ruby/3.1.0")
pass

def _configure_cmake(self):
if self._cmake is not None:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_TESTING"] = False
self._cmake.configure()
return self._cmake
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["USE_SYSTEM_BACKWARDCPP"] = True
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.variables["BUILD_TESTING"] = False
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def _patch_sources(self):
for cmakelists in self.source_path.rglob("CMakeLists.txt"):
replace_in_file(self, cmakelists, "${CMAKE_SOURCE_DIR}", "${PROJECT_SOURCE_DIR}", strict=False)
replace_in_file(self, cmakelists, "${CMAKE_BINARY_DIR}", "${PROJECT_BINARY_DIR}", strict=False)
# Generating ign.rb fails on Windows, do it outside of CMake in package() instead
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
"# Two steps to create `ign`", "return() #")

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

@staticmethod
def _chmod_plus_x(filename):
if os.name == "posix":
os.chmod(filename, os.stat(filename).st_mode | 0o111)

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)

cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

# Generate ign.rb
ign_rb_content = load(self, os.path.join(self.source_folder, "src", "ign.in"))
# FIXME: this is not relocatable
ign_rb_content = ign_rb_content.replace("@CMAKE_INSTALL_PREFIX@", self.package_folder.replace("\\", "/"))
ign_rb_content = ign_rb_content.replace("@ENV_PATH_DELIMITER@", os.pathsep)
suffix = ".rb" if self.settings.os == "Windows" else ""
ign_rb_path = os.path.join(self.package_folder, "bin", f"ign{suffix}")
save(self, ign_rb_path, ign_rb_content)
self._chmod_plus_x(ign_rb_path)

rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

# Remove MS runtime files
for dll_pattern_to_remove in ["concrt*.dll", "msvcp*.dll", "vcruntime*.dll"]:
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), dll_pattern_to_remove)
rm(self, dll_pattern_to_remove, os.path.join(self.package_folder, "bin"), recursive=True)

def package_info(self):
version_major = tools.Version(self.version).major
self.cpp_info.names["cmake_find_package"] = "ignition-tools{}".format(version_major)
self.cpp_info.names["cmake_find_package_multi"] = "ignition-tools{}".format(version_major)

self.cpp_info.components["libignition-tools"].libs = ["ignition-tools-backward"]
self.cpp_info.components["libignition-tools"].includedirs.append("include/ignition/tools{}".format(version_major))
self.cpp_info.components["libignition-tools"].names["cmake_find_package"] = "ignition-tools{}".format(version_major)
self.cpp_info.components["libignition-tools"].names["cmake_find_package_multi"] = "ignition-tools{}".format(version_major)
self.cpp_info.components["libignition-tools"].names["pkg_config"] = "ignition-tools{}".format(version_major)
self.cpp_info.includedirs = []
self.cpp_info.libdirs = []

# The package builds an ignition-tools-backward wrapper library,
# but it's only meant to be used as a runtime dependency of the ign script

# TODO: Legacy, to be removed on Conan 2.0
bin_folder = os.path.join(self.package_folder, "bin")
self.env_info.PATH.append(bin_folder)

This file was deleted.

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions recipes/ignition-tools/all/test_package/CMakeLists.txt

This file was deleted.

28 changes: 16 additions & 12 deletions recipes/ignition-tools/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from conans import ConanFile, CMake, tools
import os
from conan import ConanFile
from conan.tools.layout import basic_layout


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

def requirements(self):
self.requires(self.tested_reference_str, run=True)

def build(self):
cmake = CMake(self)
cmake.definitions["IGN_TOOLS_MAJOR_VER"] = tools.Version(self.deps_cpp_info["ignition-tools"].version).major
cmake.configure()
cmake.build()
def layout(self):
basic_layout(self)

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
# FIXME: Can't actually run this since Ruby and required Ruby gems are not set up
if self.settings.os == "Windows":
self.run("where ign", scope="conanrun")
else:
self.run("which ign", scope="conanrun")
7 changes: 0 additions & 7 deletions recipes/ignition-tools/all/test_package/test_package.cpp

This file was deleted.