From 6fa0bb991a16bf468e3ad88226b22faa5c290d00 Mon Sep 17 00:00:00 2001 From: Gregory Becker Date: Fri, 30 Oct 2015 14:08:09 -0700 Subject: [PATCH] Removed cflags from default format string and made them an option within the compiler string. Added -f option to find command; with -f, find prints flags --- lib/spack/spack/cmd/find.py | 38 +++++++++++++++++++++++++++---------- lib/spack/spack/spec.py | 14 ++++++++++---- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lib/spack/spack/cmd/find.py b/lib/spack/spack/cmd/find.py index 0b0dd6ef6f..0728f3f1b2 100644 --- a/lib/spack/spack/cmd/find.py +++ b/lib/spack/spack/cmd/find.py @@ -53,6 +53,9 @@ def setup_parser(subparser): subparser.add_argument( '-L', '--very-long', action='store_true', dest='very_long', help='Show dependency hashes as well as versions.') + subparser.add_argument( + '-f', '--show-flags', action='store_true', dest='show_flags', + help='Show spec compiler flags.') subparser.add_argument( '-u', '--unknown', action='store_true', dest='unknown', @@ -76,12 +79,18 @@ def gray_hash(spec, length): def display_specs(specs, **kwargs): mode = kwargs.get('mode', 'short') hashes = kwargs.get('long', False) + print hashes hlen = 7 if kwargs.get('very_long', False): hashes = True hlen = None + format_string = '$_$@$+' + flags = kwargs.get('show_flags', False) + if flags: + format_string = '$_$@$%+$+' + # Make a dict with specs keyed by architecture and compiler. index = index_by(specs, ('architecture', 'compiler')) @@ -97,7 +106,7 @@ def display_specs(specs, **kwargs): specs = index[(architecture,compiler)] specs.sort() - abbreviated = [s.format('$_$@$+', color=True) for s in specs] + abbreviated = [s.format(format_string, color=True) for s in specs] if mode == 'paths': # Print one spec per line along with prefix path width = max(len(s) for s in abbreviated) @@ -112,20 +121,28 @@ def display_specs(specs, **kwargs): elif mode == 'deps': for spec in specs: print spec.tree( - format='$_$@$+', + format=format_string, color=True, indent=4, prefix=(lambda s: gray_hash(s, hlen)) if hashes else None) elif mode == 'short': - def fmt(s): - string = "" - if hashes: - string += gray_hash(s, hlen) + ' ' - string += s.format('$-_$@$+', color=True) + # Print columns of output if not printing flags + if not flags: + def fmt(s): + string = "" + if hashes: + string += gray_hash(s, hlen) + ' ' + string += s.format('$-_$@$+', color=True) - return string - colify(fmt(s) for s in specs) + return string + colify(fmt(s) for s in specs) + # Print one entry per line if including flags + else: + for spec in specs: + # Print the hash if necessary + hsh = gray_hash(spec, hlen) + ' ' if hashes else '' + print hsh + spec.format(format_string, color=True) + '\n' else: raise ValueError( @@ -171,4 +188,5 @@ def find(parser, args): tty.msg("%d installed packages." % len(specs)) display_specs(specs, mode=args.mode, long=args.long, - very_long=args.very_long) + very_long=args.very_long, + show_flags=args.show_flags) diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index 40a257489e..b9dcd91e99 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -1630,7 +1630,9 @@ def format(self, format_string='$_$@$%@$+$=', **kwargs): $@ Version $% Compiler $%@ Compiler & compiler version - $+ Options & compiler flags + $%+ Compiler and compiler flags + $%@+ Compiler, compiler version, and compiler flags + $+ Options $= Architecture $# 7-char prefix of DAG hash $$ $ @@ -1684,8 +1686,6 @@ def write(s, c): elif c == '+': if self.variants: write(fmt % str(self.variants), c) - if self.compiler_flags: - write(fmt % str(self.compiler_flags), '%') elif c == '=': if self.architecture: write(fmt % ('+arch' + c + str(self.architecture)), c) @@ -1702,11 +1702,17 @@ def write(s, c): if (self.compiler and self.compiler.versions and self.compiler.versions != _any_version): write(c + str(self.compiler.versions), '%') + elif c == '+': + if self.compiler_flags: + write(fmt % str(self.compiler_flags), '%') + compiler = False elif c == '$': escape = True + compiler = False else: out.write(c) - compiler = False + compiler = False + elif c == '$': escape = True