From 50ae67998c585f4a200497980ca0cb0e9f4f0679 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 24 Sep 2022 13:43:47 +0200 Subject: [PATCH 1/4] conan v2 support --- recipes/odbc/all/conandata.yml | 1 - recipes/odbc/all/conanfile.py | 124 ++++++++++-------- recipes/odbc/all/test_package/CMakeLists.txt | 7 +- recipes/odbc/all/test_package/conanfile.py | 28 ++-- .../odbc/all/test_v1_package/CMakeLists.txt | 10 ++ recipes/odbc/all/test_v1_package/conanfile.py | 18 +++ 6 files changed, 113 insertions(+), 75 deletions(-) create mode 100644 recipes/odbc/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/odbc/all/test_v1_package/conanfile.py diff --git a/recipes/odbc/all/conandata.yml b/recipes/odbc/all/conandata.yml index df25a82c0ba11..13f25bfa16be5 100644 --- a/recipes/odbc/all/conandata.yml +++ b/recipes/odbc/all/conandata.yml @@ -12,4 +12,3 @@ sources: patches: "2.3.7": - patch_file: "patches/missing-declarations.patch" - base_path: "source_subfolder" diff --git a/recipes/odbc/all/conanfile.py b/recipes/odbc/all/conanfile.py index 52f93e639c109..fb078c5ec6cf8 100644 --- a/recipes/odbc/all/conanfile.py +++ b/recipes/odbc/all/conanfile.py @@ -1,10 +1,12 @@ -from conans import ConanFile, AutoToolsBuildEnvironment, tools -from conans.errors import ConanInvalidConfiguration -import functools +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rm, rmdir +from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.layout import basic_layout import os import shutil -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.52.0" class OdbcConan(ConanFile): @@ -27,84 +29,98 @@ class OdbcConan(ConanFile): "with_libiconv": True, } - @property - def _source_subfolder(self): - return "source_subfolder" - @property def _user_info_build(self): return getattr(self, "user_info_build", self.deps_user_info) def export_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + export_conandata_patches(self) def configure(self): if self.options.shared: - del self.options.fPIC - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + try: + del self.options.fPIC + except Exception: + pass + try: + del self.settings.compiler.cppstd + except Exception: + pass + try: + del self.settings.compiler.libcxx + except Exception: + pass + + def layout(self): + basic_layout(self, src_folder="src") def requirements(self): + self.requires("libtool/2.4.7") if self.options.with_libiconv: self.requires("libiconv/1.17") def validate(self): - if self.settings.os == "Windows": + if self.info.settings.os == "Windows": raise ConanInvalidConfiguration("odbc is a system lib on Windows") def build_requirements(self): - self.build_requires("gnu-config/cci.20201022") + self.tool_requires("gnu-config/cci.20210814") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) + + def generate(self): + tc = AutotoolsToolchain(self) + yes_no = lambda v: "yes" if v else "no" + tc.configure_args.extend([ + "--without-included-ltdl", + f"--with-ltdl-include={self.dependencies['libtool'].cpp_info.includedirs[0]}", + f"--with-ltdl-lib={self.dependencies['libtool'].cpp_info.libdirs[0]}", + "--disable-ltdl-install", + f"--enable-iconv={yes_no(self.options.with_libiconv)}", + "--sysconfdir=/etc", + ]) + if self.options.with_libiconv: + libiconv_prefix = self.dependencies["libiconv"].package_folder + tc.configure_args.append(f"--with-libiconv-prefix={libiconv_prefix}") + tc.generate() def _patch_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) + apply_conandata_patches(self) + # support more triplets shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB, - os.path.join(self._source_subfolder, "config.sub")) + os.path.join(self.source_folder, "config.sub")) shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS, - os.path.join(self._source_subfolder, "config.guess")) + os.path.join(self.source_folder, "config.guess")) + # allow external libtdl (in libtool recipe) + replace_in_file( + self, + os.path.join(self.source_folder, "configure"), + "if test -f \"$with_ltdl_lib/libltdl.la\";", + "if true;", + ) # relocatable shared libs on macOS for configure in [ - os.path.join(self._source_subfolder, "configure"), - os.path.join(self._source_subfolder, "libltdl", "configure"), + os.path.join(self.source_folder, "configure"), + os.path.join(self.source_folder, "libltdl", "configure"), ]: - tools.replace_in_file(configure, "-install_name \\$rpath/", "-install_name @rpath/") - - @functools.lru_cache(1) - def _configure_autotools(self): - autotools = AutoToolsBuildEnvironment(self) - autotools.libs = [] - yes_no = lambda v: "yes" if v else "no" - args = [ - "--enable-shared={}".format(yes_no(self.options.shared)), - "--enable-static={}".format(yes_no(not self.options.shared)), - "--enable-ltdl-install", - "--enable-iconv={}".format(yes_no(self.options.with_libiconv)), - "--sysconfdir=/etc", - ] - if self.options.with_libiconv: - libiconv_prefix = self.deps_cpp_info["libiconv"].rootpath - args.append("--with-libiconv-prefix={}".format(libiconv_prefix)) - autotools.configure(configure_dir=self._source_subfolder, args=args) - return autotools + replace_in_file(self, configure, "-install_name \\$rpath/", "-install_name @rpath/") def build(self): self._patch_sources() - autotools = self._configure_autotools() + autotools = Autotools(self) + autotools.configure() autotools.make() def package(self): - self.copy("COPYING", src=self._source_subfolder, dst="licenses") - autotools = self._configure_autotools() + copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + autotools = Autotools(self) autotools.install() - tools.rmdir(os.path.join(self.package_folder, "share")) - tools.rmdir(os.path.join(self.package_folder, "etc")) - tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") + rmdir(self, os.path.join(self.package_folder, "share")) + rmdir(self, os.path.join(self.package_folder, "etc")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + rm(self, "*.la", os.path.join(self.package_folder, "lib")) def package_info(self): self.cpp_info.set_property("cmake_find_mode", "both") @@ -119,26 +135,24 @@ def package_info(self): # odbc self.cpp_info.components["_odbc"].set_property("pkg_config_name", "odbc") self.cpp_info.components["_odbc"].libs = ["odbc"] - self.cpp_info.components["_odbc"].requires = ["odbcltdl"] + self.cpp_info.components["_odbc"].requires = ["libtool::libtool"] if self.options.with_libiconv: self.cpp_info.components["_odbc"].requires.append("libiconv::libiconv") # odbcinst self.cpp_info.components["odbcinst"].set_property("pkg_config_name", "odbcinst") self.cpp_info.components["odbcinst"].libs = ["odbcinst"] - self.cpp_info.components["odbcinst"].requires = ["odbcltdl"] + self.cpp_info.components["odbcinst"].requires = ["libtool::libtool"] # odbccr self.cpp_info.components["odbccr"].set_property("pkg_config_name", "odbccr") self.cpp_info.components["odbccr"].libs = ["odbccr"] - self.cpp_info.components["odbcltdl"].libs = ["ltdl"] - if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.components["_odbc"].system_libs = ["pthread"] self.cpp_info.components["odbcinst"].system_libs = ["pthread"] - self.cpp_info.components["odbcltdl"].system_libs = ["dl"] + # TODO: to remove in conan v2 bin_path = os.path.join(self.package_folder, "bin") - 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) diff --git a/recipes/odbc/all/test_package/CMakeLists.txt b/recipes/odbc/all/test_package/CMakeLists.txt index 5250e0988835b..7079befc5a173 100644 --- a/recipes/odbc/all/test_package/CMakeLists.txt +++ b/recipes/odbc/all/test_package/CMakeLists.txt @@ -1,10 +1,7 @@ cmake_minimum_required(VERSION 3.1) -project(test_package C) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) +project(test_package LANGUAGES C) find_package(ODBC REQUIRED) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} ODBC::ODBC) +target_link_libraries(${PROJECT_NAME} PRIVATE ODBC::ODBC) diff --git a/recipes/odbc/all/test_package/conanfile.py b/recipes/odbc/all/test_package/conanfile.py index 620e449c0ca6b..1278841f61298 100644 --- a/recipes/odbc/all/test_package/conanfile.py +++ b/recipes/odbc/all/test_package/conanfile.py @@ -1,19 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" - def build_requirements(self): - if self.settings.os == "Macos" and self.settings.arch == "armv8": - # Workaround for CMake bug with error message: - # Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being - # set. This could be because you are using a Mac OS X version less than 10.5 - # or because CMake's platform configuration is corrupt. - # FIXME: Remove once CMake on macOS/M1 CI runners is upgraded. - self.build_requires("cmake/3.22.0") + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -21,7 +21,7 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) - self.run("odbcinst --version", run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") + self.run("odbcinst --version", env="conanrun") diff --git a/recipes/odbc/all/test_v1_package/CMakeLists.txt b/recipes/odbc/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..f2decbd539e08 --- /dev/null +++ b/recipes/odbc/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package LANGUAGES C) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(ODBC REQUIRED) + +add_executable(${PROJECT_NAME} ../test_package/test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE ODBC::ODBC) diff --git a/recipes/odbc/all/test_v1_package/conanfile.py b/recipes/odbc/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..dfa9a73cae43c --- /dev/null +++ b/recipes/odbc/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + 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("bin", "test_package") + self.run(bin_path, run_environment=True) + self.run("odbcinst --version", run_environment=True) From 6b754cac0fb356b24786ed8d6aafffa8a01a8e17 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 24 Sep 2022 14:19:02 +0200 Subject: [PATCH 2/4] handle system libs deps of libltdl --- recipes/odbc/all/conanfile.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/recipes/odbc/all/conanfile.py b/recipes/odbc/all/conanfile.py index fb078c5ec6cf8..febbf1708b217 100644 --- a/recipes/odbc/all/conanfile.py +++ b/recipes/odbc/all/conanfile.py @@ -100,6 +100,14 @@ def _patch_sources(self): "if test -f \"$with_ltdl_lib/libltdl.la\";", "if true;", ) + libtool_system_libs = self.dependencies["libtool"].cpp_info.system_libs + if libtool_system_libs: + replace_in_file( + self, + os.path.join(self.source_folder, "configure"), + "-L$with_ltdl_lib -lltdl", + "-L$with_ltdl_lib -lltdl -l{}".format(" -l".join(libtool_system_libs)), + ) # relocatable shared libs on macOS for configure in [ os.path.join(self.source_folder, "configure"), From 0dee22e41ac80c99b0eda66919416fb4089ffbf7 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Sat, 24 Sep 2022 16:11:52 +0200 Subject: [PATCH 3/4] fix ODR violation between odbc & odbccr --- recipes/odbc/all/conandata.yml | 5 ++++- .../all/patches/0001-duplicated-get-connection.patch | 11 +++++++++++ ...arations.patch => 0002-missing-declarations.patch} | 0 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 recipes/odbc/all/patches/0001-duplicated-get-connection.patch rename recipes/odbc/all/patches/{missing-declarations.patch => 0002-missing-declarations.patch} (100%) diff --git a/recipes/odbc/all/conandata.yml b/recipes/odbc/all/conandata.yml index 13f25bfa16be5..89d795f5cbf07 100644 --- a/recipes/odbc/all/conandata.yml +++ b/recipes/odbc/all/conandata.yml @@ -10,5 +10,8 @@ sources: - "http://www.unixodbc.net/unixODBC-2.3.7.tar.gz" sha256: "45f169ba1f454a72b8fcbb82abd832630a3bf93baa84731cf2949f449e1e3e77" patches: + "2.3.9": + - patch_file: "patches/0001-duplicated-get-connection.patch" "2.3.7": - - patch_file: "patches/missing-declarations.patch" + - patch_file: "patches/0001-duplicated-get-connection.patch" + - patch_file: "patches/0002-missing-declarations.patch" diff --git a/recipes/odbc/all/patches/0001-duplicated-get-connection.patch b/recipes/odbc/all/patches/0001-duplicated-get-connection.patch new file mode 100644 index 0000000000000..4357214d44a8d --- /dev/null +++ b/recipes/odbc/all/patches/0001-duplicated-get-connection.patch @@ -0,0 +1,11 @@ +--- a/cur/SQLGetDiagRec.c ++++ b/cur/SQLGetDiagRec.c +@@ -101,8 +101,4 @@ SQLRETURN CLGetDiagRec( SQLSMALLINT handle_type, + text_length_ptr); + } + +-DMHDBC __get_connection( EHEAD * head ) +-{ +- return 0; +-} + diff --git a/recipes/odbc/all/patches/missing-declarations.patch b/recipes/odbc/all/patches/0002-missing-declarations.patch similarity index 100% rename from recipes/odbc/all/patches/missing-declarations.patch rename to recipes/odbc/all/patches/0002-missing-declarations.patch From 9d9dbcc9c5a52ec7a9a1070144abe09428a75e29 Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 28 Sep 2022 17:24:27 +0200 Subject: [PATCH 4/4] fix duplicated symbol in 2.3.11 --- recipes/odbc/all/conandata.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/odbc/all/conandata.yml b/recipes/odbc/all/conandata.yml index 8fc8aefc5a504..d79ee7fbfc269 100644 --- a/recipes/odbc/all/conandata.yml +++ b/recipes/odbc/all/conandata.yml @@ -15,6 +15,8 @@ sources: - "http://www.unixodbc.net/unixODBC-2.3.7.tar.gz" sha256: "45f169ba1f454a72b8fcbb82abd832630a3bf93baa84731cf2949f449e1e3e77" patches: + "2.3.11": + - patch_file: "patches/0001-duplicated-get-connection.patch" "2.3.9": - patch_file: "patches/0001-duplicated-get-connection.patch" "2.3.7":