conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
7.97k stars 952 forks source link

[bug] Autotools.autoreconf is incompatible between Conan 1.x and 2.x #16406

Closed uilianries closed 1 month ago

uilianries commented 1 month ago

Describe the bug

OS: Any Compiler: Any Conan Versions: 1.64.1 and 2.4.0

How to reproduce it

Having the follow piece of code:

from conan import ConanFile
from conan.tools.gnu import Autotools

class ConanRecipe(ConanFile):

...

    def build(self):
        autotools = Autotools(self)
        autotools.autoreconf()
        autotools.configure()
        autotools.make()

Now I need to pass a different script folder, because configure.ac and configure are in a sub-folder:

    autotools.autoreconf(build_script_folder=os.path.join(self.source_folder, "subfolder"))

This update works fine in Conan 2.x, but not for Conan 1.x. In Conan 1.x, the build_script_folder is not supported for Autotools.autoreconf, only args.

However, when comparing Autotools.configure, the same has build_script_folder available for both Conan 1.x and Conan 2.x.

Conan 2.x Autotools.autoreconf:

https://docs.conan.io/2/reference/tools/gnu/autotools.html#conan.tools.gnu.autotools.Autotools.autoreconf

Conan 1.x Autotools.autoreconf:

https://docs.conan.io/1/reference/conanfile/tools/gnu/autotools.html#autoreconf-self-args-none

memsharded commented 1 month ago

Thanks for reporting @uilianries

It seems that recipes in ConanCenter are fine with with chdir(self, self.source_folder):, so unless there is some other very compelling reason to change this now in Conan 1, I'd probably label this as "won't fix".

uilianries commented 1 month ago

@memsharded The with chdir is not enough because autoreconf, internally, changes to self.source_folder and it's hardcoded:

https://github.com/conan-io/conan/blob/1.64.1/conan/tools/gnu/autotools.py#L70

def autoreconf(self, args=None):
      args = args or []
      command = join_arguments(["autoreconf", self._autoreconf_args, args_to_string(args)])
      with chdir(self, self._conanfile.source_folder):
          self._conanfile.run(command)

As workaround, would need to avoid Autotools.autoreconf and use self.run instead:

chdir(self, os.path.join(self.source_folder, "subfolder")):
    self.run("autoreconf -vif")

As real case that's related, the PR involving KRB5 (Kerberos) in CCI. We need to patch autoconf.ac, then run autoreconf again.

https://github.com/conan-io/conan-center-index/pull/16074/files#diff-13f5582bdd83b943553d4d08f973204bf6ccf4f8f6df1b5ebcfdcbb081f7797aR105

memsharded commented 1 month ago

This is what I mean. Even if we target this for Conan 1.65, there is no planned date for it, until it is released, then ConanCenter upgrades, etc, might be a long time. As the workaround of running self.run("autoreconf is so simple, it sounds it is simply not worth it changing it in Conan 1.

uilianries commented 1 month ago

@memsharded

This is what I mean.

Sorry, I understood something like:

chdir(self, os.path.join(self.source_folder, "subfolder")):
    autotools = Autotools(self)
    autotools.autoreconf()

As the workaround of running self.run("autoreconf is so simple, it sounds it is simply not worth it changing it in Conan 1.

Yes, I'll be using this workaround, it's works for both Conan 1.x and 2.x

Even if we target this for Conan 1.65, there is no planned date for it.

Should we mark it as wontfix then?

memsharded commented 1 month ago

Sounds good, I'll mark this as unplanned and close it. Thanks for the feedback!