Fix for SPACK-46: cleanup spack clean, spack restage.

This commit is contained in:
Todd Gamblin 2015-02-18 14:00:37 -08:00
parent db11373351
commit c7b8a4e25c
5 changed files with 54 additions and 53 deletions

View file

@ -1,5 +1,5 @@
############################################################################## ##############################################################################
# Copyright (c) 2013, Lawrence Livermore National Security, LLC. # Copyright (c) 2013-2014, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory. # Produced at the Lawrence Livermore National Laboratory.
# #
# This file is part of Spack. # This file is part of Spack.
@ -23,45 +23,24 @@
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
from external import argparse from external import argparse
import subprocess
import llnl.util.tty as tty import llnl.util.tty as tty
import spack import spack
import spack.cmd import spack.cmd
import spack.stage as stage
description = "Remove staged files for packages" description = "Remove build stage and source tarball for packages."
def setup_parser(subparser): def setup_parser(subparser):
subparser.add_argument('-c', "--clean", action="store_true", dest='clean',
help="run make clean in the build directory (default)")
subparser.add_argument('-w', "--work", action="store_true", dest='work',
help="delete the build directory and re-expand it from its archive.")
subparser.add_argument('-d', "--dist", action="store_true", dest='dist',
help="delete the downloaded archive.")
subparser.add_argument('packages', nargs=argparse.REMAINDER, subparser.add_argument('packages', nargs=argparse.REMAINDER,
help="specs of packages to clean") help="specs of packages to clean")
def clean(parser, args): def clean(parser, args):
if not args.packages: if not args.packages:
tty.die("spack clean requires at least one package argument") tty.die("spack clean requires at least one package spec.")
specs = spack.cmd.parse_specs(args.packages, concretize=True) specs = spack.cmd.parse_specs(args.packages, concretize=True)
for spec in specs: for spec in specs:
package = spack.db.get(spec) package = spack.db.get(spec)
if args.dist: package.do_clean()
package.do_clean_dist()
tty.msg("Cleaned %s" % package.name)
elif args.work:
package.do_clean_work()
tty.msg("Restaged %s" % package.name)
else:
try:
package.do_clean()
except subprocess.CalledProcessError, e:
tty.warn("Warning: 'make clean' didn't work. Consider 'spack clean --work'.")
tty.msg("Made clean for %s" % package.name)

View file

@ -0,0 +1,46 @@
##############################################################################
# Copyright (c) 2013-2014, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://scalability-llnl.github.io/spack
# Please also see the LICENSE file for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License (as published by
# the Free Software Foundation) version 2.1 dated February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from external import argparse
import llnl.util.tty as tty
import spack
import spack.cmd
description = "Revert checked out package source code."
def setup_parser(subparser):
subparser.add_argument('packages', nargs=argparse.REMAINDER,
help="specs of packages to restage")
def restage(parser, args):
if not args.packages:
tty.die("spack restage requires at least one package spec.")
specs = spack.cmd.parse_specs(args.packages, concretize=True)
for spec in specs:
package = spack.db.get(spec)
package.do_restage()

View file

@ -1047,26 +1047,13 @@ def ignore(filename):
tree.unmerge(self.prefix, ignore=ignore) tree.unmerge(self.prefix, ignore=ignore)
def do_clean(self): def do_restage(self):
if self.stage.expanded_archive_path: """Reverts expanded/checked out source to a pristine state."""
self.stage.chdir_to_source()
self.clean()
def clean(self):
"""By default just runs make clean. Override if this isn't good."""
# TODO: should we really call make clean, ro just blow away the directory?
make = build_env.MakeExecutable('make', self.parallel)
make('clean')
def do_clean_work(self):
"""By default just blows away the stage directory and re-stages."""
self.stage.restage() self.stage.restage()
def do_clean_dist(self): def do_clean(self):
"""Removes the stage directory where this package was built.""" """Removes the package's build stage and source tarball."""
if os.path.exists(self.stage.path): if os.path.exists(self.stage.path):
self.stage.destroy() self.stage.destroy()

View file

@ -53,13 +53,6 @@ class Libdwarf(Package):
parallel = False parallel = False
def clean(self):
for dir in dwarf_dirs:
with working_dir(dir):
if os.path.exists('Makefile'):
make('clean')
def install(self, spec, prefix): def install(self, spec, prefix):
# dwarf build does not set arguments for ar properly # dwarf build does not set arguments for ar properly
make.add_default_arg('ARFLAGS=rcs') make.add_default_arg('ARFLAGS=rcs')

View file

@ -11,9 +11,5 @@ class PyVirtualenv(Package):
extends('python') extends('python')
depends_on('py-setuptools') depends_on('py-setuptools')
def clean(self):
if os.path.exists('build'):
shutil.rmtree('build')
def install(self, spec, prefix): def install(self, spec, prefix):
python('setup.py', 'install', '--prefix=%s' % prefix) python('setup.py', 'install', '--prefix=%s' % prefix)