Repository: spack/spack

Issue:
Autotools packages: modify ACLOCAL_PATH to build dependent packages
closes #19258 

gettext has m4 files for aclocal (for example, gettext.m4, iconv.m4).
But gettext package dose not set ACLOCAL_PATH.
This PR set ACLOCAL_PATH.


Discussion:
It might make more sense to put this in `etc/spack/defaults/modules.yaml` so it is set for all packages that have that directory. We do something similar in the `AutotoolsPackage.autoreconf` method where we search for that directory in all dependency packages.
> 
> 
> It might make more sense to put this in `etc/spack/defaults/modules.yaml` so it is set for all packages that have that directory. We do something similar in the `AutotoolsPackage.autoreconf` method where we search for that directory in all dependency packages.

The package replace autoreconf (For example audacious) dose not search that directory.
So I change in Autoreconf package.

@tkameyama I had a better look at the context, and it seems we already have something similar (as @adamjstewart pointed out) in `AutotoolsPackage.autoreconf`:

https://github.com/spack/spack/blob/8edb31e934e38a7f0f1b6c7a6da42ac1a7dd9591/lib/spack/spack/build_systems/autotools.py#L264-L270

That change was introduced in #15784 with the only difference that it's using the `-I` option to extend the macro search paths instead of the `ACLOCAL_PATH` environment variable. Before merging the PR I want to double check with you why this duplication is needed. Is there some reproducible use case where the `-I` approach doesn't work but `ACLOCAL_PATH` does?
> 
> 
> @tkameyama I had a better look at the context, and it seems we already have something similar (as @adamjstewart pointed out) in `AutotoolsPackage.autoreconf`:
> 
> https://github.com/spack/spack/blob/8edb31e934e38a7f0f1b6c7a6da42ac1a7dd9591/lib/spack/spack/build_systems/autotools.py#L264-L270
> 
> That change was introduced in #15784 with the only difference that it's using the `-I` option to extend the macro search paths instead of the `ACLOCAL_PATH` environment variable. Before merging the PR I want to double check with you why this duplication is needed. Is there some reproducible use case where the `-I` approach doesn't work but `ACLOCAL_PATH` does?

Please check audacious (sorry you may need fix #18884)
audacious cannot use this function, because audacious use own autoreconf.

Resolving patch:
diff --git a/lib/spack/spack/build_systems/autotools.py b/lib/spack/spack/build_systems/autotools.py
--- a/lib/spack/spack/build_systems/autotools.py
+++ b/lib/spack/spack/build_systems/autotools.py
@@ -261,14 +261,19 @@ def autoreconf(self, spec, prefix):
             # This line is what is needed most of the time
             # --install, --verbose, --force
             autoreconf_args = ['-ivf']
-            for dep in spec.dependencies(deptype='build'):
-                if os.path.exists(dep.prefix.share.aclocal):
-                    autoreconf_args.extend([
-                        '-I', dep.prefix.share.aclocal
-                    ])
+            autoreconf_args += self.autoreconf_search_path_args
             autoreconf_args += self.autoreconf_extra_args
             m.autoreconf(*autoreconf_args)
 
+    @property
+    def autoreconf_search_path_args(self):
+        """Arguments to autoreconf to modify the search paths"""
+        search_path_args = []
+        for dep in self.spec.dependencies(deptype='build'):
+            if os.path.exists(dep.prefix.share.aclocal):
+                search_path_args.extend(['-I', dep.prefix.share.aclocal])
+        return search_path_args
+
     @run_after('autoreconf')
     def set_configure_or_die(self):
         """Checks the presence of a ``configure`` file after the
diff --git a/var/spack/repos/builtin/packages/audacious/package.py b/var/spack/repos/builtin/packages/audacious/package.py
--- a/var/spack/repos/builtin/packages/audacious/package.py
+++ b/var/spack/repos/builtin/packages/audacious/package.py
@@ -2,10 +2,6 @@
 # Spack Project Developers. See the top-level COPYRIGHT file for details.
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
-
-from spack import *
-
-
 class Audacious(AutotoolsPackage):
     """A lightweight and versatile audio player."""
 
@@ -27,6 +23,11 @@ class Audacious(AutotoolsPackage):
     depends_on('glib')
     depends_on('qt')
 
+    def patch(self):
+        search_path_args = ' '.join(self.autoreconf_search_path_args)
+        search_path_str = '-I m4 {0}'.format(search_path_args)
+        filter_file('-I m4', search_path_str, 'autogen.sh')
+
     def autoreconf(self, spec, prefix):
         bash = which('bash')
         bash('./autogen.sh')


Test patch: