예제 #1
0
    def compiled_idl(cls,
                     idl_dep,
                     generated_deps=None,
                     compiler=None,
                     language=None,
                     namespace_map=None):
        """Marks a jar as containing IDL files that should be fetched and processed locally.

    idl_dep:        A dependency resolvable to a single jar library.
    generated_deps: Dependencies for the code that will be generated from "idl_dep"
    compiler:       The thrift compiler to apply to the fetched thrift IDL files.
    language:       The language to generate code for - supported by some compilers
    namespace_map:  A mapping from IDL declared namespaces to custom namespaces - supported by some
                    compilers.
    """
        deps = list(filter(is_concrete, idl_dep.resolve()))
        if not len(deps) == 1:
            raise TaskError(
                'Can only arrange for compiled idl for a single dependency at a time, '
                'given:\n\t%s' % '\n\t'.join(map(str, deps)))
        jar = deps.pop()
        if not isinstance(jar, JarDependency):
            raise TaskError(
                'Can only arrange for compiled idl from a jar dependency, given: %s'
                % jar)

        request = (jar, compiler, language)
        namespace_signature = None
        if namespace_map:
            sha = hashlib.sha1()
            for ns_from, ns_to in sorted(namespace_map.items()):
                sha.update(ns_from)
                sha.update(ns_to)
            namespace_signature = sha.hexdigest()
        request += (namespace_signature, )

        if request not in cls._PLACEHOLDER_BY_REQUEST:
            if not cls._EXTRACT_BASE:
                config = Config.load()
                cls._EXTRACT_BASE = config.get('idl-extract', 'workdir')
                safe_mkdir(cls._EXTRACT_BASE)
                SourceRoot.register(cls._EXTRACT_BASE, JavaThriftLibrary)

            with ParseContext.temp(cls._EXTRACT_BASE):
                # TODO(John Sirois): abstract ivy specific configurations notion away
                jar._configurations.append('idl')
                jar.with_artifact(configuration='idl', classifier='idl')
                target_name = '-'.join(
                    filter(None,
                           (jar.id, compiler, language, namespace_signature)))
                placeholder = JavaThriftLibrary(target_name,
                                                sources=None,
                                                dependencies=[jar] +
                                                (generated_deps or []),
                                                compiler=compiler,
                                                language=language,
                                                namespace_map=namespace_map)
                cls._PLACEHOLDER_BY_REQUEST[request] = placeholder
                cls._PLACEHOLDERS_BY_JAR[jar].append(placeholder)
        return cls._PLACEHOLDER_BY_REQUEST[request]
예제 #2
0
파일: extract.py 프로젝트: alfss/commons
  def compiled_idl(cls, idl_dep, generated_deps=None, compiler=None, language=None, namespace_map=None):
    """Marks a jar as containing IDL files that should be fetched and processed locally.

    idl_dep:        A dependency resolvable to a single jar library.
    generated_deps: Dependencies for the code that will be generated from "idl_dep"
    compiler:       The thrift compiler to apply to the fetched thrift IDL files.
    language:       The language to generate code for - supported by some compilers
    namespace_map:  A mapping from IDL declared namespaces to custom namespaces - supported by some
                    compilers.
    """
    deps = [t for t in idl_dep.resolve() if t.is_concrete]
    if not len(deps) == 1:
      raise TaskError('Can only arrange for compiled idl for a single dependency at a time, '
                      'given:\n\t%s' % '\n\t'.join(map(str, deps)))
    jar = deps.pop()
    if not isinstance(jar, JarDependency):
      raise TaskError('Can only arrange for compiled idl from a jar dependency, given: %s' % jar)

    request = (jar, compiler, language)
    namespace_signature = None
    if namespace_map:
      sha = hashlib.sha1()
      for ns_from, ns_to in sorted(namespace_map.items()):
        sha.update(ns_from)
        sha.update(ns_to)
      namespace_signature = sha.hexdigest()
    request += (namespace_signature,)

    if request not in cls._PLACEHOLDER_BY_REQUEST:
      if not cls._EXTRACT_BASE:
        config = Config.load()
        cls._EXTRACT_BASE = config.get('idl-extract', 'workdir')
        safe_mkdir(cls._EXTRACT_BASE)
        SourceRoot.register(cls._EXTRACT_BASE, JavaThriftLibrary)

      with ParseContext.temp(cls._EXTRACT_BASE):
        # TODO(John Sirois): abstract ivy specific configurations notion away
        jar._configurations.append('idl')
        jar.with_artifact(configuration='idl', classifier='idl')
        target_name = '-'.join(filter(None, (jar.id, compiler, language, namespace_signature)))
        placeholder = JavaThriftLibrary(target_name,
                                        sources=None,
                                        dependencies=[jar] + (generated_deps or []),
                                        compiler=compiler,
                                        language=language,
                                        namespace_map=namespace_map)
        cls._PLACEHOLDER_BY_REQUEST[request] = placeholder
        cls._PLACEHOLDERS_BY_JAR[jar].append(placeholder)
    return cls._PLACEHOLDER_BY_REQUEST[request]
예제 #3
0
    def is_test(source_set):
      if source_set.is_test:
        return True

      # Non test targets that otherwise live in test target roots (say a java_library), must
      # be marked as test for IDEA to correctly link the targets with the test code that uses
      # them.
      base = source_set.source_base
      if base not in is_test_by_base:
        is_test_by_base[base] = any(map(is_test_target_type, SourceRoot.types(base)))
      istest = is_test_by_base[base]
      if istest:
        self.context.log.debug('Marked non-test source set as test (%s, %s)' % (
          source_set.source_base, source_set.path
        ))
      return istest
예제 #4
0
 def console_output(self, targets):
   for src_root, targets in SourceRoot.all_roots().items():
     all_targets = ','.join(sorted([tgt.__name__ for tgt in targets]))
     yield '%s: %s' % (src_root, all_targets or '*')