Repository: conan-io/conan-center-index

Issue:
[package] ISL/0.24 lacks support for Conan 2.0 
### Description

Uses old-style imports

### Package and Environment Details

isl/0.24

### Conan profile

Any

### Steps to reproduce

conan-2.0 build -pr:b tools.jinja -pr:h tools.jinja --name isl --version 0.24 . 

### Logs

<details><summary>Click to expand log</summary>

```
conan-2.0 build -pr:b tools.jinja -pr:h tools.jinja --name isl --version 0.24 .

-------- Input profiles --------
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=8
os=Linux
[options]
cmake*:bootstrap=True
[tool_requires]
!openssl*: cmake/3.24.2

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=8
os=Linux
[options]
cmake*:bootstrap=True
[tool_requires]
!openssl*: cmake/3.24.2

ERROR: Error loading conanfile at '/tmp/tmp.UuQlL1yi0W/isl/conanfile.py': Unable to load conanfile in /tmp/tmp.UuQlL1yi0W/isl/conanfile.py
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/tmp/tmp.UuQlL1yi0W/isl/conanfile.py", line 1, in <module>
    from conans import AutoToolsBuildEnvironment, ConanFile, tools
ImportError: cannot import name 'AutoToolsBuildEnvironment' from 'conans' (/mathworks/devel/sandbox/marc/conan-2.0/conan-io/conans/__init__.py)
```

</details>



Discussion:
Will submit a fix shortly

Resolving patch:
diff --git a/recipes/isl/all/conanfile.py b/recipes/isl/all/conanfile.py
--- a/recipes/isl/all/conanfile.py
+++ b/recipes/isl/all/conanfile.py
@@ -1,9 +1,14 @@
-from conans import AutoToolsBuildEnvironment, ConanFile, tools
-from conans.errors import ConanInvalidConfiguration
-from contextlib import contextmanager
+from conan import ConanFile
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.apple import is_apple_os, fix_apple_shared_install_name
+from conan.tools.build import cross_building
+from conan.tools.files import copy, get, rm, rmdir, apply_conandata_patches, export_conandata_patches
+from conan.tools.gnu import Autotools, AutotoolsToolchain
+from conan.tools.layout import basic_layout
+from conan.tools.microsoft import is_msvc, msvc_runtime_flag, check_min_vs, unix_path, is_msvc_static_runtime
 import os
 
-required_conan_version = ">=1.33.0"
+required_conan_version = ">=1.58.0"
 
 
 class IslConan(ConanFile):
@@ -13,23 +18,24 @@ class IslConan(ConanFile):
     license = "MIT"
     homepage = "https://libisl.sourceforge.io"
     url = "https://github.com/conan-io/conan-center-index"
+
+    package_type = "library"
     settings = "os", "arch", "compiler", "build_type"
     options = {
         "shared": [True, False],
         "fPIC": [True, False],
         "with_int": ["gmp", "imath", "imath-32"],
+        "autogen": [True, False],
     }
     default_options = {
         "shared": False,
         "fPIC": True,
         "with_int": "gmp",
+        "autogen": False,
     }
 
-    _autotools = None
-
-    @property
-    def _source_subfolder(self):
-        return "source_subfolder"
+    def export_sources(self):
+        export_conandata_patches(self)
 
     def config_options(self):
         if self.settings.os == "Windows":
@@ -37,97 +43,86 @@ def config_options(self):
 
     def configure(self):
         if self.options.shared:
-            del self.options.fPIC
-        del self.settings.compiler.libcxx
-        del self.settings.compiler.cppstd
+            self.options.rm_safe("fPIC")
+        self.settings.rm_safe("compiler.libcxx")
+        self.settings.rm_safe("compiler.cppstd")
 
     def validate(self):
         if self.settings.os == "Windows" and self.options.shared:
             raise ConanInvalidConfiguration("Cannot build shared isl library on Windows (due to libtool refusing to link to static/import libraries)")
-        if self.settings.os == "Macos" and self.settings.arch == "armv8":
-            raise ConanInvalidConfiguration("Apple M1 is not yet supported. Contributions are welcome")
-        if self.options.with_int != "gmp":
-            # FIXME: missing imath recipe
-            raise ConanInvalidConfiguration("imath is not (yet) available on cci")
-        if self.settings.compiler == "Visual Studio" and tools.Version(self.settings.compiler.version) < 16 and self.settings.compiler.runtime == "MDd":
+        if is_apple_os(self) and cross_building(self):
+            raise ConanInvalidConfiguration("Cross-building with Apple Clang is not supported yet")
+        if msvc_runtime_flag(self) == "MDd" and not check_min_vs(self, 192, raise_invalid=False):
+            # isl fails to link with this version of visual studio and MDd runtime:
             # gmp.lib(bdiv_dbm1c.obj) : fatal error LNK1318: Unexpected PDB error; OK (0)
-            raise ConanInvalidConfiguration("isl fails to link with this version of visual studio and MDd runtime")
+            raise ConanInvalidConfiguration("isl cannot be built with MDd runtime with MSVC < 192")
 
     def requirements(self):
         if self.options.with_int == "gmp":
-            self.requires("gmp/6.2.1")
+            self.requires("gmp/6.3.0")
+        elif self.options.with_int == "imath":
+            self.requires("imath/3.1.9")
 
     @property
     def _settings_build(self):
         return getattr(self, "settings_build", self.settings)
 
     def build_requirements(self):
-        if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
-            self.build_requires("msys2/cci.latest")
-        if self.settings.compiler == "Visual Studio":
-            self.build_requires("automake/1.16.4")
+        if self._settings_build.os == "Windows":
+            self.win_bash = True
+            if not self.conf.get("tools.microsoft.bash:path", check_type=str):
+                self.tool_requires("msys2/cci.latest")
+        if self.options.autogen:
+            self.tool_requires("autoconf/2.71")
+            self.tool_requires("automake/1.16.5")
+            self.tool_requires("libtool/2.4.7")
+
+    def package_id(self):
+        del self.info.options.autogen
+
+    def layout(self):
+        basic_layout(self, src_folder="src")
 
     def source(self):
-        tools.get(**self.conan_data["sources"][self.version],
-                  strip_root=True, destination=self._source_subfolder)
-
-    @contextmanager
-    def _build_context(self):
-        if self.settings.compiler == "Visual Studio":
-            with tools.vcvars(self.settings):
-                env = {
-                    "AR": "{} lib".format(tools.unix_path(self.deps_user_info["automake"].ar_lib)),
-                    "CC": "{} cl -nologo -{}".format(tools.unix_path(self.deps_user_info["automake"].compile), self.settings.compiler.runtime),
-                    "CXX": "{} cl -nologo -{}".format(tools.unix_path(self.deps_user_info["automake"].compile), self.settings.compiler.runtime),
-                    "NM": "dumpbin -symbols",
-                    "OBJDUMP": ":",
-                    "RANLIB": ":",
-                    "STRIP": ":",
-                }
-                with tools.environment_append(env):
-                    yield
-        else:
-            yield
-
-    def _configure_autotools(self):
-        if self._autotools:
-            return self._autotools
-        self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
-        self._autotools.libs = []
-        yes_no = lambda v: "yes" if v else "no"
-        conf_args = [
-            "--with-int={}".format(self.options.with_int),
-            "--enable-portable-binary",
-            "--enable-shared={}".format(yes_no(self.options.shared)),
-            "--enable-static={}".format(yes_no(not self.options.shared)),
-        ]
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def generate(self):
+        tc = AutotoolsToolchain(self)
+        tc.configure_args.append(f'--with-int={self.options.with_int}')
+        tc.configure_args.append("--enable-portable-binary")
         if self.options.with_int == "gmp":
-            conf_args.extend([
-                "--with-gmp=system",
-                "--with-gmp-prefix={}".format(self.deps_cpp_info["gmp"].rootpath.replace("\\", "/")),
-            ])
-        if self.settings.compiler == "Visual Studio":
-            if tools.Version(self.settings.compiler.version) >= 15:
-                self._autotools.flags.append("-Zf")
-            if tools.Version(self.settings.compiler.version) >= 12:
-                self._autotools.flags.append("-FS")
-        self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
-        return self._autotools
+            tc.configure_args.append("--with-gmp=system")
+            tc.configure_args.append(f'--with-gmp-prefix={unix_path(self, self.dependencies["gmp"].package_folder)}')
+        if is_msvc(self):
+            if check_min_vs(self, 191, raise_invalid=False):
+                tc.extra_cflags = ["-Zf"]
+            if check_min_vs(self, 180, raise_invalid=False):
+                tc.extra_cflags = ["-FS"]
+        if is_msvc(self) and self.version == "0.24" and not is_msvc_static_runtime(self):
+            # Pass BUILD flags to avoid confusion with GCC and mixing of runtime variants
+            tc.configure_args += ['CC_FOR_BUILD=cl -nologo', f'CFLAGS_FOR_BUILD=-{msvc_runtime_flag(self)}']
+        env = tc.environment()
+        if is_msvc(self):
+            env.define("CC", "cl -nologo")
+            env.define("CXX", "cl -nologo")
+        tc.generate(env)
 
     def build(self):
-        with self._build_context():
-            autotools = self._configure_autotools()
-            autotools.make()
+        if self.options.autogen:
+            apply_conandata_patches(self) # Currently, the only patch is for the autogen use case
+            self.run("./autogen.sh", cwd=self.source_folder)
+        autotools = Autotools(self)
+        autotools.configure()
+        autotools.make()
 
     def package(self):
-        self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
-        with self._build_context():
-            autotools = self._configure_autotools()
-            autotools.install()
-
-        os.unlink(os.path.join(os.path.join(self.package_folder, "lib", "libisl.la")))
-        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+        copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses"))
+        autotools = Autotools(self)
+        autotools.install()
+        rm(self, "*.la", os.path.join(os.path.join(self.package_folder, "lib")))
+        rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
+        fix_apple_shared_install_name(self)
 
     def package_info(self):
-        self.cpp_info.names["pkg_config"] = "isl"
+        self.cpp_info.set_property("pkg_config_name", "isl")
         self.cpp_info.libs = ["isl"]


Test patch:
diff --git a/recipes/isl/all/patches/0.24-0001-fix-ac_test_cflags.patch b/recipes/isl/all/patches/0.24-0001-fix-ac_test_cflags.patch
new file mode 100644
--- /dev/null
+++ b/recipes/isl/all/patches/0.24-0001-fix-ac_test_cflags.patch
@@ -0,0 +1,11 @@
+--- m4/ax_cc_maxopt.m4
++++ m4/ax_cc_maxopt.m4
+@@ -65,7 +65,7 @@
+ 	acx_maxopt_portable=$withval, acx_maxopt_portable=no)
+
+ # Try to determine "good" native compiler flags if none specified via CFLAGS
+-if test "$ac_test_CFLAGS" != "set"; then
++if test "x$ac_test_CFLAGS" = "x"; then
+   CFLAGS=""
+   case $ax_cv_c_compiler_vendor in
+     dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host"
diff --git a/recipes/isl/all/test_package/CMakeLists.txt b/recipes/isl/all/test_package/CMakeLists.txt
--- a/recipes/isl/all/test_package/CMakeLists.txt
+++ b/recipes/isl/all/test_package/CMakeLists.txt
@@ -1,8 +1,7 @@
 cmake_minimum_required(VERSION 3.1)
 project(test_package C)
 
-include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
-conan_basic_setup()
+find_package(isl REQUIRED CONFIG)
 
 add_executable(${PROJECT_NAME} test_package.c)
-target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
+target_link_libraries(${PROJECT_NAME} PRIVATE isl::isl)
diff --git a/recipes/isl/all/test_package/conanfile.py b/recipes/isl/all/test_package/conanfile.py
--- a/recipes/isl/all/test_package/conanfile.py
+++ b/recipes/isl/all/test_package/conanfile.py
@@ -1,10 +1,19 @@
-from conans import ConanFile, CMake, tools
+from conan import ConanFile
+from conan.tools.cmake import CMake, cmake_layout
+from conan.tools.build import cross_building
 import os
 
 
 class TestPackageConan(ConanFile):
     settings = "os", "compiler", "build_type", "arch"
-    generators = "cmake"
+    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)
@@ -12,6 +21,6 @@ def build(self):
         cmake.build()
 
     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)
+        if not cross_building(self):
+            bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
+            self.run(bin_path, env="conanrun")
diff --git a/recipes/isl/all/test_v1_package/CMakeLists.txt b/recipes/isl/all/test_v1_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/isl/all/test_v1_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package C)
+
+include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} ../test_package/test_package.c)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
diff --git a/recipes/isl/all/test_v1_package/conanfile.py b/recipes/isl/all/test_v1_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/isl/all/test_v1_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+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):
+        if not tools.cross_building(self.settings):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)