Use gnuconfig package for config file replacement (#26035)

* Use gnuconfig package for config file replacement

Currently the autotools build system tries to pick up config.sub and
config.guess files from the system (in /usr/share) on arm and power.
This is introduces an implicit system dependency which we can avoid by
distributing config.guess and config.sub files in a separate package,
such as the new `gnuconfig` package which is very lightweight/text only
(unlike automake where we previously pulled these files from as a
backup). This PR adds `gnuconfig` as an unconditional build dependency
for arm and power archs.

In case the user needs a system version of config.sub and config.guess,
they are free to mark `gnuconfig` as an external package with the prefix
pointing to the directory containing the config files:

```yaml
    gnuconfig:
      externals:
      - spec: gnuconfig@master
        prefix: /tmp/tmp.ooBlkyAKdw/lol
      buildable: false
```

Apart from that, this PR gives some better instructions for users when
replacing config files goes wrong.

* Mock needs this package too now, because autotools adds a depends_on

* Add documentation

* Make patch_config_files a prop, fix the docs, add integrations tests

* Make macOS happy
This commit is contained in:
Harmen Stoppels
2021-09-28 00:38:14 +02:00
committed by GitHub
parent c0da0d83ff
commit 87450f3688
5 changed files with 357 additions and 44 deletions

View File

@@ -0,0 +1,88 @@
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
from spack import *
class AutotoolsConfigReplacement(AutotoolsPackage):
"""
This package features broken and working config.sub and config.guess files,
that should be replaced by the ones provided by gnuconfig. It allows testing
with / without patches and with / without substitutes available.
"""
has_code = False
version('1.0.0')
variant('patch_config_files', default=False)
variant('gnuconfig', default=False)
depends_on('gnuconfig', type='build', when='+gnuconfig')
@property
def patch_config_files(self):
return self.spec.satisfies('+patch_config_files')
def autoreconf(self, spec, prefix):
pass
def configure(self, spec, prefix):
pass
def build(self, spec, prefix):
pass
def install(self, spec, prefix):
broken = os.path.join(self.stage.source_path, 'broken')
working = os.path.join(self.stage.source_path, 'working')
install_tree(broken, self.prefix.broken)
install_tree(working, self.prefix.working)
@run_before('autoreconf')
def create_the_package_sources(self):
# Creates the following file structure:
# ./broken/config.sub -- not executable
# ./broken/config.guess -- exectuable & exit code 1
# ./working/config.sub -- executable & exit code 0
# ./working/config.guess -- executable & exit code 0
# Automatic config helper script substitution should replace the two
# broken scripts with those from the gnuconfig package.
broken = os.path.join(self.stage.source_path, 'broken')
working = os.path.join(self.stage.source_path, 'working')
mkdirp(broken)
mkdirp(working)
# a configure script is required
configure_script = join_path(self.stage.source_path, 'configure')
with open(configure_script, 'w') as f:
f.write("#!/bin/sh\nexit 0")
os.chmod(configure_script, 0o775)
# broken config.sub (not executable)
broken_config_sub = join_path(broken, 'config.sub')
with open(broken_config_sub, 'w') as f:
f.write("#!/bin/sh\nexit 0")
# broken config.guess (exectuable but with error return code)
broken_config_guess = join_path(broken, 'config.guess')
with open(broken_config_guess, 'w') as f:
f.write("#!/bin/sh\nexit 1")
os.chmod(broken_config_guess, 0o775)
# working config.sub
working_config_sub = join_path(working, 'config.sub')
with open(working_config_sub, 'w') as f:
f.write("#!/bin/sh\nexit 0")
os.chmod(working_config_sub, 0o775)
# working config.guess
working_config_guess = join_path(working, 'config.guess')
with open(working_config_guess, 'w') as f:
f.write("#!/bin/sh\nexit 0")
os.chmod(working_config_guess, 0o775)

View File

@@ -0,0 +1,35 @@
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
from spack import *
class Gnuconfig(Package):
"""
The GNU config.guess and config.sub scripts versioned by timestamp.
This package can be used as a build dependency for autotools packages that
ship a tarball with outdated config.guess and config.sub files.
"""
has_code = False
version('2021-08-14')
def install(self, spec, prefix):
config_sub = join_path(prefix, 'config.sub')
config_guess = join_path(prefix, 'config.guess')
# Create files
with open(config_sub, 'w') as f:
f.write("#!/bin/sh\necho gnuconfig version of config.sub")
with open(config_guess, 'w') as f:
f.write("#!/bin/sh\necho gnuconfig version of config.guess")
# Make executable
os.chmod(config_sub, 0o775)
os.chmod(config_guess, 0o775)