
Builders and package classes refer to packages from the builtin package repo and are often modified together with packages. That means that these classes should move into `spack_repo.builtin`. * move `spack.build_systems` -> `spack_repo.builtin.build_systems` * Remove the following re-exports from the `spack.package` module: - `AspellDictPackage` - `LuaPackage` - `AutotoolsPackage` - `MakefilePackage` - `BundlePackage` - `MavenPackage` - `CachedCMakePackage` - `MesonPackage` - `cmake_cache_filepath` - `MSBuildPackage` - `cmake_cache_option` - `NMakePackage` - `cmake_cache_path` - `OctavePackage` - `cmake_cache_string` - `PerlPackage` - `CargoPackage` - `PythonExtension` - `CMakePackage` - `PythonPackage` - `generator` - `QMakePackage` - `CompilerPackage` - `RacketPackage` - `CudaPackage` - `RPackage` - `Package` - `ROCmPackage` - `GNUMirrorPackage` - `RubyPackage` - `GoPackage` - `SConsPackage` - `IntelPackage` - `SIPPackage` - `IntelOneApiLibraryPackageWithSdk` - `SourceforgePackage` - `IntelOneApiLibraryPackage` - `SourcewarePackage` - `IntelOneApiStaticLibraryList` - `WafPackage` - `IntelOneApiPackage` - `XorgPackage` - `INTEL_MATH_LIBRARIES` * update mock packages to repo v2.0 and add copies of packages/build systems they use from builtin * add missing imports to build systems in `package.py` from builtin and test repos * update various tests This PR is breaking because of removal of various names from `spack.package`, but breakage should be minimal thanks to #50496, which ensures the above names are always imported in repo v1 packages. Specifically this PR breaks imports like the following in `package.py` files: ```python from spack.package import Package ``` but if your repo is v1.0 (see `spack repo list`) and has the following much more common pattern: ```python from spack.package import * ``` nothing should break.
139 lines
5.3 KiB
Python
139 lines
5.3 KiB
Python
# Copyright Spack Project Developers. See COPYRIGHT file for details.
|
|
#
|
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
|
from typing import List
|
|
|
|
import llnl.util.filesystem as fs
|
|
|
|
import spack.builder
|
|
import spack.package_base
|
|
import spack.phase_callbacks
|
|
import spack.spec
|
|
import spack.util.prefix
|
|
from spack.directives import build_system, conflicts, depends_on
|
|
from spack.multimethod import when
|
|
|
|
from ._checks import (
|
|
BuilderWithDefaults,
|
|
apply_macos_rpath_fixups,
|
|
execute_build_time_tests,
|
|
execute_install_time_tests,
|
|
)
|
|
|
|
|
|
class MakefilePackage(spack.package_base.PackageBase):
|
|
"""Specialized class for packages built using Makefiles."""
|
|
|
|
#: This attribute is used in UI queries that need to know the build
|
|
#: system base class
|
|
build_system_class = "MakefilePackage"
|
|
#: Legacy buildsystem attribute used to deserialize and install old specs
|
|
legacy_buildsystem = "makefile"
|
|
|
|
build_system("makefile")
|
|
|
|
with when("build_system=makefile"):
|
|
conflicts("platform=windows")
|
|
depends_on("gmake", type="build")
|
|
|
|
|
|
@spack.builder.builder("makefile")
|
|
class MakefileBuilder(BuilderWithDefaults):
|
|
"""The Makefile builder encodes the most common way of building software with
|
|
Makefiles. It has three phases that can be overridden, if need be:
|
|
|
|
1. :py:meth:`~.MakefileBuilder.edit`
|
|
2. :py:meth:`~.MakefileBuilder.build`
|
|
3. :py:meth:`~.MakefileBuilder.install`
|
|
|
|
It is usually necessary to override the :py:meth:`~.MakefileBuilder.edit`
|
|
phase (which is by default a no-op), while the other two have sensible defaults.
|
|
|
|
For a finer tuning you may override:
|
|
|
|
+-----------------------------------------------+--------------------+
|
|
| **Method** | **Purpose** |
|
|
+===============================================+====================+
|
|
| :py:attr:`~.MakefileBuilder.build_targets` | Specify ``make`` |
|
|
| | targets for the |
|
|
| | build phase |
|
|
+-----------------------------------------------+--------------------+
|
|
| :py:attr:`~.MakefileBuilder.install_targets` | Specify ``make`` |
|
|
| | targets for the |
|
|
| | install phase |
|
|
+-----------------------------------------------+--------------------+
|
|
| :py:meth:`~.MakefileBuilder.build_directory` | Directory where the|
|
|
| | Makefile is located|
|
|
+-----------------------------------------------+--------------------+
|
|
"""
|
|
|
|
phases = ("edit", "build", "install")
|
|
|
|
#: Names associated with package methods in the old build-system format
|
|
legacy_methods = ("check", "installcheck")
|
|
|
|
#: Names associated with package attributes in the old build-system format
|
|
legacy_attributes = (
|
|
"build_targets",
|
|
"install_targets",
|
|
"build_time_test_callbacks",
|
|
"install_time_test_callbacks",
|
|
"build_directory",
|
|
)
|
|
|
|
#: Targets for ``make`` during the :py:meth:`~.MakefileBuilder.build` phase
|
|
build_targets: List[str] = []
|
|
#: Targets for ``make`` during the :py:meth:`~.MakefileBuilder.install` phase
|
|
install_targets = ["install"]
|
|
|
|
#: Callback names for build-time test
|
|
build_time_test_callbacks = ["check"]
|
|
|
|
#: Callback names for install-time test
|
|
install_time_test_callbacks = ["installcheck"]
|
|
|
|
@property
|
|
def build_directory(self) -> str:
|
|
"""Return the directory containing the main Makefile."""
|
|
return self.pkg.stage.source_path
|
|
|
|
def edit(
|
|
self, pkg: MakefilePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix
|
|
) -> None:
|
|
"""Edit the Makefile before calling make. The default is a no-op."""
|
|
pass
|
|
|
|
def build(
|
|
self, pkg: MakefilePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix
|
|
) -> None:
|
|
"""Run "make" on the build targets specified by the builder."""
|
|
with fs.working_dir(self.build_directory):
|
|
pkg.module.make(*self.build_targets)
|
|
|
|
def install(
|
|
self, pkg: MakefilePackage, spec: spack.spec.Spec, prefix: spack.util.prefix.Prefix
|
|
) -> None:
|
|
"""Run "make" on the install targets specified by the builder."""
|
|
with fs.working_dir(self.build_directory):
|
|
pkg.module.make(*self.install_targets)
|
|
|
|
spack.phase_callbacks.run_after("build")(execute_build_time_tests)
|
|
|
|
def check(self) -> None:
|
|
"""Run "make" on the ``test`` and ``check`` targets, if found."""
|
|
with fs.working_dir(self.build_directory):
|
|
self.pkg._if_make_target_execute("test")
|
|
self.pkg._if_make_target_execute("check")
|
|
|
|
spack.phase_callbacks.run_after("install")(execute_install_time_tests)
|
|
|
|
def installcheck(self) -> None:
|
|
"""Searches the Makefile for an ``installcheck`` target
|
|
and runs it if found.
|
|
"""
|
|
with fs.working_dir(self.build_directory):
|
|
self.pkg._if_make_target_execute("installcheck")
|
|
|
|
# On macOS, force rpaths for shared library IDs and remove duplicate rpaths
|
|
spack.phase_callbacks.run_after("install", when="platform=darwin")(apply_macos_rpath_fixups)
|