Skip to content

Commit

Permalink
Archive files default take into account the build directory
Browse files Browse the repository at this point in the history
The glob expressions that can be used in the `archive_files` list now
are also allowed to be absolute. The errors that may occur when
archiving custom files are collected and reported in a file named
`errors.txt`.
  • Loading branch information
alalazo committed Apr 15, 2018
1 parent 1d66925 commit ce8580f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
6 changes: 4 additions & 2 deletions lib/spack/spack/build_systems/autotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ class AutotoolsPackage(PackageBase):
#: Options to be passed to autoreconf when using the default implementation
autoreconf_extra_args = []

#: Files to archive for packages based on autotools
archive_files = ['config.log']
@property
def archive_files(self):
"""Files to archive for packages based on autotools"""
return [os.path.join(self.build_directory, 'config.log')]

@run_after('autoreconf')
def _do_patch_config_guess(self):
Expand Down
8 changes: 5 additions & 3 deletions lib/spack/spack/build_systems/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ class CMakePackage(PackageBase):

build_time_test_callbacks = ['check']

#: Files to archive for packages based on CMake
archive_files = [os.path.join('spack-build', 'CMakeCache.txt')]

#: The build system generator to use.
#:
#: See ``cmake --help`` for a list of valid generators.
Expand All @@ -93,6 +90,11 @@ class CMakePackage(PackageBase):

depends_on('cmake', type='build')

@property
def archive_files(self):
"""Files to archive for packages based on CMake"""
return [os.path.join(self.build_directory, 'CMakeCache.txt')]

@property
def root_cmakelists_dir(self):
"""The relative path to the directory containing CMakeLists.txt
Expand Down
43 changes: 33 additions & 10 deletions lib/spack/spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,10 @@ class SomePackage(Package):
#: directories, sanity checks will fail.
sanity_check_is_dir = []

#: List of glob expressions relative to the package source path.
#: List of glob expressions. Each expression must either be
#: absolute or relative to the package source path.
#: Matching artifacts found at the end of the build process will
#: be copied in the same directory as build.env and build.out.
#: be copied in the same directory tree as build.env and build.out.
archive_files = []

#
Expand Down Expand Up @@ -1659,24 +1660,46 @@ def log(self):
install(self.env_path, env_install_path)
# Finally, archive files that are specific to each package
with working_dir(self.stage.source_path):
errors = StringIO()
target_dir = os.path.join(
spack.store.layout.metadata_path(self.spec), 'archived-files'
)
for glob_expr in self.archive_files:
# Check that we are trying to copy things that are
# in the source_path tree (not arbitrary files)
abs_expr = os.path.realpath(glob_expr)
if os.path.realpath(self.stage.source_path) not in abs_expr:
errors.write(
'[OUTSIDE SOURCE PATH]: {0}\n'.format(glob_expr)
)
continue
# Now that we are sure that the path is within the correct
# folder, make it relative and check for matches
if os.path.isabs(glob_expr):
glob_expr = os.path.relpath(
glob_expr, self.stage.source_path
)
files = glob.glob(glob_expr)
for file in files:
for f in files:
try:
target = os.path.join(
spack.store.layout.metadata_path(self.spec),
'archived-files',
file
)
target = os.path.join(target_dir, f)
# We must ensure that the directory exists before
# copying a file in
mkdirp(os.path.dirname(target))
install(file, target)
install(f, target)
except Exception:
# Here try to be conservative, and avoid discarding
# the whole install procedure because of copying a
# single file failed
tty.warn("FAILED ARCHIVE: {0}".format(file))
errors.write('[FAILED TO ARCHIVE]: {0}'.format(f))

if errors.getvalue():
error_file = os.path.join(target_dir, 'errors.txt')
mkdirp(target_dir)
with open(error_file, 'w') as err:
err.write(errors.getvalue())
tty.warn('Errors occurred when archiving files.\n\t'
'See: {0}'.format(error_file))

dump_packages(self.spec, packages_dir)

Expand Down

0 comments on commit ce8580f

Please sign in to comment.