def _find_matches_in_path(cls, compiler_names, detect_version, *path): """Finds compilers in the paths supplied. Looks for all combinations of ``compiler_names`` with the ``prefixes`` and ``suffixes`` defined for this compiler class. If any compilers match the compiler_names, prefixes, or suffixes, uses ``detect_version`` to figure out what version the compiler is. This returns a dict with compilers grouped by (prefix, suffix, version) tuples. This can be further organized by find(). """ if not path: path = get_path('PATH') prefixes = [''] + cls.prefixes suffixes = [''] + cls.suffixes checks = [] for directory in path: files = os.listdir(directory) for exe in files: full_path = join_path(directory, exe) prod = itertools.product(prefixes, compiler_names, suffixes) for pre, name, suf in prod: regex = r'^(%s)%s(%s)$' % (pre, re.escape(name), suf) match = re.match(regex, exe) if match: key = (full_path, ) + match.groups() checks.append(key) def check(key): try: full_path, prefix, suffix = key version = detect_version(full_path) return (version, prefix, suffix, full_path) except ProcessError, e: tty.debug("Couldn't get version for compiler %s" % full_path, e) return None except Exception, e: # Catching "Exception" here is fine because it just # means something went wrong running a candidate executable. tty.debug( "Error while executing candidate compiler %s" % full_path, "%s: %s" % (e.__class__.__name__, e)) return None
def compiler_add(args): """Search either $PATH or a list of paths for compilers and add them to Spack's configuration.""" paths = args.add_paths if not paths: paths = get_path('PATH') compilers = [c for c in spack.compilers.find_compilers(*args.add_paths) if c.spec not in spack.compilers.all_compilers()] if compilers: spack.compilers.add_compilers_to_config('user', *compilers) n = len(compilers) tty.msg("Added %d new compiler%s to %s" % ( n, 's' if n > 1 else '', spack.config.get_filename('user'))) colify(reversed(sorted(c.spec for c in compilers)), indent=4) else: tty.msg("Found no new compilers")
def _get_config(): """Get a Spack config, but make sure it has compiler configuration first.""" # If any configuration file has compilers, just stick with the # ones already configured. config = spack.config.get_config() existing = [spack.spec.CompilerSpec(s) for s in config.get_section_names('compiler')] if existing: return config compilers = find_compilers(*get_path('PATH')) new_compilers = [ c for c in compilers if c.spec not in existing] add_compilers_to_config('user', *new_compilers) # After writing compilers to the user config, return a full config # from all files. return spack.config.get_config(refresh=True)
def _find_matches_in_path(cls, compiler_names, detect_version, *path): """Finds compilers in the paths supplied. Looks for all combinations of ``compiler_names`` with the ``prefixes`` and ``suffixes`` defined for this compiler class. If any compilers match the compiler_names, prefixes, or suffixes, uses ``detect_version`` to figure out what version the compiler is. This returns a dict with compilers grouped by (prefix, suffix, version) tuples. This can be further organized by find(). """ if not path: path = get_path('PATH') prefixes = [''] + cls.prefixes suffixes = [''] + cls.suffixes checks = [] for directory in path: files = os.listdir(directory) for exe in files: full_path = join_path(directory, exe) prod = itertools.product(prefixes, compiler_names, suffixes) for pre, name, suf in prod: regex = r'^(%s)%s(%s)$' % (pre, re.escape(name), suf) match = re.match(regex, exe) if match: key = (full_path,) + match.groups() checks.append(key) def check(key): try: full_path, prefix, suffix = key version = detect_version(full_path) return (version, prefix, suffix, full_path) except ProcessError, e: tty.debug("Couldn't get version for compiler %s" % full_path, e) return None
def _get_config(): """Get a Spack config, but make sure it has compiler configuration first.""" # If any configuration file has compilers, just stick with the # ones already configured. config = spack.config.get_config() existing = [ spack.spec.CompilerSpec(s) for s in config.get_section_names('compiler') ] if existing: return config compilers = find_compilers(*get_path('PATH')) new_compilers = [c for c in compilers if c.spec not in existing] add_compilers_to_config('user', *new_compilers) # After writing compilers to the user config, return a full config # from all files. return spack.config.get_config(refresh=True)
def compiler_add(args): """Search either $PATH or a list of paths for compilers and add them to Spack's configuration.""" paths = args.add_paths if not paths: paths = get_path('PATH') compilers = [ c for c in spack.compilers.find_compilers(*args.add_paths) if c.spec not in spack.compilers.all_compilers() ] if compilers: spack.compilers.add_compilers_to_config('user', *compilers) n = len(compilers) tty.msg("Added %d new compiler%s to %s" % (n, 's' if n > 1 else '', spack.config.get_filename('user'))) colify(reversed(sorted(c.spec for c in compilers)), indent=4) else: tty.msg("Found no new compilers")