diff options
author | Christoph Junghans <christoph.junghans@gmail.com> | 2017-08-23 15:08:52 -0600 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2017-08-23 14:08:52 -0700 |
commit | fa1d0a8a4d41616e4689ca0c80318269f55c5c9e (patch) | |
tree | 24d76bc3da8bc8302169814390cc504059fb573e | |
parent | 359b21c888c923ef61b4680cdbd00e3781a9d78b (diff) | |
download | spack-fa1d0a8a4d41616e4689ca0c80318269f55c5c9e.tar.gz spack-fa1d0a8a4d41616e4689ca0c80318269f55c5c9e.tar.bz2 spack-fa1d0a8a4d41616e4689ca0c80318269f55c5c9e.tar.xz spack-fa1d0a8a4d41616e4689ca0c80318269f55c5c9e.zip |
Add --source option to spack install (#4102)
- -- source will copy source into prefix along with the package.
- added a test for --source, as well
-rw-r--r-- | lib/spack/spack/cmd/install.py | 4 | ||||
-rw-r--r-- | lib/spack/spack/package.py | 11 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/install.py | 12 | ||||
-rwxr-xr-x | share/spack/spack-completion.bash | 2 |
4 files changed, 28 insertions, 1 deletions
diff --git a/lib/spack/spack/cmd/install.py b/lib/spack/spack/cmd/install.py index ec1efdc9cf..83ebe71787 100644 --- a/lib/spack/spack/cmd/install.py +++ b/lib/spack/spack/cmd/install.py @@ -69,6 +69,9 @@ the dependencies""" '--restage', action='store_true', dest='restage', 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( '-n', '--no-checksum', action='store_true', dest='no_checksum', help="do not check packages against checksum") subparser.add_argument( @@ -314,6 +317,7 @@ def install(parser, args, **kwargs): 'keep_prefix': args.keep_prefix, 'keep_stage': args.keep_stage, 'restage': args.restage, + 'install_source': args.install_source, 'install_deps': 'dependencies' in args.things_to_install, 'make_jobs': args.jobs, 'run_tests': args.run_tests, diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index 64db8013d0..c13a566e27 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -1193,6 +1193,7 @@ class PackageBase(with_metaclass(PackageMeta, object)): def do_install(self, keep_prefix=False, keep_stage=False, + install_source=False, install_deps=True, skip_patch=False, verbose=False, @@ -1213,6 +1214,8 @@ class PackageBase(with_metaclass(PackageMeta, object)): keep_stage (bool): By default, stage is destroyed only if there are no exceptions during build. Set to True to keep the stage 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 package skip_patch (bool): Skip patch stage of build if True. @@ -1260,6 +1263,7 @@ class PackageBase(with_metaclass(PackageMeta, object)): dep.package.do_install( keep_prefix=keep_prefix, keep_stage=keep_stage, + install_source=install_source, install_deps=install_deps, fake=fake, skip_patch=skip_patch, @@ -1312,6 +1316,13 @@ class PackageBase(with_metaclass(PackageMeta, object)): if fake: self.do_fake_install() 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. self.stage.chdir_to_source() diff --git a/lib/spack/spack/test/cmd/install.py b/lib/spack/spack/test/cmd/install.py index eef5605275..2886aa5d6a 100644 --- a/lib/spack/spack/test/cmd/install.py +++ b/lib/spack/spack/test/cmd/install.py @@ -24,6 +24,7 @@ ############################################################################## import argparse import os +import filecmp 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 install.error.name == 'InstallError' 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')) diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash index 408aaf61ac..05ae403eb5 100755 --- a/share/spack/spack-completion.bash +++ b/share/spack/spack-completion.bash @@ -456,7 +456,7 @@ function _spack_install { then compgen -W "-h --help --only -j --jobs --keep-prefix --keep-stage -n --no-checksum -v --verbose --fake --clean --dirty - --run-tests --log-format --log-file" -- "$cur" + --run-tests --log-format --log-file --source" -- "$cur" else compgen -W "$(_all_packages)" -- "$cur" fi |