https://pantsbuild.org/ logo
#general
Title
# general
b

brief-engineer-67497

11/07/2018, 11:16 AM
I'm trying to write a code generating task. This core logic require to run javac with a specfic jar in the classpath and a given set of arguments. So far I've written this:
Copy code
class QueryDslGen(SimpleCodegenTask, JavacCompile):
    def __init__(self, *args, **kwargs):
        super(QueryDslGen, self).__init__(*args, **kwargs)

    def synthetic_target_type(self, target):
        return JavaLibrary

    def is_gentarget(self, target):
        return isinstance(target, QueryDslLibrary)

    def execute_codegen(self, target, target_workdir):
        if not isinstance(target, QueryDslLibrary):
            raise TaskError('Invalid target type "{class_type}" (expected QueryDslLibrary)'
                            .format(class_type=type(target).__name__))

        result = ???

        if result != 0:
            raise TaskError('twirl-gen ... exited non-zero ({code})'.format(code=result))

    @classmethod
    def get_args_default(cls, bootstrap_option_values):
        return super(JavacCompile, cls).get_args_default(cls, bootstrap_option_values) + ('-proc:only', '-processor', 'com.querydsl.apt.jpa.JPAAnnotationProcessor', '-s', target_workdir)
obviously I cannot use the
get_args_default
to pass the argument since I need the
target_workdir
value passed to
execute_codegen
. I suppose I need to use
self.context.options
somehow but I'm not sure how. Furthermore I'm a complete python newbie so I'm not sure how python will work with regards to the multiple inheritance and the diamond I've got here
4 Views