environment.py: write lockfile last (#30039)

This makes it easier to write `spack.lock: spack.yaml` type of rules in `Makefiles`.
This commit is contained in:
Harmen Stoppels 2022-04-19 21:32:59 +02:00 committed by GitHub
parent dc3cf5c6b0
commit abc162cf3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1897,10 +1897,14 @@ def write(self, regenerate=True):
fs.mkdirp(pkg_dir)
spack.repo.path.dump_provenance(dep, pkg_dir)
# write the lock file last
self._update_and_write_manifest(raw_yaml_dict, yaml_dict)
# Write the lock file last. This is useful for Makefiles
# with `spack.lock: spack.yaml` rules, where the target
# should be newer than the prerequisite to avoid
# redundant re-concretization.
with fs.write_tmp_and_move(self.lock_path) as f:
sjson.dump(self._to_lockfile_dict(), stream=f)
self._update_and_write_manifest(raw_yaml_dict, yaml_dict)
else:
with fs.safe_remove(self.lock_path):
self._update_and_write_manifest(raw_yaml_dict, yaml_dict)