diff options
author | psakievich <psakiev@sandia.gov> | 2024-09-26 09:59:13 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-26 08:59:13 -0700 |
commit | ea6e39805ac76326a5a63f394ee8bbdca1130ac6 (patch) | |
tree | 0fe2d61e38675cbf5c3fac9ba0ce93b2d64b7eaa /lib | |
parent | bbd205543b09139f2f57f21099eb366c9f183d76 (diff) | |
download | spack-ea6e39805ac76326a5a63f394ee8bbdca1130ac6.tar.gz spack-ea6e39805ac76326a5a63f394ee8bbdca1130ac6.tar.bz2 spack-ea6e39805ac76326a5a63f394ee8bbdca1130ac6.tar.xz spack-ea6e39805ac76326a5a63f394ee8bbdca1130ac6.zip |
Add a custom hook for dev_path changes (#46529)
* Add a custom hook for dev_path changes
Co-authored-by: Greg Becker <becker33@llnl.gov>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/docs/environments.rst | 8 | ||||
-rw-r--r-- | lib/spack/spack/environment/environment.py | 10 | ||||
-rw-r--r-- | lib/spack/spack/package_base.py | 9 |
3 files changed, 21 insertions, 6 deletions
diff --git a/lib/spack/docs/environments.rst b/lib/spack/docs/environments.rst index 86be68d0c5..f36232095c 100644 --- a/lib/spack/docs/environments.rst +++ b/lib/spack/docs/environments.rst @@ -414,7 +414,13 @@ default, it will also clone the package to a subdirectory in the environment. This package will have a special variant ``dev_path`` set, and Spack will ensure the package and its dependents are rebuilt any time the environment is installed if the package's local source -code has been modified. Spack ensures that all instances of a +code has been modified. Spack's native implementation to check for modifications +is to check if ``mtime`` is newer than the installation. +A custom check can be created by overriding the ``detect_dev_src_change`` method +in your package class. This is particularly useful for projects using custom spack repo's +to drive development and want to optimize performance. + +Spack ensures that all instances of a developed package in the environment are concretized to match the version (and other constraints) passed as the spec argument to the ``spack develop`` command. diff --git a/lib/spack/spack/environment/environment.py b/lib/spack/spack/environment/environment.py index e1a35b2e9e..28588f07b6 100644 --- a/lib/spack/spack/environment/environment.py +++ b/lib/spack/spack/environment/environment.py @@ -546,8 +546,7 @@ def _is_dev_spec_and_has_changed(spec): last installation""" # First check if this is a dev build and in the process already try to get # the dev_path - dev_path_var = spec.variants.get("dev_path", None) - if not dev_path_var: + if not spec.variants.get("dev_path", None): return False # Now we can check whether the code changed since the last installation @@ -555,9 +554,10 @@ def _is_dev_spec_and_has_changed(spec): # Not installed -> nothing to compare against return False - _, record = spack.store.STORE.db.query_by_spec_hash(spec.dag_hash()) - mtime = fs.last_modification_time_recursive(dev_path_var.value) - return mtime > record.installation_time + # hook so packages can use to write their own method for checking the dev_path + # use package so attributes about concretization such as variant state can be + # utilized + return spec.package.detect_dev_src_change() def _error_on_nonempty_view_dir(new_root): diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py index cc5f11cb72..414020faa4 100644 --- a/lib/spack/spack/package_base.py +++ b/lib/spack/spack/package_base.py @@ -1101,6 +1101,15 @@ class PackageBase(WindowsRPath, PackageViewMixin, RedistributionMixin, metaclass """ pass + def detect_dev_src_change(self): + """ + Method for checking for source code changes to trigger rebuild/reinstall + """ + dev_path_var = self.spec.variants.get("dev_path", None) + _, record = spack.store.STORE.db.query_by_spec_hash(self.spec.dag_hash()) + mtime = fsys.last_modification_time_recursive(dev_path_var.value) + return mtime > record.installation_time + def all_urls_for_version(self, version: StandardVersion) -> List[str]: """Return all URLs derived from version_urls(), url, urls, and list_url (if it contains a version) in a package in that order. |