Fixes #175: Dump environment provenance as well as build log.

This commit is contained in:
Todd Gamblin 2016-03-02 00:08:36 -08:00
parent be306d09e9
commit 21d125c914
3 changed files with 27 additions and 1 deletions

View File

@ -173,7 +173,9 @@ def __init__(self, root, **kwargs):
self.spec_file_name = 'spec.yaml' self.spec_file_name = 'spec.yaml'
self.extension_file_name = 'extensions.yaml' self.extension_file_name = 'extensions.yaml'
self.build_log_name = 'build.out' # TODO: use config file. self.build_log_name = 'build.out' # build log.
self.build_env_name = 'build.env' # build environment
self.packages_dir = 'repos' # archive of package.py files
# Cache of already written/read extension maps. # Cache of already written/read extension maps.
self._extension_maps = {} self._extension_maps = {}
@ -231,6 +233,16 @@ def build_log_path(self, spec):
self.build_log_name) self.build_log_name)
def build_env_path(self, spec):
return join_path(self.path_for_spec(spec), self.metadata_dir,
self.build_env_name)
def build_packages_path(self, spec):
return join_path(self.path_for_spec(spec), self.metadata_dir,
self.packages_dir)
def create_install_directory(self, spec): def create_install_directory(self, spec):
_check_concrete(spec) _check_concrete(spec)

View File

@ -66,6 +66,7 @@
from spack.stage import Stage, ResourceStage, StageComposite from spack.stage import Stage, ResourceStage, StageComposite
from spack.util.compression import allowed_archive, extension from spack.util.compression import allowed_archive, extension
from spack.util.executable import ProcessError from spack.util.executable import ProcessError
from spack.util.environment import dump_environment
"""Allowed URL schemes for spack packages.""" """Allowed URL schemes for spack packages."""
_ALLOWED_URL_SCHEMES = ["http", "https", "ftp", "file", "git"] _ALLOWED_URL_SCHEMES = ["http", "https", "ftp", "file", "git"]
@ -884,10 +885,14 @@ def real_work():
# Do the real install in the source directory. # Do the real install in the source directory.
self.stage.chdir_to_source() self.stage.chdir_to_source()
# Save the build environment in a file before building.
env_path = join_path(os.getcwd(), 'spack-build.env')
# This redirects I/O to a build log (and optionally to the terminal) # This redirects I/O to a build log (and optionally to the terminal)
log_path = join_path(os.getcwd(), 'spack-build.out') log_path = join_path(os.getcwd(), 'spack-build.out')
log_file = open(log_path, 'w') log_file = open(log_path, 'w')
with log_output(log_file, verbose, sys.stdout.isatty(), True): with log_output(log_file, verbose, sys.stdout.isatty(), True):
dump_environment(env_path)
self.install(self.spec, self.prefix) self.install(self.spec, self.prefix)
# Ensure that something was actually installed. # Ensure that something was actually installed.
@ -896,7 +901,9 @@ def real_work():
# Move build log into install directory on success # Move build log into install directory on success
if not fake: if not fake:
log_install_path = spack.install_layout.build_log_path(self.spec) log_install_path = spack.install_layout.build_log_path(self.spec)
env_install_path = spack.install_layout.build_env_path(self.spec)
install(log_path, log_install_path) install(log_path, log_install_path)
install(env_path, env_install_path)
# On successful install, remove the stage. # On successful install, remove the stage.
if not keep_stage: if not keep_stage:

View File

@ -63,3 +63,10 @@ def pop_keys(dictionary, *keys):
for key in keys: for key in keys:
if key in dictionary: if key in dictionary:
dictionary.pop(key) dictionary.pop(key)
def dump_environment(path):
"""Dump the current environment out to a file."""
with open(path, 'w') as env_file:
for key,val in sorted(os.environ.items()):
env_file.write("%s=%s\n" % (key, val))