Ejemplo n.º 1
0
  def _lint(self, target, classpath):
    self.context.log.debug('Linting {0}'.format(target.address.spec))

    config_args = []

    config_args.extend(self.get_options().linter_args)

    # N.B. We always set --fatal-warnings to make sure errors like missing-namespace are at least printed.
    # If --no-strict is turned on, the return code will be 0 instead of 1, but the errors/warnings
    # need to always be printed.
    config_args.append('--fatal-warnings')
    if not self._is_strict(target):
      config_args.append('--ignore-errors')

    paths = list(target.sources_relative_to_buildroot())
    include_paths = calculate_include_paths([target], self._is_thrift)
    if target.include_paths:
      include_paths |= set(target.include_paths)
    for p in include_paths:
      config_args.extend(['--include-path', p])

    args = config_args + paths

    # If runjava returns non-zero, this marks the workunit as a
    # FAILURE, and there is no way to wrap this here.
    returncode = self.runjava(classpath=classpath,
                              main='com.twitter.scrooge.linter.Main',
                              args=args,
                              jvm_options=self.get_options().jvm_options,
                              # to let stdout/err through, but don't print tool's label.
                              workunit_labels=[WorkUnitLabel.COMPILER, WorkUnitLabel.SUPPRESS_LABEL])

    if returncode != 0:
      raise ThriftLintError(
        'Lint errors in target {0} for {1}.'.format(target.address.spec, paths))
Ejemplo n.º 2
0
    def gen(self, partial_cmd, target, target_workdir):
        import_paths = calculate_include_paths([target], self.is_gentarget)

        args = list(partial_cmd.compiler_args)

        if partial_cmd.default_java_namespace:
            args.extend([
                "--default-java-namespace", partial_cmd.default_java_namespace
            ])

        for import_path in import_paths:
            args.extend(["--import-path", import_path])

        args.extend(["--language", partial_cmd.language])

        for lhs, rhs in partial_cmd.namespace_map:
            args.extend(["--namespace-map", f"{lhs}={rhs}"])

        args.extend(["--dest", target_workdir])

        if not self.get_options().strict:
            args.append("--disable-strict")

        if partial_cmd.include_paths:
            for include_path in partial_cmd.include_paths:
                args.extend(["--include-path", include_path])

        if self.get_options().verbose:
            args.append("--verbose")

        gen_file_map_path = os.path.relpath(self._tempname())
        args.extend(["--gen-file-map", gen_file_map_path])

        args.extend(target.sources_relative_to_buildroot())

        classpath = self.tool_classpath("scrooge-gen")
        jvm_options = list(self.get_options().jvm_options)
        jvm_options.append("-Dfile.encoding=UTF-8")
        returncode = self.runjava(
            classpath=classpath,
            main="com.twitter.scrooge.Main",
            jvm_options=jvm_options,
            args=args,
            workunit_name="scrooge-gen",
        )
        if 0 != returncode:
            raise TaskError(
                f"Scrooge compiler exited non-zero for {target} ({returncode})"
            )
Ejemplo n.º 3
0
    def gen(self, partial_cmd, target, target_workdir):
        import_paths = calculate_include_paths([target], self.is_gentarget)

        args = list(partial_cmd.compiler_args)

        if partial_cmd.default_java_namespace:
            args.extend([
                '--default-java-namespace', partial_cmd.default_java_namespace
            ])

        for import_path in import_paths:
            args.extend(['--import-path', import_path])

        args.extend(['--language', partial_cmd.language])

        for lhs, rhs in partial_cmd.namespace_map:
            args.extend(['--namespace-map', '%s=%s' % (lhs, rhs)])

        args.extend(['--dest', target_workdir])

        if not self.get_options().strict:
            args.append('--disable-strict')

        if partial_cmd.include_paths:
            for include_path in partial_cmd.include_paths:
                args.extend(['--include-path', include_path])

        if self.get_options().verbose:
            args.append('--verbose')

        gen_file_map_path = os.path.relpath(self._tempname())
        args.extend(['--gen-file-map', gen_file_map_path])

        args.extend(target.sources_relative_to_buildroot())

        classpath = self.tool_classpath('scrooge-gen')
        jvm_options = list(self.get_options().jvm_options)
        jvm_options.append('-Dfile.encoding=UTF-8')
        returncode = self.runjava(classpath=classpath,
                                  main='com.twitter.scrooge.Main',
                                  jvm_options=jvm_options,
                                  args=args,
                                  workunit_name='scrooge-gen')
        if 0 != returncode:
            raise TaskError(
                'Scrooge compiler exited non-zero for {} ({})'.format(
                    target, returncode))
Ejemplo n.º 4
0
  def gen(self, partial_cmd, target, target_workdir):
    import_paths = calculate_include_paths([target], self.is_gentarget)

    args = list(partial_cmd.compiler_args)

    if partial_cmd.default_java_namespace:
      args.extend(['--default-java-namespace', partial_cmd.default_java_namespace])

    for import_path in import_paths:
      args.extend(['--import-path', import_path])

    args.extend(['--language', partial_cmd.language])

    for lhs, rhs in partial_cmd.namespace_map:
      args.extend(['--namespace-map', '%s=%s' % (lhs, rhs)])

    args.extend(['--dest', target_workdir])

    if not self.get_options().strict:
      args.append('--disable-strict')

    if partial_cmd.include_paths:
      for include_path in partial_cmd.include_paths:
        args.extend(['--include-path', include_path])

    if self.get_options().verbose:
      args.append('--verbose')

    gen_file_map_path = os.path.relpath(self._tempname())
    args.extend(['--gen-file-map', gen_file_map_path])

    args.extend(target.sources_relative_to_buildroot())

    classpath = self.tool_classpath('scrooge-gen')
    jvm_options = list(self.get_options().jvm_options)
    jvm_options.append('-Dfile.encoding=UTF-8')
    returncode = self.runjava(classpath=classpath,
                              main='com.twitter.scrooge.Main',
                              jvm_options=jvm_options,
                              args=args,
                              workunit_name='scrooge-gen')
    if 0 != returncode:
      raise TaskError('Scrooge compiler exited non-zero for {} ({})'.format(target, returncode))
Ejemplo n.º 5
0
    def _lint(self, target, classpath):
        self.context.log.debug(f'Linting {target.address.spec}')

        config_args = []

        config_args.extend(self.get_options().linter_args)
        config_args.extend(ScroogeLinter.global_instance().options.args)

        if self._is_strict(target):
            config_args.append('--fatal-warnings')
        else:
            # Make sure errors like missing-namespace are at least printed.
            config_args.append('--warnings')

        if self.get_options().ignore_errors:
            config_args.append('--ignore-errors')

        paths = list(target.sources_relative_to_buildroot())
        include_paths = calculate_include_paths([target], self._is_thrift)
        if target.include_paths:
            include_paths |= set(target.include_paths)
        for p in include_paths:
            config_args.extend(['--include-path', p])

        args = config_args + paths

        # If runjava returns non-zero, this marks the workunit as a
        # FAILURE, and there is no way to wrap this here.
        returncode = self.runjava(
            classpath=classpath,
            main='com.twitter.scrooge.linter.Main',
            args=args,
            jvm_options=self.get_options().jvm_options,
            # to let stdout/err through, but don't print tool's label.
            workunit_labels=[
                WorkUnitLabel.COMPILER, WorkUnitLabel.SUPPRESS_LABEL
            ])

        if returncode != 0:
            raise ThriftLintError(
                f'Lint errors in target {target.address.spec} for {paths}.')
Ejemplo n.º 6
0
    def _lint(self, target, classpath):
        self.context.log.debug('Linting {0}'.format(target.address.spec))

        config_args = []

        config_args.extend(self.get_options().linter_args)

        # N.B. We always set --fatal-warnings to make sure errors like missing-namespace are at least printed.
        # If --no-strict is turned on, the return code will be 0 instead of 1, but the errors/warnings
        # need to always be printed.
        config_args.append('--fatal-warnings')
        if not self._is_strict(target):
            config_args.append('--ignore-errors')

        paths = list(target.sources_relative_to_buildroot())
        include_paths = calculate_include_paths([target], self._is_thrift)
        if target.include_paths:
            include_paths |= set(target.include_paths)
        for p in include_paths:
            config_args.extend(['--include-path', p])

        args = config_args + paths

        # If runjava returns non-zero, this marks the workunit as a
        # FAILURE, and there is no way to wrap this here.
        returncode = self.runjava(
            classpath=classpath,
            main='com.twitter.scrooge.linter.Main',
            args=args,
            jvm_options=self.get_options().jvm_options,
            # to let stdout/err through, but don't print tool's label.
            workunit_labels=[
                WorkUnitLabel.COMPILER, WorkUnitLabel.SUPPRESS_LABEL
            ])

        if returncode != 0:
            raise ThriftLintError('Lint errors in target {0} for {1}.'.format(
                target.address.spec, paths))