From c1c8ebfb8bb635234d4c4c188a9bda1599782bdf Mon Sep 17 00:00:00 2001
From: MADELA Patrick <patrick.madela@synchrotron-soleil.fr>
Date: Thu, 6 Apr 2023 12:06:33 +0200
Subject: [PATCH] Update for Conan 2.x

---
 .gitlab-ci.yml |  9 ++++----
 conanfile.py   | 59 +++++++++++++++++++-------------------------------
 2 files changed, 27 insertions(+), 41 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 19ddb58..613dc61 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,12 +23,13 @@ workflow:
     - rm python.zip
     - export PATH=$(readlink -e .)/python-${PYTHON_VERSION}-${PLATFORM}/bin:${PATH}
     - python --version | grep ${PYTHON_VERSION}
-    - sudo python -m pip install --upgrade pip 
-    - sudo python -m pip install --upgrade conan 
+    - python -m pip install --upgrade pip 
+    - python -m pip install --upgrade conan 
     # Build git with conan
     - conan profile detect --force
-    - conan create . --name git --version ${GIT_VERSION} --user soleil --channel stable -s compiler.libcxx=libstdc++11 --build="*"  -c tools.system.package_manager:mode=install -c tools.system.package_manager:tool=yum -c tools.system.package_manager:sudo=True
-    - conan install --name git --version ${GIT_VERSION} --user soleil --channel stable -s compiler.libcxx=libstdc++11 --install-folder ${CI_PROJECT_DIR}/${NAME}
+    - conan create . --version ${GIT_VERSION} -s compiler.libcxx=libstdc++11 --build="*" 
+    - conan install --requires git/${GIT_VERSION} -s compiler.libcxx=libstdc++11 --deploy direct_deploy
+    - mv git ${CI_PROJECT_DIR}/${NAME}
   artifacts:
     name: ${NAME}
     paths:
diff --git a/conanfile.py b/conanfile.py
index 106c0a2..be326c3 100644
--- a/conanfile.py
+++ b/conanfile.py
@@ -1,21 +1,20 @@
 from conan import ConanFile
 from conan.tools.system import package_manager
+from conan.tools.gnu import AutotoolsDeps
+from conan.tools.gnu import AutotoolsToolchain
+from conan.tools.gnu import Autotools
+from conan.tools.files import replace_in_file
 from conan.errors import ConanInvalidConfiguration
-from conans import AutoToolsBuildEnvironment, RunEnvironment, tools
 import os
 
-
-class GitConan(ConanFile):
+class GitRecipe(ConanFile):
     name = "git"
-    version = "2.40.0"
 
     settings = "os", "compiler", "build_type", "arch"
 
-    requires = \
-        "libcurl/7.86.0", \
-        "zlib/1.2.13"
+    requires = "libcurl/7.86.0", "zlib/1.2.13"
 
-    _autotools = None
+    build_requires = "libcurl/7.86.0"
 
     _autotools_args = [
         "NO_TCLTK=YesPlease",
@@ -32,43 +31,29 @@ class GitConan(ConanFile):
             raise ConanInvalidConfiguration("This recipe supports only Linux")
 
     def source(self):
-        self.run(
-            "curl -s -L -O https://github.com/git/git/archive/refs/tags/v%s.tar.gz" % self.version)
+        self.run("curl -s -L -O https://github.com/git/git/archive/refs/tags/v%s.tar.gz" % self.version)
         self.run("tar -xzf v%s.tar.gz --strip 1" % self.version)
 
-    def _build_configure(self):
-        if self._autotools:
-            return self._autotools
-
-        self._autotools = AutoToolsBuildEnvironment(self)
-
-        args = [
-            "--enable-pthreads=-pthread",
-            "--with-tcltk=NO",
-        ]
-
-        # Append run environment to autotools environment to have curl-config in path
-        env_build_vars = self._autotools.vars
-        run_environment = RunEnvironment(self)
-        env_build_vars = env_build_vars | run_environment.vars
+    def generate(self):
+        td = AutotoolsDeps(self)
+        td.generate()
+        tc = AutotoolsToolchain(self)
+        tc.configure_args.append("--enable-pthreads=-pthread")
+        tc.configure_args.append("--with-tcltk=NO")
+        tc.generate()
 
+    def build(self):
         # Build configure
         self.run("make configure")
 
-        self._autotools.configure(args=args, vars=env_build_vars)
-        return self._autotools
-
-    def build(self):
-        env_build = self._build_configure()
-        tools.replace_in_file("Makefile", "EXTLIBS += -lrt", "EXTLIBS += -lrt -ldl")
-        env_build.make(args=self._autotools_args)
+        autotools = Autotools(self)
+        autotools.configure()
+        replace_in_file(self, "Makefile", "EXTLIBS += -lrt", "EXTLIBS += -lrt -ldl")
+        autotools.make(args=self._autotools_args)
 
     def package(self):
-        env_build = self._build_configure()
-        env_build.install(args=self._autotools_args)
+        autotools = Autotools(self)
+        autotools.install(args=self._autotools_args)
 
     def package_info(self):
         self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
-
-    def deploy(self):
-        self.copy("*", symlinks=True) 
-- 
GitLab