Add --source option to spack install (#4102)

- -- source will copy source into prefix along with the package.
- added a test for --source, as well
This commit is contained in:
Christoph Junghans 2017-08-23 15:08:52 -06:00 committed by Todd Gamblin
parent 359b21c888
commit fa1d0a8a4d
4 changed files with 28 additions and 1 deletions

View File

@ -68,6 +68,9 @@ def setup_parser(subparser):
subparser.add_argument( subparser.add_argument(
'--restage', action='store_true', dest='restage', '--restage', action='store_true', dest='restage',
help="if a partial install is detected, delete prior state") help="if a partial install is detected, delete prior state")
subparser.add_argument(
'--source', action='store_true', dest='install_source',
help="install source files in prefix")
subparser.add_argument( subparser.add_argument(
'-n', '--no-checksum', action='store_true', dest='no_checksum', '-n', '--no-checksum', action='store_true', dest='no_checksum',
help="do not check packages against checksum") help="do not check packages against checksum")
@ -314,6 +317,7 @@ def install(parser, args, **kwargs):
'keep_prefix': args.keep_prefix, 'keep_prefix': args.keep_prefix,
'keep_stage': args.keep_stage, 'keep_stage': args.keep_stage,
'restage': args.restage, 'restage': args.restage,
'install_source': args.install_source,
'install_deps': 'dependencies' in args.things_to_install, 'install_deps': 'dependencies' in args.things_to_install,
'make_jobs': args.jobs, 'make_jobs': args.jobs,
'run_tests': args.run_tests, 'run_tests': args.run_tests,

View File

@ -1193,6 +1193,7 @@ def _update_explicit_entry_in_db(self, rec, explicit):
def do_install(self, def do_install(self,
keep_prefix=False, keep_prefix=False,
keep_stage=False, keep_stage=False,
install_source=False,
install_deps=True, install_deps=True,
skip_patch=False, skip_patch=False,
verbose=False, verbose=False,
@ -1213,6 +1214,8 @@ def do_install(self,
keep_stage (bool): By default, stage is destroyed only if there keep_stage (bool): By default, stage is destroyed only if there
are no exceptions during build. Set to True to keep the stage are no exceptions during build. Set to True to keep the stage
even with exceptions. even with exceptions.
install_source (bool): By default, source is not installed, but
for debugging it might be useful to keep it around.
install_deps (bool): Install dependencies before installing this install_deps (bool): Install dependencies before installing this
package package
skip_patch (bool): Skip patch stage of build if True. skip_patch (bool): Skip patch stage of build if True.
@ -1260,6 +1263,7 @@ def do_install(self,
dep.package.do_install( dep.package.do_install(
keep_prefix=keep_prefix, keep_prefix=keep_prefix,
keep_stage=keep_stage, keep_stage=keep_stage,
install_source=install_source,
install_deps=install_deps, install_deps=install_deps,
fake=fake, fake=fake,
skip_patch=skip_patch, skip_patch=skip_patch,
@ -1312,6 +1316,13 @@ def build_process():
if fake: if fake:
self.do_fake_install() self.do_fake_install()
else: else:
source_path = self.stage.source_path
if install_source and os.path.isdir(source_path):
src_target = join_path(
self.spec.prefix, 'share', self.name, 'src')
tty.msg('Copying source to {0}'.format(src_target))
install_tree(self.stage.source_path, src_target)
# 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()

View File

@ -24,6 +24,7 @@
############################################################################## ##############################################################################
import argparse import argparse
import os import os
import filecmp
import pytest import pytest
@ -130,3 +131,14 @@ def test_install_output_on_python_error(builtin_mock, mock_archive, mock_fetch,
assert isinstance(install.error, spack.build_environment.ChildError) assert isinstance(install.error, spack.build_environment.ChildError)
assert install.error.name == 'InstallError' assert install.error.name == 'InstallError'
assert 'raise InstallError("Expected failure.")' in out assert 'raise InstallError("Expected failure.")' in out
def test_install_with_source(
builtin_mock, mock_archive, mock_fetch, config, install_mockery):
"""Verify that source has been copied into place."""
install('--source', '--keep-stage', 'trivial-install-test-package')
spec = Spec('trivial-install-test-package').concretized()
src = os.path.join(
spec.prefix.share, 'trivial-install-test-package', 'src')
assert filecmp.cmp(os.path.join(mock_archive.path, 'configure'),
os.path.join(src, 'configure'))

View File

@ -456,7 +456,7 @@ function _spack_install {
then then
compgen -W "-h --help --only -j --jobs --keep-prefix --keep-stage compgen -W "-h --help --only -j --jobs --keep-prefix --keep-stage
-n --no-checksum -v --verbose --fake --clean --dirty -n --no-checksum -v --verbose --fake --clean --dirty
--run-tests --log-format --log-file" -- "$cur" --run-tests --log-format --log-file --source" -- "$cur"
else else
compgen -W "$(_all_packages)" -- "$cur" compgen -W "$(_all_packages)" -- "$cur"
fi fi