def _lint(self, target): self.context.log.debug('Linting {0}'.format(target.address.spec)) classpath = self.tool_classpath('scrooge-linter') config_args = [] config_args.extend(self.get_options().linter_args) if not self._is_strict(target): config_args.append('--ignore-errors') include_paths , paths = calculate_compile_sources([target], self._is_thrift) for p in include_paths: config_args.extend(['--include-path', p]) args = config_args + list(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, workunit_labels=[WorkUnitLabel.COMPILER]) # to let stdout/err through. if returncode != 0: raise ThriftLintError( 'Lint errors in target {0} for {1}.'.format(target.address.spec, paths))
def _lint(self, target): self.context.log.debug('Linting {0}'.format(target.address.spec)) classpath = self.tool_classpath('scrooge-linter') config_args = [] config_args.extend(self.get_options().linter_args) if not self._is_strict(target): config_args.append('--ignore-errors') include_paths, paths = calculate_compile_sources([target], self._is_thrift) for p in include_paths: config_args.extend(['--include-path', p]) args = config_args + list(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, workunit_labels=[ WorkUnitLabel.COMPILER ]) # to let stdout/err through. if returncode != 0: raise ThriftLintError('Lint errors in target {0} for {1}.'.format( target.address.spec, paths))
def gen(self, partial_cmd, invalid_targets): for vt in invalid_targets: outdir = self.codegen_workdir(vt) import_paths, dummy_changed_srcs = calculate_compile_sources(invalid_targets, self.is_gentarget) changed_srcs = vt.sources_relative_to_buildroot() if changed_srcs: args = [] 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)]) if partial_cmd.rpc_style == 'ostrich': args.append('--finagle') args.append('--ostrich') elif partial_cmd.rpc_style == 'finagle': args.append('--finagle') args.extend(['--dest', outdir]) safe_mkdir(outdir) if not self.get_options().strict: args.append('--disable-strict') 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(changed_srcs) 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') try: if 0 == returncode: gen_files_for_source = self.parse_gen_file_map(gen_file_map_path, outdir) else: gen_files_for_source = None finally: os.remove(gen_file_map_path) if 0 != returncode: raise TaskError('Scrooge compiler exited non-zero ({0})'.format(returncode))
def gen(self, partial_cmd, target, target_workdir): import_paths, _ = calculate_compile_sources([target], self.is_gentarget) 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)]) if partial_cmd.rpc_style == 'ostrich': args.append('--finagle') args.append('--ostrich') elif partial_cmd.rpc_style == 'finagle': args.append('--finagle') 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))
def gen(self, partial_cmd, target, target_workdir): import_paths, _ = calculate_compile_sources([target], self.is_gentarget) 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)]) if partial_cmd.rpc_style == 'ostrich': args.append('--finagle') args.append('--ostrich') elif partial_cmd.rpc_style == 'finagle': args.append('--finagle') 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))
def gen(self, partial_cmd, target, target_workdir): import_paths, _ = calculate_compile_sources([target], self.is_gentarget) args = [] 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)]) if partial_cmd.rpc_style == "ostrich": args.append("--finagle") args.append("--ostrich") elif partial_cmd.rpc_style == "finagle": args.append("--finagle") args.extend(["--dest", target_workdir]) if not self.get_options().strict: args.append("--disable-strict") 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))
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') include_paths, paths = calculate_compile_sources([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 + list(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))
def calc_srcs(target): _, srcs = calculate_compile_sources([target], self.is_scroogetarget) return srcs
def gen(self, partial_cmd, targets): fp_strategy = JavaThriftLibraryFingerprintStrategy(self._thrift_defaults) with self.invalidated(targets, fingerprint_strategy=fp_strategy, invalidate_dependents=True) as invalidation_check: invalid_targets = [] for vt in invalidation_check.invalid_vts: invalid_targets.extend(vt.targets) import_paths, changed_srcs = calculate_compile_sources(invalid_targets, self.is_scroogetarget) outdir = self._outdir(partial_cmd) if changed_srcs: args = [] 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)]) if partial_cmd.rpc_style == 'ostrich': args.append('--finagle') args.append('--ostrich') elif partial_cmd.rpc_style == 'finagle': args.append('--finagle') args.extend(['--dest', outdir]) safe_mkdir(outdir) if not self.get_options().strict: args.append('--disable-strict') 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(changed_srcs) 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') try: if 0 == returncode: gen_files_for_source = self.parse_gen_file_map(gen_file_map_path, outdir) else: gen_files_for_source = None finally: os.remove(gen_file_map_path) if 0 != returncode: raise TaskError('Scrooge compiler exited non-zero ({0})'.format(returncode)) self.write_gen_file_map(gen_files_for_source, invalid_targets, outdir) return self.gen_file_map(targets, outdir)