示例#1
0
 def __call__(self, parser, namespace, value, *args, **kwargs):
     try:
         delattr(namespace, family_attr)
     except AttributeError:
         pass
     family = InstalledCompilerFamily(kbase.families[value])
     for comp in family:
         setattr(namespace, comp.info.role.keyword, comp.absolute_path)
示例#2
0
 def _configure_argument_group(self, group, kbase, family_flag, family_attr,
                               hint):
     # Check environment variables for default compilers.
     compilers = {
         role: self._get_compiler_from_env(role)
         for role in kbase.roles.itervalues()
     }
     # Use the result of previous compiler detection to find compilers not specified in the environment
     if hint:
         try:
             family = InstalledCompilerFamily(kbase.families[hint])
         except ConfigurationError as err:
             # Something wrong with that installation... oh well, keep going
             self.logger.debug(err)
         except KeyError:
             # Suggested family might not support this compiler group,
             # e.g. Intel doesn't have SHMEM compilers.
             pass
         else:
             for role, comp in compilers.iteritems():
                 if comp is None and role in family:
                     compilers[role] = family[role]
     sibling = next(
         (comp for comp in compilers.itervalues() if comp is not None),
         None)
     for role, comp in compilers.iteritems():
         if not comp:
             if sibling:
                 # If some compilers found, but not all, then use compiler
                 # family information to get default compilers.
                 compilers[role] = self._get_compiler_from_sibling(
                     role, sibling)
             else:
                 # No environment variables specify compiler defaults so use model defaults.
                 compilers[role] = self._get_compiler_from_defaults(
                     kbase, role)
     # Use the majority family as the default compiler family.
     family_count = Counter(comp.info.family
                            for comp in compilers.itervalues()
                            if comp is not None)
     try:
         family_default = family_count.most_common()[0][0].name
     except IndexError:
         family_default = arguments.SUPPRESS
     # Add the compiler family flag. If the knowledgebase keyword isn't all-caps then show in lower case.
     keyword = kbase.keyword
     if keyword.upper() != keyword:
         keyword = keyword.lower()
     group.add_argument(
         family_flag,
         help=
         ("select all %(kw)s compilers automatically from the given family, "
          "ignored if at least one %(kw)s compiler is specified") %
         {'kw': keyword},
         metavar='<family>',
         dest=family_attr,
         default=family_default,
         choices=kbase.family_names(),
         action=TargetCreateCommand._family_flag_action(kbase, family_attr))
     # Monkey-patch default actions for compiler arguments
     # pylint: disable=protected-access
     for role, comp in compilers.iteritems():
         action = next(act for act in group._actions
                       if act.dest == role.keyword)
         action.default = comp.absolute_path if comp else arguments.SUPPRESS
         action.__action_call__ = action.__call__
         action.__call__ = TargetCreateCommand._compiler_flag_action_call(
             family_attr)
     # Use the name of the default compiler family as a hint for the next search
     return family_default