Пример #1
0
    def _compile(self):
        thrift_src_dir_path = os.path.join(ROOT_DIR_PATH, 'thrift', 'src')
        assert os.path.isdir(thrift_src_dir_path)

        java_generator = \
            JavaGenerator(
                default_methods=True,
                function_overloads=True,
                namespace_prefix='io.github.minorg.'
            )
        lint_generator = LintGenerator()

        for pass_i in xrange(2):
            # Two passes: one to test-compile all .thrift files, the other to generate them
            # ASTs are cached in the compiler so this only costs us the file system traversal,
            # and avoids generating code when there's a compilation error
            for thrift_file_path in self._get_thrift_file_paths(
                    thrift_src_dir_path):
                compile_kwds = {
                    'document_root_dir_path': thrift_src_dir_path,
                    'thrift_file_path': thrift_file_path
                }

                if pass_i == 0:
                    self._compile_thrift_file(generator=lint_generator,
                                              **compile_kwds)

                    continue

                self._compile_thrift_file(generator=java_generator,
                                          out=os.path.join(
                                              ROOT_DIR_PATH, 'java', 'src',
                                              'gen', 'java'),
                                          **compile_kwds)
Пример #2
0
    def _compile(self):
        generators = {
            'cpp': (CppGenerator(), ),
            'java': (JavaGenerator(), ),
            'py': (PyGenerator(), ),
        }

        for in_dir_path, out_dir_paths in (
            (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'thrift', 'src',
                          'thryft', 'native'), {
                              'cpp': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib',
                                                   'cpp', 'include'), )
                          }),
            (
                os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'thrift', 'test'),
                {
                    'cpp': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'cpp',
                                         'test'), ),
                    'java': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'java',
                                          'src', 'test', 'java'), ),
                    'py': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'py',
                                        'test'), ),
                },
            ),
            (
                os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'thrift', 'src',
                             'thryft', 'protocol'),
                {
                    'cpp': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'cpp',
                                         'include'), ),
                    'java': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'java',
                                          'src', 'main', 'java'), ),
                    'py': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'py',
                                        'src'), ),
                },
            ),
        ):
            for thrift_file_path in self._get_thrift_file_paths(in_dir_path):
                if os.path.splitext(
                        os.path.split(thrift_file_path)[1])[0] in ('float',
                                                                   'i8', 'u32',
                                                                   'u64',
                                                                   'variant'):
                    continue

                compile_kwds = {
                    'document_root_dir_path': in_dir_path,
                    'thrift_file_path': thrift_file_path
                }

                self._compile_thrift_file(generator=LintGenerator(),
                                          **compile_kwds)

                for gen_name, generator in generators.iteritems():
                    for out_dir_path in out_dir_paths.get(gen_name, []):
                        self._compile_thrift_file(generator=generator[0],
                                                  out=out_dir_path,
                                                  **compile_kwds)
Пример #3
0
    def _get_compile_tasks(self):
        gen = self._gen

        generators = {
            'cpp': (CppGenerator(), ),
            'java': (JavaGenerator(), ),
            'js': (JsGenerator(), ),
            'py': (PyGenerator(), ),
        }

        for in_dir_path, out_dir_paths in ((
                os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'thrift', 'test'),
            {
                'cpp': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'cpp',
                                     'test'), ),
                'java': (
                    os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'java',
                                 'protocol', 'src', 'test', 'java'),
                    os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'java', 'store',
                                 'src', 'test', 'java'),
                ),
                'js': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'js',
                                    'test'), ),
                'py': (os.path.join(THRYFT_ROOT_DIR_PATH, 'lib', 'py',
                                    'test'), ),
            },
        ), ):
            for dir_path, _, file_names in os.walk(in_dir_path):
                for file_name in file_names:
                    file_base_name, file_ext = os.path.splitext(file_name)
                    if file_ext != '.thrift':
                        continue
                    elif os.path.isfile(
                            os.path.join(dir_path, file_base_name + '.py')):
                        continue
                    thrift_file_path = os.path.join(dir_path, file_name)

                    compile_task_kwds = {'thrift_file_path': thrift_file_path}

                    if self._dry_run:
                        yield self._CompileTask(generator=None,
                                                out=None,
                                                **compile_task_kwds)
                        continue

                    if len(gen) == 0:
                        gen_names = generators.keys()
                    else:
                        gen_names = gen.keys()
                    for gen_name in gen_names:
                        for generator in generators[gen_name]:
                            for out_dir_path in out_dir_paths[gen_name]:
                                yield \
                                    self._CompileTask(
                                        generator=generator,
                                        out=out_dir_path,
                                        **compile_task_kwds
                                    )
Пример #4
0
 def __init__(self, project_name, **kwds):
     JavaGenerator.__init__(self, **kwds)
     self._project_name = project_name
Пример #5
0
 def __init__(self, **kwds):
     JavaGenerator.__init__(self, mutable_compound_types=True, **kwds)
Пример #6
0
 def __init__(self, **kwds):
     JavaGenerator.__init__(self, mutable_compound_types=True, **kwds)