diff options
author | Massimiliano Culpo <massimiliano.culpo@gmail.com> | 2022-10-26 20:17:32 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-26 20:17:32 +0200 |
commit | 30c9ff50dd048573e3cd7a63a8ab9c05c0bee339 (patch) | |
tree | 188f4739697adc00669c75b7e91b1d1e769db97e /var/spack/repos/builder.test | |
parent | 83ee5001086672a45e140d5858eacc0b8ef90941 (diff) | |
download | spack-30c9ff50dd048573e3cd7a63a8ab9c05c0bee339.tar.gz spack-30c9ff50dd048573e3cd7a63a8ab9c05c0bee339.tar.bz2 spack-30c9ff50dd048573e3cd7a63a8ab9c05c0bee339.tar.xz spack-30c9ff50dd048573e3cd7a63a8ab9c05c0bee339.zip |
Allow for packages with multiple build-systems (#30738)
This commit extends the DSL that can be used in packages
to allow declaring that a package uses different build-systems
under different conditions.
It requires each spec to have a `build_system` single valued
variant. The variant can be used in many context to query, manipulate
or select the build system associated with a concrete spec.
The knowledge to build a package has been moved out of the
PackageBase hierarchy, into a new Builder hierarchy. Customization
of the default behavior for a given builder can be obtained by
coding a new derived builder in package.py.
The "run_after" and "run_before" decorators are now applied to
methods on the builder. They can also incorporate a "when="
argument to specify that a method is run only when certain
conditions apply.
For packages that do not define their own builder, forwarding logic
is added between the builder and package (methods not found in one
will be retrieved from the other); this PR is expected to be fully
backwards compatible with unmodified packages that use a single
build system.
Diffstat (limited to 'var/spack/repos/builder.test')
8 files changed, 224 insertions, 0 deletions
diff --git a/var/spack/repos/builder.test/packages/callbacks/package.py b/var/spack/repos/builder.test/packages/callbacks/package.py new file mode 100644 index 0000000000..ea6787d9b5 --- /dev/null +++ b/var/spack/repos/builder.test/packages/callbacks/package.py @@ -0,0 +1,45 @@ +# Copyright 2013-2022 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 + +import spack.build_systems.generic +from spack.package import * + + +class Callbacks(Package): + """Package used to verify that callbacks on phases work correctly, including conditions""" + + homepage = "http://www.example.com" + url = "http://www.example.com/a-1.0.tar.gz" + + version("2.0", "abcdef0123456789abcdef0123456789") + version("1.0", "0123456789abcdef0123456789abcdef") + + +class GenericBuilder(spack.build_systems.generic.GenericBuilder): + def install(self, pkg, spec, prefix): + os.environ["CALLBACKS_INSTALL_CALLED"] = "1" + os.environ["INSTALL_VALUE"] = "CALLBACKS" + mkdirp(prefix.bin) + + @run_before("install") + def before_install_1(self): + os.environ["BEFORE_INSTALL_1_CALLED"] = "1" + os.environ["TEST_VALUE"] = "1" + + @run_before("install") + def before_install_2(self): + os.environ["BEFORE_INSTALL_2_CALLED"] = "1" + os.environ["TEST_VALUE"] = "2" + + @run_after("install") + def after_install_1(self): + os.environ["AFTER_INSTALL_1_CALLED"] = "1" + os.environ["TEST_VALUE"] = "3" + + @run_after("install", when="@1.0") + def after_install_2(self): + os.environ["AFTER_INSTALL_2_CALLED"] = "1" + os.environ["TEST_VALUE"] = "4" diff --git a/var/spack/repos/builder.test/packages/custom-phases/package.py b/var/spack/repos/builder.test/packages/custom-phases/package.py new file mode 100644 index 0000000000..37b26e37d0 --- /dev/null +++ b/var/spack/repos/builder.test/packages/custom-phases/package.py @@ -0,0 +1,31 @@ +# Copyright 2013-2022 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 + +import spack.build_systems.generic +from spack.package import * + + +class CustomPhases(Package): + """Package used to verify that we can set custom phases on builders""" + + homepage = "http://www.example.com" + url = "http://www.example.com/a-1.0.tar.gz" + + version("2.0", "abcdef0123456789abcdef0123456789") + version("1.0", "0123456789abcdef0123456789abcdef") + + +class GenericBuilder(spack.build_systems.generic.GenericBuilder): + phases = ["configure", "install"] + + def configure(self, pkg, spec, prefix): + os.environ["CONFIGURE_CALLED"] = "1" + os.environ["LAST_PHASE"] = "CONFIGURE" + + def install(self, pkg, spec, prefix): + os.environ["INSTALL_CALLED"] = "1" + os.environ["LAST_PHASE"] = "INSTALL" + mkdirp(prefix.bin) diff --git a/var/spack/repos/builder.test/packages/gnuconfig/package.py b/var/spack/repos/builder.test/packages/gnuconfig/package.py new file mode 100644 index 0000000000..53f8a10705 --- /dev/null +++ b/var/spack/repos/builder.test/packages/gnuconfig/package.py @@ -0,0 +1,15 @@ +# Copyright 2013-2022 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) +from spack.package import * + + +class Gnuconfig(Package): + """This package is needed to allow mocking AutotoolsPackage objects""" + + homepage = "http://www.example.com" + url = "http://www.example.com/a-1.0.tar.gz" + + version("2.0", "abcdef0123456789abcdef0123456789") + version("1.0", "0123456789abcdef0123456789abcdef") diff --git a/var/spack/repos/builder.test/packages/inheritance/package.py b/var/spack/repos/builder.test/packages/inheritance/package.py new file mode 100644 index 0000000000..307d93ca80 --- /dev/null +++ b/var/spack/repos/builder.test/packages/inheritance/package.py @@ -0,0 +1,26 @@ +# Copyright 2013-2022 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 + +import spack.pkg.builder.test.callbacks +from spack.package import * + + +class Inheritance(spack.pkg.builder.test.callbacks.Callbacks): + """Package used to verify that inheritance among packages work as expected""" + + pass + + +class GenericBuilder(spack.pkg.builder.test.callbacks.GenericBuilder): + def install(self, pkg, spec, prefix): + super(GenericBuilder, self).install(pkg, spec, prefix) + os.environ["INHERITANCE_INSTALL_CALLED"] = "1" + os.environ["INSTALL_VALUE"] = "INHERITANCE" + + @run_before("install") + def derived_before_install(self): + os.environ["DERIVED_BEFORE_INSTALL_CALLED"] = "1" + os.environ["TEST_VALUE"] = "0" diff --git a/var/spack/repos/builder.test/packages/old-style-autotools/package.py b/var/spack/repos/builder.test/packages/old-style-autotools/package.py new file mode 100644 index 0000000000..56213d7158 --- /dev/null +++ b/var/spack/repos/builder.test/packages/old-style-autotools/package.py @@ -0,0 +1,50 @@ +# Copyright 2013-2022 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.package import * + + +class OldStyleAutotools(AutotoolsPackage): + """Package used to verify that old-style packages work correctly when executing the + installation procedure. + """ + + homepage = "http://www.example.com" + url = "http://www.example.com/a-1.0.tar.gz" + + version("2.0", "abcdef0123456789abcdef0123456789") + version("1.0", "0123456789abcdef0123456789abcdef") + + def configure(self, spec, prefix): + pass + + def build(self, spec, prefix): + pass + + def install(self, spec, prefix): + mkdirp(prefix.bin) + + def configure_args(self): + """This override a function in the builder and construct the result using a method + defined in this class and a super method defined in the builder. + """ + return [self.foo()] + super(OldStyleAutotools, self).configure_args() + + def foo(self): + return "--with-foo" + + @run_before("autoreconf") + def create_configure(self): + mkdirp(self.configure_directory) + touch(self.configure_abs_path) + + @run_after("autoreconf", when="@1.0") + def after_autoreconf_1(self): + os.environ["AFTER_AUTORECONF_1_CALLED"] = "1" + + @run_after("autoreconf", when="@2.0") + def after_autoreconf_2(self): + os.environ["AFTER_AUTORECONF_2_CALLED"] = "1" diff --git a/var/spack/repos/builder.test/packages/old-style-custom-phases/package.py b/var/spack/repos/builder.test/packages/old-style-custom-phases/package.py new file mode 100644 index 0000000000..afa5b52d70 --- /dev/null +++ b/var/spack/repos/builder.test/packages/old-style-custom-phases/package.py @@ -0,0 +1,34 @@ +# Copyright 2013-2022 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.package import * + + +class OldStyleCustomPhases(AutotoolsPackage): + """Package used to verify that old-style packages work correctly when defining custom + phases (though it's not recommended for packagers to do so). + """ + + homepage = "http://www.example.com" + url = "http://www.example.com/a-1.0.tar.gz" + + version("2.0", "abcdef0123456789abcdef0123456789") + version("1.0", "0123456789abcdef0123456789abcdef") + + phases = ["configure"] + + def configure(self, spec, prefix): + mkdirp(prefix.bin) + + @run_after("configure") + def after_configure(self): + os.environ["AFTER_CONFIGURE_CALLED"] = "1" + os.environ["TEST_VALUE"] = "0" + + @run_after("install") + def after_install(self): + os.environ["AFTER_INSTALL_CALLED"] = "1" + os.environ["TEST_VALUE"] = "1" diff --git a/var/spack/repos/builder.test/packages/old-style-derived/package.py b/var/spack/repos/builder.test/packages/old-style-derived/package.py new file mode 100644 index 0000000000..a7dd026217 --- /dev/null +++ b/var/spack/repos/builder.test/packages/old-style-derived/package.py @@ -0,0 +1,21 @@ +# Copyright 2013-2022 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 spack.pkg.builder.test.old_style_autotools +from spack.package import * + + +class OldStyleDerived(spack.pkg.builder.test.old_style_autotools.OldStyleAutotools): + """Package used to verify that old-style packages work correctly when executing the + installation procedure. + """ + + homepage = "http://www.example.com" + url = "http://www.example.com/a-1.0.tar.gz" + + version("2.0", "abcdef0123456789abcdef0123456789") + version("1.0", "0123456789abcdef0123456789abcdef") + + def configure_args(self): + return ["--with-bar"] + super(OldStyleDerived, self).configure_args() diff --git a/var/spack/repos/builder.test/repo.yaml b/var/spack/repos/builder.test/repo.yaml new file mode 100644 index 0000000000..a9031afe21 --- /dev/null +++ b/var/spack/repos/builder.test/repo.yaml @@ -0,0 +1,2 @@ +repo: + namespace: builder.test |