dev-build: --drop-in <shell> (#14887)
* dev-build: --drop-in <shell> Add a `--drop-in <shell>` option to `spack dev-build`. This option will automatically run a `spack build-env <spec> -- <shell>` at the end of a `dev-build`, e.g. to quickly drop-and-devel into a build phase of a package. Example usage: ``` spack dev-build --before cmake --drop-in bash openpmd-api@develop ``` * build_env: drop in unit test Co-authored-by: Greg Becker <becker33@llnl.gov>
This commit is contained in:
		@@ -37,6 +37,9 @@ def setup_parser(subparser):
 | 
				
			|||||||
    subparser.add_argument(
 | 
					    subparser.add_argument(
 | 
				
			||||||
        '-q', '--quiet', action='store_true', dest='quiet',
 | 
					        '-q', '--quiet', action='store_true', dest='quiet',
 | 
				
			||||||
        help="do not display verbose build output while installing")
 | 
					        help="do not display verbose build output while installing")
 | 
				
			||||||
 | 
					    subparser.add_argument(
 | 
				
			||||||
 | 
					        '--drop-in', type=str, dest='shell', default=None,
 | 
				
			||||||
 | 
					        help="drop into a build environment in a new shell, e.g. bash, zsh")
 | 
				
			||||||
    arguments.add_common_arguments(subparser, ['spec'])
 | 
					    arguments.add_common_arguments(subparser, ['spec'])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    stop_group = subparser.add_mutually_exclusive_group()
 | 
					    stop_group = subparser.add_mutually_exclusive_group()
 | 
				
			||||||
@@ -98,3 +101,8 @@ def dev_build(self, args):
 | 
				
			|||||||
        dirty=args.dirty,
 | 
					        dirty=args.dirty,
 | 
				
			||||||
        stop_before=args.before,
 | 
					        stop_before=args.before,
 | 
				
			||||||
        stop_at=args.until)
 | 
					        stop_at=args.until)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # drop into the build environment of the package?
 | 
				
			||||||
 | 
					    if args.shell is not None:
 | 
				
			||||||
 | 
					        spack.build_environment.setup_package(package, dirty=False)
 | 
				
			||||||
 | 
					        os.execvp(args.shell, [args.shell])
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,6 +76,17 @@ def test_dev_build_before_until(tmpdir, mock_packages, install_mockery):
 | 
				
			|||||||
                      'dev-build-test-install@0.0.0')
 | 
					                      'dev-build-test-install@0.0.0')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_dev_build_drop_in(tmpdir, mock_packages, monkeypatch,
 | 
				
			||||||
 | 
					                           install_mockery):
 | 
				
			||||||
 | 
					    def print_spack_cc(*args):
 | 
				
			||||||
 | 
					        # Eat arguments and print environment variable to test
 | 
				
			||||||
 | 
					        print(os.environ['CC'])
 | 
				
			||||||
 | 
					    monkeypatch.setattr(os, 'execvp', print_spack_cc)
 | 
				
			||||||
 | 
					    output = dev_build('-b', 'edit', '--drop-in', 'sh',
 | 
				
			||||||
 | 
					                       'dev-build-test-install@0.0.0')
 | 
				
			||||||
 | 
					    assert "lib/spack/env" in output
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def test_dev_build_fails_already_installed(tmpdir, mock_packages,
 | 
					def test_dev_build_fails_already_installed(tmpdir, mock_packages,
 | 
				
			||||||
                                           install_mockery):
 | 
					                                           install_mockery):
 | 
				
			||||||
    spec = spack.spec.Spec('dev-build-test-install@0.0.0').concretized()
 | 
					    spec = spack.spec.Spec('dev-build-test-install@0.0.0').concretized()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -697,7 +697,7 @@ _spack_deprecate() {
 | 
				
			|||||||
_spack_dev_build() {
 | 
					_spack_dev_build() {
 | 
				
			||||||
    if $list_options
 | 
					    if $list_options
 | 
				
			||||||
    then
 | 
					    then
 | 
				
			||||||
        SPACK_COMPREPLY="-h --help -j --jobs -d --source-path -i --ignore-dependencies -n --no-checksum --keep-prefix --skip-patch -q --quiet -b --before -u --until --clean --dirty"
 | 
					        SPACK_COMPREPLY="-h --help -j --jobs -d --source-path -i --ignore-dependencies -n --no-checksum --keep-prefix --skip-patch -q --quiet --drop-in -b --before -u --until --clean --dirty"
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        _all_packages
 | 
					        _all_packages
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
@@ -706,7 +706,7 @@ _spack_dev_build() {
 | 
				
			|||||||
_spack_diy() {
 | 
					_spack_diy() {
 | 
				
			||||||
    if $list_options
 | 
					    if $list_options
 | 
				
			||||||
    then
 | 
					    then
 | 
				
			||||||
        SPACK_COMPREPLY="-h --help -j --jobs -d --source-path -i --ignore-dependencies -n --no-checksum --keep-prefix --skip-patch -q --quiet -b --before -u --until --clean --dirty"
 | 
					        SPACK_COMPREPLY="-h --help -j --jobs -d --source-path -i --ignore-dependencies -n --no-checksum --keep-prefix --skip-patch -q --quiet --drop-in -b --before -u --until --clean --dirty"
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        _all_packages
 | 
					        _all_packages
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user