Repository: conan-io/conan
Pull request #13403 (2023-03-09 21:27:25)

ISSUE-13392: Add build scripts folder to 'autoreconf' method of 'Auto…
Changelog: (Feature): (Issue-13392) Adds an optional "build_script_folder" argument to the `autoreconf` method of the `Autotools` class. It mirrors the same argument and behavior of the `configure` method of the same class. That is, it allows one to override where the tool is run (by default it runs in the `source_folder`.

Docs: No PR -- the docs are automatically updated from the mark-up in the method documentation.


CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/conan-io/conan?pullRequest=13403) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/conan-io/conan?pullRequest=13403) before we can accept your contribution.<br/><hr/>**Gabe Black** seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please [add the email address used for this commit to your account](https://help.github.com/articles/why-are-my-commits-linked-to-the-wrong-user/#commits-are-not-linked-to-any-user).<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/conan-io/conan?pullRequest=13403) it.</sub>

Patch:
diff --git a/conan/tools/gnu/autotools.py b/conan/tools/gnu/autotools.py
index 16baf6fb7..5a1878acc 100644
--- a/conan/tools/gnu/autotools.py
+++ b/conan/tools/gnu/autotools.py
@@ -98,16 +98,20 @@ class Autotools(object):
             args.insert(0, "DESTDIR={}".format(unix_path(self._conanfile, self._conanfile.package_folder)))
         self.make(target=target, args=args)
 
-    def autoreconf(self, args=None):
+    def autoreconf(self, build_script_folder=None, args=None):
         """
         Call ``autoreconf``
 
         :param args: (Optional, Defaulted to ``None``): List of arguments to use for the
                      ``autoreconf`` call.
+        :param build_script_folder: Subfolder where the `configure` script is located. If not specified
+                                    conanfile.source_folder is used.
         """
+        script_folder = os.path.join(self._conanfile.source_folder, build_script_folder) \
+            if build_script_folder else self._conanfile.source_folder
         args = args or []
         command = join_arguments(["autoreconf", self._autoreconf_args, cmd_args_to_string(args)])
-        with chdir(self, self._conanfile.source_folder):
+        with chdir(self, script_folder):
             self._conanfile.run(command)
 
     def _use_win_mingw(self):


Test patch:
diff --git a/conans/test/unittests/tools/gnu/autotools_test.py b/conans/test/unittests/tools/gnu/autotools_test.py
index 5d882b7be..d1cafffc0 100644
--- a/conans/test/unittests/tools/gnu/autotools_test.py
+++ b/conans/test/unittests/tools/gnu/autotools_test.py
@@ -1,4 +1,5 @@
 import os
+from mock import patch
 
 from conan.tools.build import save_toolchain_args
 from conan.tools.gnu import Autotools
@@ -6,13 +7,14 @@ from conans.test.utils.mocks import ConanFileMock
 from conans.test.utils.test_files import temp_folder
 
 
-def test_source_folder_works():
+@patch('conan.tools.gnu.autotools.chdir')
+def test_source_folder_works(chdir_mock):
     folder = temp_folder()
     os.chdir(folder)
     save_toolchain_args({
         "configure_args": "-foo bar",
         "make_args": "",
-        "autoreconf_args": ""}
+        "autoreconf_args": "-bar foo"}
     )
     conanfile = ConanFileMock()
     sources = "/path/to/sources"
@@ -24,3 +26,10 @@ def test_source_folder_works():
     autotools = Autotools(conanfile)
     autotools.configure()
     assert conanfile.command.replace("\\", "/") == '"/path/to/sources/configure" -foo bar '
+
+    autotools.autoreconf(build_script_folder="subfolder")
+    chdir_mock.assert_called_with(autotools, "/path/to/sources/subfolder")
+
+    autotools.autoreconf()
+    chdir_mock.assert_called_with(autotools, "/path/to/sources")
+    assert conanfile.command.replace("\\", "/") == 'autoreconf -bar foo'