diff --git a/3rdparty/jvm/com/twitter/BUILD b/3rdparty/jvm/com/twitter/BUILD deleted file mode 100644 index 00b766b6d02..00000000000 --- a/3rdparty/jvm/com/twitter/BUILD +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -SCROOGE_REV = '18.12.0' - -jar_library(name='finagle-thrift', - jars=[ - scala_jar(org='com.twitter', name='finagle-thrift', rev=SCROOGE_REV), - ], -) - -jar_library(name='scrooge-core', - jars=[ - scala_jar(org='com.twitter', name='scrooge-core', rev=SCROOGE_REV), - ], -) - - diff --git a/BUILD b/BUILD index 429e005fed6..840e6b031c5 100644 --- a/BUILD +++ b/BUILD @@ -13,11 +13,6 @@ files( sources = ["BUILD_ROOT"], ) -files( - name = 'build_tools', - sources = ['BUILD.tools'], -) - files( name = 'gitignore', sources = ['.gitignore'], diff --git a/BUILD.tools b/BUILD.tools deleted file mode 100644 index cc1c05f44a9..00000000000 --- a/BUILD.tools +++ /dev/null @@ -1,36 +0,0 @@ -# JVM artifacts that Pants itself depends on. -# http://pantsbuild.github.io/dev_tasks.html#jvm-tool-bootstrapping - -# TODO: Attempting to use these targets fails because BootstrapJvmTools.get_alternate_target_roots() -# doesn't descend into dependent target directories and uses the same build_graph it starts with. -# target( -# name='scrooge-gen', -# dependencies=[ -# '3rdparty/jvm/com/twitter:scrooge-gen', -# ], -# ) - -# target( -# name='scrooge-linter', -# dependencies=[ -# '3rdparty/jvm/com/twitter:scrooge-linter', -# ], -# ) - -SCROOGE_REV = '18.12.0' - -# NB: The scrooge tools do not mix their classpaths with the sources they interact with, and -# therefore they do not need to use the `scala-platform` via scala_jar. -jar_library( - name = 'scrooge-gen', - jars = [ - jar(org='com.twitter', name='scrooge-generator_2.11', rev=SCROOGE_REV), - ], -) - -jar_library( - name = 'scrooge-linter', - jars = [ - jar(org='com.twitter', name='scrooge-linter_2.11', rev=SCROOGE_REV), - ], -) diff --git a/build-support/bin/packages.py b/build-support/bin/packages.py index dd87a694adf..a187cfb7e5b 100644 --- a/build-support/bin/packages.py +++ b/build-support/bin/packages.py @@ -91,10 +91,6 @@ def core_packages() -> Set[Package]: def contrib_packages() -> Set[Package]: return { - Package( - "pantsbuild.pants.contrib.scrooge", - "contrib/scrooge/src/python/pants/contrib/scrooge:plugin", - ), Package( "pantsbuild.pants.contrib.mypy", "contrib/mypy/src/python/pants/contrib/mypy:plugin", ), diff --git a/contrib/BUILD b/contrib/BUILD index a444866c8c9..322dbc21fcb 100644 --- a/contrib/BUILD +++ b/contrib/BUILD @@ -5,7 +5,6 @@ target( name = 'plugins', dependencies = [ 'contrib/mypy/src/python/pants/contrib/mypy:plugin', - 'contrib/scrooge/src/python/pants/contrib/scrooge:plugin', ] ) diff --git a/contrib/README.md b/contrib/README.md index 836935011f0..3690337e585 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -9,8 +9,7 @@ plugin APIs are used. Most new plugins should get their own top-level `contrib/` subdirectory although it may make sense to house the source code for related plugins under one top-level `contrib/` subdirectory. The -`contrib/scrooge` directory is an example of this and houses two plugin tasks that both use the same -underlying [Scrooge](https://github.com/twitter/scrooge) tool. +`contrib/mypy` directory is an example of this. Contrib plugins should generally follow 3 basic setup steps: diff --git a/contrib/release_packages.sh b/contrib/release_packages.sh index 21b773b8433..1ece154e15a 100644 --- a/contrib/release_packages.sh +++ b/contrib/release_packages.sh @@ -6,16 +6,6 @@ # `PKG_$NAME` definition. # -function pkg_scrooge_install_test() { - local version=$1 - execute_packaged_pants_with_internal_backends \ - --plugins="['pantsbuild.pants.contrib.scrooge==${version}']" \ - --explain gen | grep "scrooge" &> /dev/null && \ - execute_packaged_pants_with_internal_backends \ - --plugins="['pantsbuild.pants.contrib.scrooge==${version}']" \ - --explain lint | grep "thrift" &> /dev/null -} - function pkg_mypy_install_test() { local version=$1 execute_packaged_pants_with_internal_backends \ diff --git a/contrib/scrooge/BUILD b/contrib/scrooge/BUILD deleted file mode 100644 index ae6fc0822b7..00000000000 --- a/contrib/scrooge/BUILD +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -files( - name='scala_tests_directory', - sources=['tests/scala/**/*'], -) - -files( - name='thrift_tests_directory', - sources=['tests/thrift/**/*'], -) diff --git a/contrib/scrooge/README.md b/contrib/scrooge/README.md deleted file mode 100644 index 2782b3cf79a..00000000000 --- a/contrib/scrooge/README.md +++ /dev/null @@ -1,6 +0,0 @@ -Pants plugins to support the [Scrooge](https://github.com/twitter/scrooge) thrift code generator -================================================================================================ - -Currently there is a code gen plugin for generating java and scala struct and rpc bindings for -thrift IDLs as well as a thrift-linter plugin for running basic lint checks against thrift IDLs -that will be used with the scrooge code generator. diff --git a/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/android_generator/BUILD b/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/android_generator/BUILD deleted file mode 100644 index 01bb0edf89a..00000000000 --- a/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/android_generator/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -java_thrift_library( - sources=['struct.thrift'], - compiler='scrooge', - language='android', - compiler_args=['--finagle'], - dependencies=[ - '3rdparty:thrift', - 'contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/dummy_generator:dummy_generator' - ], -) diff --git a/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/android_generator/struct.thrift b/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/android_generator/struct.thrift deleted file mode 100644 index 17646d5cb93..00000000000 --- a/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/android_generator/struct.thrift +++ /dev/null @@ -1,30 +0,0 @@ -#@namespace android thrift.android.test - -include "contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/dummy_generator/dummy.thrift" - -typedef i32 MyInteger - -enum Day { - Mon = 1, - Tue = 2, -} - -struct Other { -} - -struct Work { - 1: i32 num1 = 0, - 2: MyInteger num2, - 3: optional string comment, - 4: set test_set, - 5: double d1, - 6: map test_map, - 7: binary test_binary, - 8: required i64 req_int, - 9: required Day day = 1, - 10: required Other other, - 11: list test_list, - 12: required list user_ids, - 13: list other_list, - 14: required dummy.Krow krow, -} diff --git a/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/dummy_generator/BUILD b/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/dummy_generator/BUILD deleted file mode 100644 index 76e951f62ea..00000000000 --- a/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/dummy_generator/BUILD +++ /dev/null @@ -1,8 +0,0 @@ -java_thrift_library( - sources=['dummy.thrift'], - compiler='scrooge', - language='android', - compiler_args=['--finagle'], - dependencies=['3rdparty:thrift'], - tags=['nolint'] -) diff --git a/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/dummy_generator/dummy.thrift b/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/dummy_generator/dummy.thrift deleted file mode 100644 index 4a70b26e30e..00000000000 --- a/contrib/scrooge/examples/src/thrift/org/pantsbuild/contrib/scrooge/dummy_generator/dummy.thrift +++ /dev/null @@ -1,10 +0,0 @@ -#@namespace android thrift.dummy.test -typedef i32 MyInteger - -struct Rehto { -} - -struct Krow { - 1: i32 num1 = 0, - 2: MyInteger num2, -} diff --git a/contrib/scrooge/src/python/pants/__init__.py b/contrib/scrooge/src/python/pants/__init__.py deleted file mode 100644 index 5284146ebf2..00000000000 --- a/contrib/scrooge/src/python/pants/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__("pkg_resources").declare_namespace(__name__) diff --git a/contrib/scrooge/src/python/pants/contrib/__init__.py b/contrib/scrooge/src/python/pants/contrib/__init__.py deleted file mode 100644 index 5284146ebf2..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__("pkg_resources").declare_namespace(__name__) diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/BUILD b/contrib/scrooge/src/python/pants/contrib/scrooge/BUILD deleted file mode 100644 index 7c09cf2fb8e..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/BUILD +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -contrib_plugin( - name='plugin', - dependencies=[ - 'contrib/scrooge/src/python/pants/contrib/scrooge/tasks', - 'src/python/pants/goal:task_registrar', - ], - tags = {"partially_type_checked"}, - provides=contrib_setup_py( - name='pantsbuild.pants.contrib.scrooge', - description='Scrooge thrift generator pants plugins.', - additional_classifiers=[ - 'Topic :: Software Development :: Code Generators' - ], - register_goals=True, - ), -) diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/__init__.py b/contrib/scrooge/src/python/pants/contrib/scrooge/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/register.py b/contrib/scrooge/src/python/pants/contrib/scrooge/register.py deleted file mode 100644 index 570a9a9112f..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/register.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -"""Thrift code generator. - -See https://github.com/twitter/scrooge. -""" - -from pants.goal.task_registrar import TaskRegistrar as task - -from pants.contrib.scrooge.tasks.scrooge_gen import ScroogeGen -from pants.contrib.scrooge.tasks.thrift_linter_task import ThriftLinterTask - - -def register_goals(): - task(name="thrift", action=ThriftLinterTask).install("lint") - task(name="scrooge", action=ScroogeGen).install("gen") diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/subsystems/BUILD b/contrib/scrooge/src/python/pants/contrib/scrooge/subsystems/BUILD deleted file mode 100644 index d2c4f0eaccc..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/subsystems/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -python_library( - dependencies = [ - 'src/python/pants/backend/python/subsystems', - 'src/python/pants/option', - ], - tags = {"partially_type_checked"}, -) diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/subsystems/__init__.py b/contrib/scrooge/src/python/pants/contrib/scrooge/subsystems/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/subsystems/scrooge_linter.py b/contrib/scrooge/src/python/pants/contrib/scrooge/subsystems/scrooge_linter.py deleted file mode 100644 index d50693a31cd..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/subsystems/scrooge_linter.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import multiprocessing - -from pants.option.custom_types import shell_str -from pants.subsystem.subsystem import Subsystem - - -class ScroogeLinter(Subsystem): - - options_scope = "scrooge-linter" - - @classmethod - def register_options(cls, register): - super().register_options(register) - register( - "--args", - type=list, - member_type=shell_str, - fingerprint=True, - help="Arguments to pass directly to the Scrooge Thrift linter, e.g. " - '`--scrooge-linter-args="--disable-rule Namespaces"`.', - ) - register( - "--skip", - type=bool, - default=False, - help="Don't use the Scrooge Thrift linter when running `./pants lint`.", - ) - register( - "--strict", - type=bool, - fingerprint=True, - help="Fail the goal if thrift linter errors are found. Overrides the `strict-default` option.", - ) - register( - "--strict-default", - default=False, - advanced=True, - type=bool, - fingerprint=True, - help="Sets the default strictness for targets. The `strict` option overrides this value if " - "it is set.", - ) - register( - "--worker-count", - default=multiprocessing.cpu_count(), - advanced=True, - type=int, - help="Maximum number of workers to use for linter parallelization.", - ) diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/BUILD b/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/BUILD deleted file mode 100644 index 6efdd7f691d..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/BUILD +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -python_library( - dependencies=[ - ':scrooge_gen', - ':thrift_linter', - ], - tags = {"partially_type_checked"}, -) - -python_library( - name='scrooge_gen', - sources=['scrooge_gen.py'], - dependencies=[ - ':java_thrift_library_fingerprint_strategy', - ':thrift_util', - 'src/python/pants/backend/codegen/thrift/java', - 'src/python/pants/backend/jvm/targets:java', - 'src/python/pants/backend/jvm/targets:scala', - 'src/python/pants/backend/jvm/tasks:jvm_tool_task_mixin', - 'src/python/pants/backend/jvm/tasks:nailgun_task', - 'src/python/pants/base:build_environment', - 'src/python/pants/base:exceptions', - 'src/python/pants/build_graph', - 'src/python/pants/option', - 'src/python/pants/task', - 'src/python/pants/util:dirutil', - 'src/python/pants/util:memo', - 'src/python/pants/util:ordered_set', - ], - tags = {"partially_type_checked"}, -) - -python_library( - name='thrift_linter', - sources=['thrift_linter_task.py'], - dependencies=[ - ':thrift_util', - 'contrib/scrooge/src/python/pants/contrib/scrooge/subsystems', - 'src/python/pants/backend/codegen/thrift/java', - 'src/python/pants/backend/jvm/tasks:nailgun_task', - 'src/python/pants/base:exceptions', - 'src/python/pants/base:worker_pool', - 'src/python/pants/base:workunit', - 'src/python/pants/option', - 'src/python/pants/task' - ], - tags = {"partially_type_checked"}, -) - -python_library( - name='thrift_util', - sources=['thrift_util.py'], - tags = {"partially_type_checked"}, -) - -python_library( - name='java_thrift_library_fingerprint_strategy', - sources=['java_thrift_library_fingerprint_strategy.py'], - dependencies=[ - 'src/python/pants/backend/codegen/thrift/java', - 'src/python/pants/base:fingerprint_strategy', - ], - tags = {"partially_type_checked"}, -) diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/__init__.py b/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/java_thrift_library_fingerprint_strategy.py b/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/java_thrift_library_fingerprint_strategy.py deleted file mode 100644 index c628092664d..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/java_thrift_library_fingerprint_strategy.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import hashlib - -from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary -from pants.base.fingerprint_strategy import FingerprintStrategy - - -class JavaThriftLibraryFingerprintStrategy(FingerprintStrategy): - """Scrooge cares about a Thrift target's `language` and `compiler_args` and more in addition to - its payload. - - As such this strategy ensures new code is generated by Scrooge whenever any option that effects - codegen changes. - """ - - def __init__(self, thrift_defaults): - self._thrift_defaults = thrift_defaults - - def compute_fingerprint(self, target): - fp = target.payload.fingerprint() - if not isinstance(target, JavaThriftLibrary): - return fp - - hasher = hashlib.sha1() - hasher.update(fp.encode()) - hasher.update(self._thrift_defaults.language(target).encode()) - hasher.update(str(self._thrift_defaults.compiler_args(target)).encode()) - - namespace_map = self._thrift_defaults.namespace_map(target) - if namespace_map: - hasher.update(str(sorted(namespace_map.items())).encode()) - - default_java_namespace = self._thrift_defaults.default_java_namespace(target) - if default_java_namespace: - hasher.update(default_java_namespace.encode()) - - if target.include_paths: - hasher.update(str(target.include_paths).encode()) - - return hasher.hexdigest() - - def __hash__(self): - return hash((type(self), self._thrift_defaults)) - - def __eq__(self, other): - return type(self) == type(other) and self._thrift_defaults == other._thrift_defaults diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/scrooge_gen.py b/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/scrooge_gen.py deleted file mode 100644 index afe9306fff7..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/scrooge_gen.py +++ /dev/null @@ -1,354 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import os -import re -import tempfile -from collections import defaultdict, namedtuple - -from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary -from pants.backend.codegen.thrift.java.thrift_defaults import ThriftDefaults -from pants.backend.jvm.tasks.nailgun_task import NailgunTask -from pants.base.build_environment import get_buildroot -from pants.base.exceptions import TargetDefinitionException, TaskError -from pants.build_graph.address import Address -from pants.build_graph.address_lookup_error import AddressLookupError -from pants.task.simple_codegen_task import SimpleCodegenTask -from pants.util.dirutil import safe_mkdir, safe_open -from pants.util.memo import memoized_method, memoized_property -from pants.util.ordered_set import OrderedSet - -from pants.contrib.scrooge.tasks.java_thrift_library_fingerprint_strategy import ( - JavaThriftLibraryFingerprintStrategy, -) -from pants.contrib.scrooge.tasks.thrift_util import calculate_include_paths - - -class ScroogeGen(SimpleCodegenTask, NailgunTask): - - DepInfo = namedtuple("DepInfo", ["service", "structs"]) - PartialCmd = namedtuple( - "PartialCmd", - ["language", "namespace_map", "default_java_namespace", "include_paths", "compiler_args"], - ) - - sources_globs = ("**/*",) - - @classmethod - def register_options(cls, register): - super().register_options(register) - register("--verbose", type=bool, help="Emit verbose output.") - register("--strict", fingerprint=True, type=bool, help="Enable strict compilation.") - register( - "--service-deps", - default={}, - advanced=True, - type=dict, - help="A map of language to targets to add as dependencies of " - "synthetic thrift libraries that contain services.", - ) - register( - "--structs-deps", - default={}, - advanced=True, - type=dict, - help="A map of language to targets to add as dependencies of " - "synthetic thrift libraries that contain structs.", - ) - register( - "--service-exports", - default={}, - advanced=True, - type=dict, - help="A map of language to targets to add as exports of " - "synthetic thrift libraries that contain services.", - ) - register( - "--structs-exports", - default={}, - advanced=True, - type=dict, - help="A map of language to targets to add as exports of " - "synthetic thrift libraries that contain structs.", - ) - register( - "--target-types", - default={"scala": "scala_library", "java": "java_library", "android": "java_library"}, - advanced=True, - type=dict, - help="Registered target types.", - ) - register( - "--unchecked-compiler-args", - advanced=True, - type=list, - default=["--java-passthrough"], - help="Don't fail if these options are different between targets." - "Usually, Scrooge requires all targets in the dependency tree to" - "have the same compiler options. However, discrepancies in options" - "specified in this list will not cause the compiler to fail.", - ) - cls.register_jvm_tool(register, "scrooge-gen") - - @classmethod - def subsystem_dependencies(cls): - return super().subsystem_dependencies() + (ThriftDefaults,) - - @classmethod - def product_types(cls): - return ["java", "scala"] - - @classmethod - def implementation_version(cls): - return super().implementation_version() + [("ScroogeGen", 3)] - - @classmethod - def get_fingerprint_strategy(cls): - return JavaThriftLibraryFingerprintStrategy(ThriftDefaults.global_instance()) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self._thrift_defaults = ThriftDefaults.global_instance() - self._depinfo = None - - # TODO(benjy): Use regular os-located tmpfiles, as we do everywhere else. - def _tempname(self): - # don't assume the user's cwd is buildroot - pants_workdir = self.get_options().pants_workdir - tmp_dir = os.path.join(pants_workdir, "tmp") - safe_mkdir(tmp_dir) - fd, path = tempfile.mkstemp(dir=tmp_dir, prefix="") - os.close(fd) - return path - - def _resolve_deps(self, depmap): - """Given a map of gen-key=>address specs, resolves the address specs into references.""" - deps = defaultdict(lambda: OrderedSet()) - for category, depspecs in depmap.items(): - dependencies = deps[category] - for depspec in depspecs: - dep_address = Address.parse(depspec) - try: - self.context.build_graph.maybe_inject_address_closure(dep_address) - dependencies.add(self.context.build_graph.get_target(dep_address)) - except AddressLookupError as e: - raise AddressLookupError(f"{e}\n referenced from {self.options_scope} scope") - return deps - - def _validate_language(self, target): - language = self._thrift_defaults.language(target) - if language not in self._registered_language_aliases(): - raise TargetDefinitionException( - target, - f"language {language} not supported: expected one of {list(self._registered_language_aliases().keys())}.", - ) - return language - - @memoized_method - def _registered_language_aliases(self): - return self.get_options().target_types - - @memoized_method - def _target_type_for_language(self, language): - alias_for_lang = self._registered_language_aliases()[language] - registered_aliases = self.context.build_configuration.registered_aliases() - target_types = registered_aliases.target_types_by_alias.get(alias_for_lang, None) - if not target_types: - raise TaskError( - f"Registered target type `{alias_for_lang}` for language `{language}` does not exist!" - ) - if len(target_types) > 1: - raise TaskError(f"More than one target type registered for language `{language}`") - return next(iter(target_types)) - - def execute_codegen(self, target, target_workdir): - self._validate_compiler_configs(target) - self._must_have_sources(target) - - namespace_map = self._thrift_defaults.namespace_map(target) - partial_cmd = self.PartialCmd( - language=self._validate_language(target), - namespace_map=tuple(sorted(namespace_map.items())) if namespace_map else (), - default_java_namespace=self._thrift_defaults.default_java_namespace(target), - include_paths=target.include_paths, - compiler_args=(self._thrift_defaults.compiler_args(target)), - ) - - self.gen(partial_cmd, target, target_workdir) - - 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})") - - @staticmethod - def _declares_exception(source): - # ideally we'd use more sophisticated parsing - exception_parser = re.compile(r"^\s*exception\s+(?:[^\s{]+)") - return ScroogeGen._has_declaration(source, exception_parser) - - @staticmethod - def _declares_service(source): - # ideally we'd use more sophisticated parsing - service_parser = re.compile(r"^\s*service\s+(?:[^\s{]+)") - return ScroogeGen._has_declaration(source, service_parser) - - @staticmethod - def _has_declaration(source, regex): - source_path = os.path.join(get_buildroot(), source) - with open(source_path, "r") as thrift: - return any(line for line in thrift if regex.search(line)) - - def parse_gen_file_map(self, gen_file_map_path, outdir): - d = defaultdict(set) - with safe_open(gen_file_map_path, "r") as deps: - for dep in deps: - src, cls = dep.strip().split("->") - src = os.path.relpath(src.strip()) - cls = os.path.relpath(cls.strip(), outdir) - d[src].add(cls) - return d - - def is_gentarget(self, target): - if not isinstance(target, JavaThriftLibrary): - return False - - # We only handle requests for 'scrooge' compilation and not, for example 'thrift', aka the - # Apache thrift compiler - return self._thrift_defaults.compiler(target) == "scrooge" - - _ValidateCompilerConfig = namedtuple( - "ValidateCompilerConfig", ["language", "compiler", "compiler_args"] - ) - - def _validate_compiler_configs(self, target): - def filter_unchecked_compiler_args(tgt): - # Filter out args that exist in the unchecked list from the list of compiler args. - return [ - args - for args in self._thrift_defaults.compiler_args(tgt) - if args not in self.get_options().unchecked_compiler_args - ] - - def compiler_config(tgt): - return self._ValidateCompilerConfig( - language=self._thrift_defaults.language(tgt), - compiler=self._thrift_defaults.compiler(tgt), - compiler_args=filter_unchecked_compiler_args(tgt), - ) - - mismatched_compiler_configs = defaultdict(set) - mycompilerconfig = compiler_config(target) - - def collect(dep): - if mycompilerconfig != compiler_config(dep): - mismatched_compiler_configs[target].add(dep) - - target.walk(collect, predicate=lambda t: isinstance(t, JavaThriftLibrary)) - - if mismatched_compiler_configs: - msg = [ - "Thrift dependency trees must be generated with a uniform compiler configuration.\n\n" - ] - for tgt in sorted(mismatched_compiler_configs.keys()): - msg.append(f"{tgt} - {compiler_config(tgt)}\n") - for dep in mismatched_compiler_configs[tgt]: - msg.append(f" {dep} - {compiler_config(dep)}\n") - raise TaskError("".join(msg)) - - def _must_have_sources(self, target): - if isinstance(target, JavaThriftLibrary) and not target.payload.sources.source_paths: - raise TargetDefinitionException(target, "no thrift files found") - - def synthetic_target_type(self, target): - language = self._thrift_defaults.language(target) - return self._target_type_for_language(language) - - def synthetic_target_extra_dependencies(self, target, target_workdir): - deps = OrderedSet(self._thrift_dependencies_for_target(target)) - deps.update(target.dependencies) - return deps - - def synthetic_target_extra_exports(self, target, target_workdir): - dep_info = self._resolved_export_info - target_declares_service = any( - self._declares_service(source) for source in target.sources_relative_to_buildroot() - ) - language = self._thrift_defaults.language(target) - - if target_declares_service: - return dep_info.service[language] - else: - return dep_info.structs[language] - - def _thrift_dependencies_for_target(self, target): - dep_info = self._resolved_dep_info - target_declares_service_or_exception = any( - self._declares_service(source) or self._declares_exception(source) - for source in target.sources_relative_to_buildroot() - ) - language = self._thrift_defaults.language(target) - - if target_declares_service_or_exception: - return dep_info.service[language] - else: - return dep_info.structs[language] - - @memoized_property - def _resolved_dep_info(self): - return ScroogeGen.DepInfo( - self._resolve_deps(self.get_options().service_deps), - self._resolve_deps(self.get_options().structs_deps), - ) - - @memoized_property - def _resolved_export_info(self): - return ScroogeGen.DepInfo( - self._resolve_deps(self.get_options().service_exports), - self._resolve_deps(self.get_options().structs_exports), - ) - - @property - def _copy_target_attributes(self): - return super()._copy_target_attributes + ["strict_deps"] diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/thrift_linter_task.py b/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/thrift_linter_task.py deleted file mode 100644 index a9fcec17907..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/thrift_linter_task.py +++ /dev/null @@ -1,158 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary -from pants.backend.jvm.tasks.nailgun_task import NailgunTask -from pants.base.deprecated import resolve_conflicting_options -from pants.base.exceptions import TaskError -from pants.base.worker_pool import Work, WorkerPool -from pants.base.workunit import WorkUnitLabel -from pants.task.lint_task_mixin import LintTaskMixin - -from pants.contrib.scrooge.subsystems.scrooge_linter import ScroogeLinter -from pants.contrib.scrooge.tasks.thrift_util import calculate_include_paths - - -class ThriftLintError(Exception): - """Raised on a lint failure.""" - - -class ThriftLinterTask(LintTaskMixin, NailgunTask): - """Print lint warnings for thrift files.""" - - def _resolve_conflicting_options(self, *, old_option: str, new_option: str): - return resolve_conflicting_options( - old_option=old_option, - new_option=new_option, - old_scope="lint-thrift", - new_scope="scrooge-linter", - old_container=self.get_options(), - new_container=ScroogeLinter.global_instance().options, - ) - - @staticmethod - def _is_thrift(target): - return isinstance(target, JavaThriftLibrary) - - @classmethod - def register_options(cls, register): - super().register_options(register) - register( - "--ignore-errors", - default=False, - advanced=True, - type=bool, - fingerprint=True, - help="Ignore any error so thrift-linter always exit 0.", - ) - cls.register_jvm_tool(register, "scrooge-linter") - - @classmethod - def subsystem_dependencies(cls): - return super().subsystem_dependencies() + (ScroogeLinter,) - - @classmethod - def product_types(cls): - # Declare the product of this goal. Gen depends on thrift-linter. - return ["thrift-linter"] - - @property - def skip_execution(self): - return ScroogeLinter.global_instance().options.skip - - @property - def cache_target_dirs(self): - return True - - @staticmethod - def _to_bool(value): - # Converts boolean and string values to boolean. - return str(value) == "True" - - def _is_strict(self, target): - # The strict value is read from the following, in order: - # 1. the option --[no-]strict, but only if explicitly set. - # 2. java_thrift_library target in BUILD file, thrift_linter_strict = False, - # 3. options, --[no-]strict-default - subsystem_options = ScroogeLinter.global_instance().options - - if not subsystem_options.is_default("strict"): - return self._to_bool(subsystem_options.strict) - - if target.thrift_linter_strict is not None: - return self._to_bool(target.thrift_linter_strict) - - return self._to_bool(subsystem_options.strict_default) - - def _lint(self, target, classpath): - self.context.log.debug(f"Linting {target.address.spec}") - - config_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}.") - - def execute(self): - thrift_targets = self.get_targets(self._is_thrift) - with self.invalidated(thrift_targets) as invalidation_check: - if not invalidation_check.invalid_vts: - return - - with self.context.new_workunit("parallel-thrift-linter") as workunit: - worker_pool = WorkerPool( - workunit.parent, - self.context.run_tracker, - ScroogeLinter.global_instance().options.worker_count, - workunit.name, - ) - - scrooge_linter_classpath = self.tool_classpath("scrooge-linter") - results = [] - errors = [] - for vt in invalidation_check.invalid_vts: - r = worker_pool.submit_async_work( - Work(self._lint, [(vt.target, scrooge_linter_classpath)]) - ) - results.append((r, vt)) - for r, vt in results: - r.wait() - # MapResult will raise _value in `get` if the run is not successful. - try: - r.get() - except ThriftLintError as e: - errors.append(str(e)) - else: - vt.update() - - if errors: - raise TaskError("\n".join(errors)) diff --git a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/thrift_util.py b/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/thrift_util.py deleted file mode 100644 index de38f222666..00000000000 --- a/contrib/scrooge/src/python/pants/contrib/scrooge/tasks/thrift_util.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import os -import re - -INCLUDE_PARSER = re.compile(r'^\s*include\s+"([^"]+)"\s*([\/\/|\#].*)*$') - - -def find_includes(basedirs, source, log=None): - """Finds all thrift files included by the given thrift source. - - :basedirs: A set of thrift source file base directories to look for includes in. - :source: The thrift source file to scan for includes. - :log: An optional logger - """ - - all_basedirs = [os.path.dirname(source)] - all_basedirs.extend(basedirs) - - includes = set() - with open(source, "r") as thrift: - for line in thrift.readlines(): - match = INCLUDE_PARSER.match(line) - if match: - capture = match.group(1) - added = False - for basedir in all_basedirs: - include = os.path.join(basedir, capture) - if os.path.exists(include): - if log: - log.debug(f"{source} has include {include}") - includes.add(include) - added = True - if not added: - raise ValueError( - "{} included in {} not found in bases {}".format( - include, source, all_basedirs - ) - ) - return includes - - -def find_root_thrifts(basedirs, sources, log=None): - """Finds the root thrift files in the graph formed by sources and their recursive includes. - - :basedirs: A set of thrift source file base directories to look for includes in. - :sources: Seed thrift files to examine. - :log: An optional logger. - """ - - root_sources = set(sources) - for source in sources: - root_sources.difference_update(find_includes(basedirs, source, log=log)) - return root_sources - - -def calculate_include_paths(targets, is_thrift_target): - """Calculates the set of import paths for the given targets. - - :targets: The targets to examine. - :is_thrift_target: A predicate to pick out thrift targets for consideration in the analysis. - - :returns: Include basedirs for the target. - """ - - basedirs = set() - - def collect_paths(target): - basedirs.add(target.target_base) - - for target in targets: - target.walk(collect_paths, predicate=is_thrift_target) - return basedirs diff --git a/contrib/scrooge/tests/python/pants_test/__init__.py b/contrib/scrooge/tests/python/pants_test/__init__.py deleted file mode 100644 index 5284146ebf2..00000000000 --- a/contrib/scrooge/tests/python/pants_test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__("pkg_resources").declare_namespace(__name__) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/__init__.py b/contrib/scrooge/tests/python/pants_test/contrib/__init__.py deleted file mode 100644 index 5284146ebf2..00000000000 --- a/contrib/scrooge/tests/python/pants_test/contrib/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__import__("pkg_resources").declare_namespace(__name__) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/__init__.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/BUILD b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/BUILD deleted file mode 100644 index f353730be42..00000000000 --- a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/BUILD +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -python_tests( - name='java_thrift_library_fingerprint_strategy', - sources=['test_java_thrift_library_fingerprint_strategy.py'], - dependencies=[ - 'contrib/scrooge/src/python/pants/contrib/scrooge/tasks:java_thrift_library_fingerprint_strategy', - 'src/python/pants/backend/codegen/thrift/java', - 'src/python/pants/testutil:test_base', - ], - tags = {'partially_type_checked'}, -) - -python_tests( - name='scrooge_gen', - sources=['test_scrooge_gen.py'], - dependencies=[ - 'contrib/scrooge/src/python/pants/contrib/scrooge/tasks:scrooge_gen', - 'src/python/pants/backend/codegen/thrift/java', - 'src/python/pants/backend/jvm/targets:java', - 'src/python/pants/base:build_environment', - 'src/python/pants/base:exceptions', - 'src/python/pants/build_graph', - 'src/python/pants/goal:context', - 'src/python/pants/util:dirutil', - 'src/python/pants/util:ordered_set', - 'src/python/pants/testutil/jvm:nailgun_task_test_base' - ], - tags = {'partially_type_checked'}, -) - -python_tests( - name='scrooge_gen_integration', - sources=['test_scrooge_gen_integration.py'], - dependencies=[ - 'src/python/pants/testutil:int-test', - 'contrib/scrooge:scala_tests_directory', - 'contrib/scrooge:thrift_tests_directory', - ], - tags={'integration', 'partially_type_checked'}, - timeout=270, -) - -python_tests( - name='thrift_linter_integration', - sources=['test_thrift_linter_integration.py'], - dependencies=[ - 'src/python/pants/testutil:int-test', - 'contrib/scrooge:thrift_tests_directory', - ], - tags={'integration', 'partially_type_checked'}, - timeout=240, -) - -python_tests( - name='thrift_linter', - sources=['test_thrift_linter.py'], - dependencies=[ - 'contrib/scrooge/src/python/pants/contrib/scrooge/tasks:thrift_linter', - 'contrib/scrooge/src/python/pants/contrib/scrooge/tasks:thrift_util', - 'src/python/pants/backend/codegen/thrift/java', - 'src/python/pants/build_graph', - 'src/python/pants/testutil:task_test_base', - 'src/python/pants/testutil:mock_logger', - ], - tags = {'partially_type_checked'}, -) - -python_tests( - name='thrift_util', - sources=['test_thrift_util.py'], - dependencies=[ - 'contrib/scrooge/src/python/pants/contrib/scrooge/tasks:thrift_util', - 'src/python/pants/util:contextutil', - 'src/python/pants/util:dirutil', - 'src/python/pants/testutil:test_base', - ], - tags = {'partially_type_checked'}, -) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/__init__.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_java_thrift_library_fingerprint_strategy.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_java_thrift_library_fingerprint_strategy.py deleted file mode 100644 index 45b770885f6..00000000000 --- a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_java_thrift_library_fingerprint_strategy.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary -from pants.backend.codegen.thrift.java.thrift_defaults import ThriftDefaults -from pants.testutil.test_base import TestBase - -from pants.contrib.scrooge.tasks.java_thrift_library_fingerprint_strategy import ( - JavaThriftLibraryFingerprintStrategy, -) - - -class JavaThriftLibraryFingerprintStrategyTest(TestBase): - - options1 = {"compiler": "scrooge", "language": "java", "compiler_args": []} - - def create_strategy(self, option_values): - self.context( - for_subsystems=[ThriftDefaults], options={ThriftDefaults.options_scope: option_values} - ) - return JavaThriftLibraryFingerprintStrategy(ThriftDefaults.global_instance()) - - def test_fp_diffs_due_to_option(self): - option_values = {"compiler": "scrooge", "language": "java", "compiler_args": ["--foo"]} - - a = self.make_target(":a", target_type=JavaThriftLibrary) - - fp1 = self.create_strategy(self.options1).compute_fingerprint(a) - fp2 = self.create_strategy(option_values).compute_fingerprint(a) - self.assertNotEqual(fp1, fp2) - - def test_fp_diffs_due_to_compiler_args_change(self): - a = self.make_target(":a", target_type=JavaThriftLibrary, compiler_args=["--foo"]) - b = self.make_target(":b", target_type=JavaThriftLibrary, compiler_args=["--bar"]) - - fp1 = self.create_strategy(self.options1).compute_fingerprint(a) - fp2 = self.create_strategy(self.options1).compute_fingerprint(b) - self.assertNotEqual(fp1, fp2) - - def test_hash_and_equal(self): - self.assertEqual(self.create_strategy(self.options1), self.create_strategy(self.options1)) - self.assertEqual( - hash(self.create_strategy(self.options1)), hash(self.create_strategy(self.options1)) - ) - - option_values = {"compiler": "scrooge", "language": "java", "compiler_args": ["--baz"]} - self.assertNotEqual( - self.create_strategy(self.options1), self.create_strategy(option_values) - ) - self.assertNotEqual( - hash(self.create_strategy(self.options1)), hash(self.create_strategy(option_values)) - ) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen.py deleted file mode 100644 index ace2b6db2b5..00000000000 --- a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen.py +++ /dev/null @@ -1,245 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import os -from textwrap import dedent -from unittest.mock import MagicMock - -from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary -from pants.backend.jvm.targets.java_library import JavaLibrary -from pants.backend.jvm.targets.scala_library import ScalaLibrary -from pants.base.exceptions import TargetDefinitionException, TaskError -from pants.build_graph.build_file_aliases import BuildFileAliases -from pants.goal.context import Context -from pants.testutil.jvm.nailgun_task_test_base import NailgunTaskTestBase -from pants.util.ordered_set import OrderedSet - -from pants.contrib.scrooge.tasks.scrooge_gen import ScroogeGen - -GEN_ADAPT = "--gen-adapt" - - -class ScroogeGenTest(NailgunTaskTestBase): - @classmethod - def task_type(cls): - return ScroogeGen - - @classmethod - def alias_groups(cls): - return ( - super() - .alias_groups() - .merge( - BuildFileAliases( - targets={ - "java_thrift_library": JavaThriftLibrary, - "java_library": JavaLibrary, - "scala_library": ScalaLibrary, - } - ) - ) - ) - - def test_validate_compiler_configs(self): - self.add_to_build_file( - "test_validate", - self._test_create_build_str( - name="one", sources="[]", language="uniform", compiler_args="[]", deps="[]" - ), - ) - - self.add_to_build_file( - "test_validate", - self._test_create_build_str( - name="two", sources="[]", language="uniform", compiler_args="[]", deps="[':one']" - ), - ) - - target = self.target("test_validate:one") - context = self.context(target_roots=[target]) - task = self.prepare_execute(context) - task._validate_compiler_configs(self.target("test_validate:one")) - task._validate_compiler_configs(self.target("test_validate:two")) - - def test_validate_unchecked_compiler_args(self): - self.add_to_build_file( - "test_validate", - self._test_create_build_str( - name="one", sources="[]", language="uniform", compiler_args="[]", deps="[]" - ), - ) - - self.add_to_build_file( - "test_validate", - self._test_create_build_str( - name="two", - sources="[]", - language="uniform", - compiler_args="['--java-passthrough']", - deps="[':one']", - ), - ) - - target = self.target("test_validate:two") - context = self.context(target_roots=[target]) - task = self.prepare_execute(context) - task._validate_compiler_configs(self.target("test_validate:one")) - task._validate_compiler_configs(self.target("test_validate:two")) - - def test_validate_invalid_unchecked_compiler_args(self): - self.add_to_build_file( - "test_validate", - self._test_create_build_str( - name="one", sources="[]", language="uniform", compiler_args="[]", deps="[]" - ), - ) - - self.add_to_build_file( - "test_validate", - self._test_create_build_str( - name="two", - sources="[]", - language="uniform", - compiler_args="['--invalid_args']", - deps="[':one']", - ), - ) - - target = self.target("test_validate:two") - context = self.context(target_roots=[target]) - task = self.prepare_execute(context) - with self.assertRaises(TaskError): - task._validate_compiler_configs(self.target("test_validate:two")) - - def test_scala(self): - sources = [os.path.join(self.test_workdir, "org/pantsbuild/example/Example.scala")] - self._test_help("scala", ScalaLibrary, [GEN_ADAPT], sources) - - def test_compiler_args(self): - sources = [os.path.join(self.test_workdir, "org/pantsbuild/example/Example.scala")] - self._test_help("scala", ScalaLibrary, [GEN_ADAPT], sources) - - def test_android(self): - sources = [os.path.join(self.test_workdir, "org/pantsbuild/android_example/Example.java")] - self._test_help("android", JavaLibrary, [GEN_ADAPT], sources) - - def test_invalid_lang(self): - with self.assertRaises(TargetDefinitionException): - self._test_help("not-a-lang", JavaLibrary, [GEN_ADAPT], []) - - def test_empty_compiler_args(self): - sources = [os.path.join(self.test_workdir, "org/pantsbuild/example/Example.scala")] - self._test_help("scala", ScalaLibrary, [], sources) - - def compiler_args_to_string(self, compiler_args): - quoted = [f"'{x}'" for x in compiler_args] - comma_separated = ", ".join(quoted) - return f"[{comma_separated}]" - - def _test_create_build_str(self, name, sources, language, compiler_args, deps): - return dedent( - """ - java_thrift_library(name='{name}', - sources={sources}, - dependencies={deps}, - compiler='scrooge', - language='{language}', - compiler_args={compiler_args}, - strict_deps=True, - tags=['my_tag'], - ) - """.format( - name=name, - sources=sources, - language=language, - compiler_args=compiler_args, - deps=deps, - ) - ) - - def _test_help(self, language, library_type, compiler_args, sources): - contents = dedent( - """#@namespace android org.pantsbuild.android_example - namespace java org.pantsbuild.example - struct Example { - 1: optional i64 number - } - """ - ) - - self.create_file(relpath="test_smoke/a.thrift", contents=contents) - build_string = self._test_create_build_str( - name="a", - sources=["a.thrift"], - language=language, - compiler_args=compiler_args, - deps="[]", - ) - self.add_to_build_file("test_smoke", build_string) - - target = self.target("test_smoke:a") - context = self.context(target_roots=[target]) - task = self.prepare_execute(context) - - task.gen = MagicMock() - task.gen.return_value = {"test_smoke/a.thrift": sources} - - saved_add_new_target = Context.add_new_target - try: - mock = MagicMock() - Context.add_new_target = mock - task.execute() - - self.assertEqual(1, mock.call_count) - _, call_kwargs = mock.call_args - self.assertEqual(call_kwargs["target_type"], library_type) - self.assertEqual(call_kwargs["dependencies"], OrderedSet()) - self.assertEqual(call_kwargs["provides"], None) - self.assertEqual(call_kwargs["derived_from"], target) - self.assertEqual(call_kwargs["strict_deps"], True) - self.assertEqual(call_kwargs["tags"], {"my_tag"}) - - sources = call_kwargs["sources"] - self.assertEqual(sources.files, ()) - - finally: - Context.add_new_target = saved_add_new_target - - def test_basic_deps(self): - contents = dedent( - """#@namespace android org.pantsbuild.android_example - namespace java org.pantsbuild.example - struct Example { - 1: optional i64 number - } - """ - ) - self._test_dependencies_help(contents, False, False) - - def test_service_deps(self): - contents = dedent( - """#@namespace android org.pantsbuild.android_example - namespace java org.pantsbuild.example - service MultiplicationService - { - int multiply(1:int n1, 2:int n2), - }""" - ) - self._test_dependencies_help(contents, True, False) - - def test_exception_deps(self): - contents = dedent( - """#@namespace android org.pantsbuild.android_example - namespace java org.pantsbuild.example - exception InvalidOperation { - 1: i32 what, - 2: string why - }""" - ) - self._test_dependencies_help(contents, False, True) - - def _test_dependencies_help(self, contents, declares_service, declares_exception): - source = "test_smoke/a.thrift" - self.create_file(relpath=source, contents=contents) - self.assertEqual(ScroogeGen._declares_service(source), declares_service) - self.assertEqual(ScroogeGen._declares_exception(source), declares_exception) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen_integration.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen_integration.py deleted file mode 100644 index 01ee219a2ed..00000000000 --- a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_scrooge_gen_integration.py +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from pants.testutil.pants_run_integration_test import PantsRunIntegrationTest - - -class ScroogeGenTest(PantsRunIntegrationTest): - @classmethod - def hermetic(cls): - return True - - def run_pants(self, command, config=None, stdin_data=None, extra_env=None, **kwargs): - full_config = { - "GLOBAL": { - "pythonpath": ["%(buildroot)s/contrib/scrooge/src/python"], - "backend_packages": [ - "pants.backend.codegen", - "pants.backend.jvm", - "pants.contrib.scrooge", - ], - }, - "source": {"root_patterns": ["src/*", "tests/*"]}, - "scala": {"version": "2.11"}, - "gen.scrooge": { - "service_deps": { - "java": [ - "3rdparty:slf4j-api", - "3rdparty:thrift", - "3rdparty/jvm/com/twitter:finagle-thrift", - "3rdparty/jvm/com/twitter:scrooge-core", - ], - "scala": [ - "3rdparty:thrift", - "3rdparty/jvm/com/twitter:finagle-thrift", - "3rdparty/jvm/com/twitter:scrooge-core", - ], - }, - "service_exports": { - "java": ["3rdparty:thrift"], - "scala": [ - "3rdparty:thrift", - "3rdparty/jvm/com/twitter:finagle-thrift", - "3rdparty/jvm/com/twitter:scrooge-core", - ], - }, - "structs_deps": { - "java": ["3rdparty:thrift", "3rdparty/jvm/com/twitter:scrooge-core"], - "scala": ["3rdparty:thrift", "3rdparty/jvm/com/twitter:scrooge-core"], - }, - "structs_exports": { - "java": ["3rdparty:thrift", "3rdparty/jvm/com/twitter:scrooge-core"], - "scala": ["3rdparty:thrift", "3rdparty/jvm/com/twitter:scrooge-core"], - }, - }, - } - if config: - for scope, scoped_cfgs in config.items(): - updated = full_config.get(scope, {}) - updated.update(scoped_cfgs) - full_config[scope] = updated - return super().run_pants(command, full_config, stdin_data, extra_env, **kwargs) - - @staticmethod - def thrift_test_target(name): - return "contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen:" + name - - def test_good(self): - # scrooge_gen should pass with correct thrift files. - cmd = ["gen", self.thrift_test_target("good-thrift")] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) - - def test_exports_of_thrift(self): - # Compiling against a thrift service with strict_deps=True should work - # because the necessary transitive dependencies will be exported. - cmd = ["compile", "contrib/scrooge/tests/scala/org/pantsbuild/contrib/scrooge/scrooge_gen"] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) - - def test_namespace_map(self): - # scrooge_gen should pass with namespace_map specified - cmd = ["gen", self.thrift_test_target("namespace-map-thrift")] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) - - def test_default_java_namespace(self): - # scrooge_gen should pass with default_java_namespace specified - cmd = ["gen", self.thrift_test_target("default-java-namespace-thrift")] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) - - def test_include_paths(self): - # scrooge_gen should pass with include_paths specified - cmd = ["gen", self.thrift_test_target("include-paths-thrift")] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_linter.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_linter.py deleted file mode 100644 index 56c0bebf97e..00000000000 --- a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_linter.py +++ /dev/null @@ -1,97 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from unittest.mock import Mock, patch - -from pants.backend.codegen.thrift.java.java_thrift_library import JavaThriftLibrary -from pants.base.workunit import WorkUnitLabel -from pants.build_graph.build_file_aliases import BuildFileAliases -from pants.testutil.task_test_base import TaskTestBase - -from pants.contrib.scrooge.tasks.thrift_linter_task import ThriftLinterTask - - -class ThriftLinterTest(TaskTestBase): - def _prepare_mocks(self, task): - self._run_java_mock = Mock(return_value=0) - task.tool_classpath = Mock(return_value="foo_classpath") - task.runjava = self._run_java_mock - - @classmethod - def alias_groups(cls): - return BuildFileAliases(targets={"java_thrift_library": JavaThriftLibrary}) - - @classmethod - def task_type(cls): - return ThriftLinterTask - - @patch("pants.contrib.scrooge.tasks.thrift_linter_task.calculate_include_paths") - def test_lint(self, mock_calculate_include_paths): - def get_default_jvm_options(): - return self.task_type().get_jvm_options_default( - self.context().options.for_global_scope() - ) - - thrift_target = self.create_library( - path="src/thrift/tweet", - target_type="java_thrift_library", - name="a", - sources=["A.thrift"], - ) - task = self.create_task(self.context(target_roots=thrift_target)) - self._prepare_mocks(task) - expected_include_paths = ["src/thrift/users", "src/thrift/tweet"] - mock_calculate_include_paths.return_value = expected_include_paths - task._lint(thrift_target, task.tool_classpath("scrooge-linter")) - - self._run_java_mock.assert_called_once_with( - classpath="foo_classpath", - main="com.twitter.scrooge.linter.Main", - args=[ - "--warnings", - "--include-path", - "src/thrift/users", - "--include-path", - "src/thrift/tweet", - "src/thrift/tweet/A.thrift", - ], - jvm_options=get_default_jvm_options(), - workunit_labels=[WorkUnitLabel.COMPILER, WorkUnitLabel.SUPPRESS_LABEL], - ) - - @patch("pants.contrib.scrooge.tasks.thrift_linter_task.calculate_include_paths") - def test_lint_direct_only(self, mock_calculate_include_paths): - # Validate that we do lint only the direct sources of a target, rather than including the - # sources of its transitive deps. - - def get_default_jvm_options(): - return self.task_type().get_jvm_options_default( - self.context().options.for_global_scope() - ) - - self.create_library( - path="src/thrift/tweet", - target_type="java_thrift_library", - name="a", - sources=["A.thrift"], - ) - target_b = self.create_library( - path="src/thrift/tweet", - target_type="java_thrift_library", - name="b", - sources=["B.thrift"], - dependencies=[":a"], - ) - task = self.create_task(self.context(target_roots=target_b)) - self._prepare_mocks(task) - mock_calculate_include_paths.return_value = ["src/thrift/tweet"] - task._lint(target_b, task.tool_classpath("scrooge-linter")) - - # Confirm that we did not include the sources of the dependency. - self._run_java_mock.assert_called_once_with( - classpath="foo_classpath", - main="com.twitter.scrooge.linter.Main", - args=["--warnings", "--include-path", "src/thrift/tweet", "src/thrift/tweet/B.thrift"], - jvm_options=get_default_jvm_options(), - workunit_labels=[WorkUnitLabel.COMPILER, WorkUnitLabel.SUPPRESS_LABEL], - ) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_linter_integration.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_linter_integration.py deleted file mode 100644 index 1127e102552..00000000000 --- a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_linter_integration.py +++ /dev/null @@ -1,172 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -from functools import wraps -from typing import Any, Callable, TypeVar - -from pants.testutil.pants_run_integration_test import PantsRunIntegrationTest - -FuncType = Callable[..., Any] -F = TypeVar("F", bound=FuncType) - - -class ThriftLinterTest(PantsRunIntegrationTest): - - lint_warn_token = "LINT-WARN" - lint_error_token = "LINT-ERROR" - thrift_folder_root = "contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter" - - @classmethod - def hermetic(cls): - return True - - @classmethod - def thrift_test_target(cls, name): - return f"{cls.thrift_folder_root}:{name}" - - def rename_build_file(func: F) -> F: - """This decorator implements the TEST_BUILD pattern. - - Because these tests use files that intentionally should fail linting, the goal `./pants lint ::` - we use in CI would complain about these files. To avoid this, we rename BUILD to TEST_BUILD. - - However, these tests require us to temporarily rename TEST_BUILD back to BUILD. - """ - - @wraps(func) - def wrapper(self, *args, **kwargs): - with self.file_renamed( - self.thrift_folder_root, test_name="TEST_BUILD", real_name="BUILD" - ): - func(self, *args, **kwargs) - - return wrapper # type: ignore[return-value] - - def run_pants(self, command, config=None, stdin_data=None, extra_env=None, **kwargs): - full_config = { - "GLOBAL": { - "pythonpath": ["%(buildroot)s/contrib/scrooge/src/python"], - "backend_packages": [ - "pants.backend.codegen", - "pants.backend.jvm", - "pants.contrib.scrooge", - ], - }, - "source": {"root_patterns": ["tests/*", "src/*"]}, - } - if config: - for scope, scoped_cfgs in config.items(): - updated = full_config.get(scope, {}) - updated.update(scoped_cfgs) - full_config[scope] = updated - return super().run_pants(command, full_config, stdin_data, extra_env, **kwargs) - - @rename_build_file - def test_good(self): - # thrift-linter should pass without warnings with correct thrift files. - cmd = ["lint.thrift", self.thrift_test_target("good-thrift")] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) - self.assertNotIn(self.lint_error_token, pants_run.stdout_data) - - @rename_build_file - def test_bad_default(self): - # thrift-linter fails on linter errors. - cmd = ["lint.thrift", self.thrift_test_target("bad-thrift-default")] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) - self.assertIn(self.lint_warn_token, pants_run.stdout_data) - - @rename_build_file - def test_bad_strict(self): - # thrift-linter fails on linter errors (BUILD target defines thrift_linter_strict=True) - cmd = ["lint.thrift", self.thrift_test_target("bad-thrift-strict")] - pants_run = self.run_pants(cmd) - self.assert_failure(pants_run) - self.assertIn(self.lint_error_token, pants_run.stdout_data) - - @rename_build_file - def test_bad_non_strict(self): - # thrift-linter fails on linter errors (BUILD target defines thrift_linter_strict=False) - cmd = ["lint.thrift", self.thrift_test_target("bad-thrift-non-strict")] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) - self.assertIn(self.lint_warn_token, pants_run.stdout_data) - - @rename_build_file - def test_bad_default_override(self): - # thrift-linter fails with command line flag overriding the BUILD section. - cmd = [ - "--scrooge-linter-strict", - "lint.thrift", - self.thrift_test_target("bad-thrift-default"), - ] - pants_run = self.run_pants(cmd) - self.assert_failure(pants_run) - self.assertIn(self.lint_error_token, pants_run.stdout_data) - - @rename_build_file - def test_multiple_bad_strict_override(self): - # Using -q to make sure bad thrift files are in the final exception messages. - target_a = self.thrift_test_target("bad-thrift-strict") - target_b = self.thrift_test_target("bad-thrift-strict2") - cmd = [ - "-q", - "--scrooge-linter-strict", - "lint.thrift", - target_a, - target_b, - ] - pants_run = self.run_pants(cmd) - self.assert_failure(pants_run) - self.assertIn("bad-strict2.thrift", pants_run.stdout_data) - self.assertIn("bad-strict.thrift", pants_run.stdout_data) - self.assertIn(target_a, pants_run.stdout_data) - self.assertIn(target_b, pants_run.stdout_data) - - @rename_build_file - def test_bad_strict_override(self): - # thrift-linter passes with non-strict command line flag overriding the BUILD section. - cmd = [ - "--no-scrooge-linter-strict", - "lint.thrift", - self.thrift_test_target("bad-thrift-strict"), - ] - pants_run = self.run_pants(cmd) - self.assert_success(pants_run) - self.assertIn(self.lint_warn_token, pants_run.stdout_data) - - @rename_build_file - def test_bad_non_strict_override(self): - # thrift-linter fails with command line flag overriding the BUILD section. - cmd = [ - "--scrooge-linter-strict", - "lint.thrift", - self.thrift_test_target("bad-thrift-non-strict"), - ] - pants_run = self.run_pants(cmd) - self.assert_failure(pants_run) - self.assertIn(self.lint_error_token, pants_run.stdout_data) - - @rename_build_file - def test_bad_pants_ini_strict(self): - # thrift-linter fails if pants.toml has a thrift-linter:strict=True setting. - cmd = ["lint.thrift", self.thrift_test_target("bad-thrift-default")] - pants_ini_config = {"scrooge-linter": {"strict": True}} - pants_run = self.run_pants(cmd, config=pants_ini_config) - self.assert_failure(pants_run) - self.assertIn(self.lint_error_token, pants_run.stdout_data) - - @rename_build_file - def test_bad_pants_ini_strict_overridden(self): - # thrift-linter passes if pants.toml has a thrift-linter:strict=True setting and - # a command line non-strict flag is passed. - cmd = [ - "--no-scrooge-linter-strict", - "lint.thrift", - self.thrift_test_target("bad-thrift-default"), - ] - pants_ini_config = {"scrooge-linter": {"strict": True}} - pants_run = self.run_pants(cmd, config=pants_ini_config) - self.assert_success(pants_run) - self.assertIn(self.lint_warn_token, pants_run.stdout_data) diff --git a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_util.py b/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_util.py deleted file mode 100644 index 2f8f394c454..00000000000 --- a/contrib/scrooge/tests/python/pants_test/contrib/scrooge/tasks/test_thrift_util.py +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -import os -import unittest - -from pants.util.contextutil import temporary_dir -from pants.util.dirutil import safe_open - -from pants.contrib.scrooge.tasks.thrift_util import find_includes, find_root_thrifts - - -class ThriftUtilTest(unittest.TestCase): - def write(self, path, contents): - with safe_open(path, "w") as fp: - fp.write(contents) - return path - - def test_find_includes(self): - with temporary_dir() as dir: - a = os.path.join(dir, "a") - b = os.path.join(dir, "b") - - main = self.write( - os.path.join(a, "main.thrift"), - """ - include "sub/a_included.thrift" //Todo comment - include "b_included.thrift" - include "c_included.thrift" #jibberish - include "d_included.thrift" some random - """, - ) - - a_included = self.write(os.path.join(a, "sub", "a_included.thrift"), "# noop") - b_included = self.write(os.path.join(b, "b_included.thrift"), "# noop") - c_included = self.write(os.path.join(b, "c_included.thrift"), "# noop") - - self.assertEqual( - {a_included, b_included, c_included}, find_includes(basedirs={a, b}, source=main) - ) - - def test_find_includes_exception(self): - with temporary_dir() as dir: - a = os.path.join(dir, "a") - - main = self.write( - os.path.join(a, "main.thrift"), - """ - include "sub/a_included.thrift # Todo" - include "b_included.thrift" - """, - ) - self.write(os.path.join(a, "sub", "a_included.thrift"), "# noop") - self.assertRaises(ValueError, find_includes, basedirs={a}, source=main) - - def test_find_root_thrifts(self): - with temporary_dir() as dir: - root_1 = self.write(os.path.join(dir, "root_1.thrift"), "# noop") - root_2 = self.write(os.path.join(dir, "root_2.thrift"), "# noop") - self.assertEqual( - {root_1, root_2}, find_root_thrifts(basedirs=[], sources=[root_1, root_2]) - ) - - with temporary_dir() as dir: - root_1 = self.write(os.path.join(dir, "root_1.thrift"), 'include "mid_1.thrift"') - self.write(os.path.join(dir, "mid_1.thrift"), 'include "leaf_1.thrift"') - self.write(os.path.join(dir, "leaf_1.thrift"), "# noop") - root_2 = self.write(os.path.join(dir, "root_2.thrift"), 'include "root_1.thrift"') - self.assertEqual({root_2}, find_root_thrifts(basedirs=[], sources=[root_1, root_2])) diff --git a/contrib/scrooge/tests/scala/org/pantsbuild/contrib/scrooge/scrooge_gen/BUILD b/contrib/scrooge/tests/scala/org/pantsbuild/contrib/scrooge/scrooge_gen/BUILD deleted file mode 100644 index c3998a0b37f..00000000000 --- a/contrib/scrooge/tests/scala/org/pantsbuild/contrib/scrooge/scrooge_gen/BUILD +++ /dev/null @@ -1,6 +0,0 @@ -scala_library( - dependencies=[ - 'contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen:good-thrift' - ], - strict_deps=True -) diff --git a/contrib/scrooge/tests/scala/org/pantsbuild/contrib/scrooge/scrooge_gen/UseGoodThrift.scala b/contrib/scrooge/tests/scala/org/pantsbuild/contrib/scrooge/scrooge_gen/UseGoodThrift.scala deleted file mode 100644 index 628158b4952..00000000000 --- a/contrib/scrooge/tests/scala/org/pantsbuild/contrib/scrooge/scrooge_gen/UseGoodThrift.scala +++ /dev/null @@ -1,7 +0,0 @@ -package org.pantsbuild.contrib.scrooge.scrooge_gen - -class UseGoodThrift extends all.your.base.thriftscala.MyService.MethodPerEndpoint { - def getNumber(x: Int): com.twitter.util.Future[Int] = { - com.twitter.util.Future[Int](1) - } -} diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/BUILD b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/BUILD deleted file mode 100644 index a87ca6ba7a5..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/BUILD +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -java_thrift_library( - name = 'good-thrift', - sources = ['good.thrift'], - compiler='scrooge', - language='scala', - compiler_args=['--finagle'], -) - -java_thrift_library( - name = 'namespace-map-thrift', - sources = ['good.thrift'], - compiler='scrooge', - language='scala', - compiler_args=['--finagle'], - namespace_map = { - 'old': 'new', - }, -) - -java_thrift_library( - name = 'default-java-namespace-thrift', - sources = ['good.thrift'], - compiler='scrooge', - language='scala', - compiler_args=['--finagle'], - default_java_namespace = 'the_namespace', -) - -java_thrift_library( - name = 'include-paths-thrift', - sources = ['good.thrift'], - compiler='scrooge', - language='scala', - compiler_args=['--finagle'], - include_paths = [ - 'some_dir', - ], -) - diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/README b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/README deleted file mode 100644 index e9959a3c93b..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/README +++ /dev/null @@ -1 +0,0 @@ -These are the tests for the scrooge_gen goal. diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/good.thrift b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/good.thrift deleted file mode 100644 index 8b27dd63c97..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/scrooge_gen/good.thrift +++ /dev/null @@ -1,6 +0,0 @@ -namespace java all.your.base.thriftjava -#@namespace scala all.your.base.thriftscala - -service MyService { - i32 getNumber(1: i32 input) -} diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/README b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/README deleted file mode 100644 index c91eedc64c9..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/README +++ /dev/null @@ -1 +0,0 @@ -These are the tests for the thrift-linter goal. diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/TEST_BUILD b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/TEST_BUILD deleted file mode 100644 index ceb8d46cfbe..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/TEST_BUILD +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -java_thrift_library( - name = 'bad-thrift-default', - sources = ['bad-default.thrift'], - tags=['nolint'], - # thrift_linter_strict not defined -) - -java_thrift_library( - name = 'bad-thrift-strict', - sources = ['bad-strict.thrift'], - thrift_linter_strict=True, - tags=['nolint'], -) - -java_thrift_library( - name = 'bad-thrift-strict2', - sources = ['bad-strict2.thrift'], - thrift_linter_strict=True, - tags=['nolint'], -) - -java_thrift_library( - name = 'bad-thrift-non-strict', - sources = ['bad-non-strict.thrift'], - thrift_linter_strict=False, - tags=['nolint'], -) - -java_thrift_library( - name = 'good-thrift', - sources = ['good.thrift'], - thrift_linter_strict=True, - tags=['nolint'], -) diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-default.thrift b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-default.thrift deleted file mode 100644 index 53c4b29bdcd..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-default.thrift +++ /dev/null @@ -1,5 +0,0 @@ -// No scala/java namespaces - -struct DuckDefaultStrictness { - 1: optional string quack, -} diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-non-strict.thrift b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-non-strict.thrift deleted file mode 100644 index 809cd6d1d24..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-non-strict.thrift +++ /dev/null @@ -1,5 +0,0 @@ -// No scala/java namespaces - -struct DuckNonStrict { - 1: optional string quack, -} diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-strict.thrift b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-strict.thrift deleted file mode 100644 index cb30a979d72..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-strict.thrift +++ /dev/null @@ -1,5 +0,0 @@ -// No scala/java namespaces - -struct DuckStrict { - 1: optional string quack, -} diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-strict2.thrift b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-strict2.thrift deleted file mode 100644 index d777ca05a20..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/bad-strict2.thrift +++ /dev/null @@ -1,5 +0,0 @@ -// No scala/java namespaces - -struct DuckStrict2 { - 1: optional string quack, -} diff --git a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/good.thrift b/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/good.thrift deleted file mode 100644 index 8b27dd63c97..00000000000 --- a/contrib/scrooge/tests/thrift/org/pantsbuild/contrib/scrooge/thrift_linter/good.thrift +++ /dev/null @@ -1,6 +0,0 @@ -namespace java all.your.base.thriftjava -#@namespace scala all.your.base.thriftscala - -service MyService { - i32 getNumber(1: i32 input) -} diff --git a/examples/src/thrift/org/pantsbuild/example/README.md b/examples/src/thrift/org/pantsbuild/example/README.md deleted file mode 100644 index 71b7b3b9b06..00000000000 --- a/examples/src/thrift/org/pantsbuild/example/README.md +++ /dev/null @@ -1,208 +0,0 @@ -Thrift -====== - -[Apache Thrift](http://thrift.apache.org/) is a popular framework for -working with data types and service interfaces. It uses an Interface -Definition Language (IDL) to define these types and interfaces. There -are tools to generate code in "real" programming languages from Thrift -IDL files. Two programs, perhaps in different programming languages, -should be able to communicate over Thrift interfaces by using this -generated code. - -Pants knows Thrift. For each Thrift file you use, your codebase has some -`BUILD` targets that represent "real" code generated from IDL code. You -can write code in your favorite language that imports the generated -code. To make the import work, your code's `BUILD` target depends on the -appropriate Thrift `BUILD` target. - -Generating Code ---------------- - -You have some Thrift; you want to use it from your "regular" programming -language. Normally, to make, e.g., Java code usable, you set up a -`java_library` target with sources `*.java` and then depend on that -target; Thrift works similarly, but you use a different target type that -generates Java code from `*.thrift`. You can define Java, Python, or -Scala library targets whose code is Thrift-generated by setting up -*lang*\_thrift\_library targets. (Scala is tricky; you use a -`java_thrift_library` with carefully-chosen parameters.) Other targets -can depend on a *lang*\_thrift\_library and their code can then import -the generated code. - -### Target Example - -This example sets up a `java_thrift_library` target; its source is -Thrift; it generates Java. - - :::python - # Target defined in src/thrift/com/twitter/mybird/BUILD: - java_thrift_library( - name='mybird', - # Specify dependencies for thrift IDL file includes. - dependencies=[ - 'src/thrift/com/twitter/otherbird', - ], - sources=['*.thrift'] - ) - -Pants knows that before it compiles such a target, it must first -generate Java code from the Thrift IDL files. Users can depend on this -target like any other internal target. In this case, users would add a -dependency on `'src/thrift/com/twitter/mybird'`. - -One *lang*\_thrift\_library can depend on another; use this if one of -your Thrift files `include`s a Thrift file that lives in another target. - -### Configuring - -Here are some popular `*_thrift_library` configurations: - -**Java** - -Use Apache Thrift compiler (the default): - - :::python - java_thrift_library(...) - -...or Scrooge: - - :::python - java_thrift_library( - compiler='scrooge') - -**Python** - - :::python - python_thrift_library(...) - -**Scala** - - :::python - java_thrift_library( # Yes, a "java" library to generate Scala - compiler='scrooge', # default compiler does not gen Scala; Scrooge does - language='scala', - # maybe set compiler_args - ) - -**Android** - -Scrooge compiler can now generate java code with a limited number of getters and -setters which is more suitable for Android applications which have a 65K limit on the -number of methods. - - :::python - java_thrift_library( # Yes, a "java" library to generate Scala - compiler='scrooge', # default compiler does not gen android; Scrooge does - language='android', - ) - - -Thrift Example --------------- - -Let's look at some sample code that puts all of this together. - -- Thrift IDL code (`.thrift` files) -- `BUILD` targets for the Thrift IDL code -- Java code that `import`s code generated from Thrift -- `BUILD` target dependencies that allow that `import` - -### Thrift IDL - -Our example uses two Thrift files, one of which `include`s the other. They look pretty ordinary. -The `include`d Thrift, `examples/src/thrift/org/pantsbuild/example/distance/distance.thrift`, is -regular Thrift: - -!inc(distance/distance.thrift) - -The `include`ing Thrift, -`examples/src/thrift/org/pantsbuild/example/precipitation/precipitation.thrift`, -also looks ordinary. (The include path is a little tricky: it's based on source roots. -Thus, if your source tree has more than one root `foo` and `bar` and has Thrift in both, -code in foo can `include` code from `bar` without mentioning `bar` in the include path.): - -!inc(precipitation/precipitation.thrift) - -### BUILD Targets - -In a `BUILD` file, we use a `java_thrift_library` or -`python_thrift_library` to generate "real" code from Thrift. Our example -just uses Java; thus, the `BUILD` file for `distance.thrift` looks like - -!inc[start-after=cd ../precipitation](distance/BUILD) - -Notice the target type is -java_thrift_library, -and this target staked its claim to our distance thrift IDL file. -JVM library targets -(e.g.: -`java_library`, -`scala_library`) that depend on this -target will simply see generated code from the IDL. Since no additional -options are specified we use the defaults; however, if we need more -control over how code is generated we control that through arguments -provided by -java_thrift_library. - -> **note** -> -> While the name `java_thrift_library` might make you think it generates -> Java, it can also generate other target languages via the `language` -> parameter (scala for example). For Python code, however, use -> python_thrift_library. - -As with "regular" languages, for one target's code to include another's, -a target should have the other in its `dependencies`. Thus, to allow -`precipitation.thrift` to depend on `distance.thrift`, we set up -`.../precipitation/BUILD` like so: - -!inc[start-after=includes other thrift](precipitation/BUILD) - -### Using in "Regular" Code - -We want to use the Thrift-generated interface from "regular" code. In -this Java example, we want to `import` the generated code. In our Java, -the `import` statements use the names from the `.thrift` files' -`namespace`s: - -!inc[start-after=from Java.](../../../../../tests/java/org/pantsbuild/example/usethrift/UseThriftTest.java) - -As usual, for code in one target to use code from another, one target -needs to depend on the other. Thus, our Java code's target has the -`*_thrift_library` target whose code it uses in its dependencies: - -!inc[start-after=using Thrift from Java, though.](../../../../../tests/java/org/pantsbuild/example/usethrift/BUILD) - -Publishing ----------- - -Publishing a *lang*\_thrift\_library is like -[[publishing a "regular" library|pants('examples/src/java/org/pantsbuild/example:publish')]] -The targets use `provides` -parameters. It might look something like: - - :::python - java_thrift_library(name='eureka-java', - sources=['eureka.thrift'], - dependencies=[ - 'src/thrift/org/archimedes/volume:volume-java', - ], - language='java', - provides=artifact( - org='org.archimedes', - name='eureka-java', - repo='BUILD.archimedes:jar-public', - )) - - java_thrift_library(name='eureka-scala', - sources=['eureka.thrift'], - dependencies=[ - 'src/thrift/org/archimedes/volume:volume-scala', - ], - compiler='scrooge', - language='scala', - provides=artifact( - org='org.archimedes', - name='eureka-scala', - repo='BUILD.archimedes:jar-public', - )) diff --git a/pants.toml b/pants.toml index 3f913870a7b..4e17215edff 100644 --- a/pants.toml +++ b/pants.toml @@ -24,11 +24,9 @@ v2 = false # Enable our own custom loose-source plugins as well as contribs. pythonpath = [ "%(buildroot)s/contrib/mypy/src/python", - "%(buildroot)s/contrib/scrooge/src/python", "%(buildroot)s/pants-plugins/src/python", ] backend_packages.add = [ - "pants.contrib.scrooge", "internal_backend.repositories", "internal_backend.utilities", ] @@ -97,58 +95,6 @@ ivy_settings = "%(pants_supportdir)s/ivy/ivysettings.xml" # signing artifacts we publish to maven central. ivy_profile = "%(pants_supportdir)s/ivy/ivy.xml" -[gen.scrooge] -service_deps = """ -{ - 'java': [ - '3rdparty:slf4j-api', - '3rdparty:thrift', - '3rdparty/jvm/com/twitter:finagle-thrift', - '3rdparty/jvm/com/twitter:scrooge-core', - ], - 'scala': [ - '3rdparty:thrift', - '3rdparty/jvm/com/twitter:finagle-thrift', - '3rdparty/jvm/com/twitter:scrooge-core', - ], -} -""" -structs_deps = """ -{ - 'java': [ - '3rdparty:thrift', - '3rdparty/jvm/com/twitter:scrooge-core', - ], - 'scala': [ - '3rdparty:thrift', - '3rdparty/jvm/com/twitter:scrooge-core', - ], -} -""" -service_exports = """ -{ - 'java': [ - '3rdparty:thrift', - ], - 'scala': [ - '3rdparty:thrift', - '3rdparty/jvm/com/twitter:finagle-thrift', - '3rdparty/jvm/com/twitter:scrooge-core', - ], -} -""" -structs_exports = """ -{ - 'java': [ - '3rdparty:thrift', - ], - 'scala': [ - '3rdparty:thrift', - '3rdparty/jvm/com/twitter:scrooge-core', - ], -} -""" - [gen.thrift-java] deps = ["3rdparty:thrift"] diff --git a/src/python/pants/bin/BUILD b/src/python/pants/bin/BUILD index 88c9da75573..48600de9a4c 100644 --- a/src/python/pants/bin/BUILD +++ b/src/python/pants/bin/BUILD @@ -74,7 +74,6 @@ python_binary( dependencies=[ ':bin', '//:build_root', - '//:build_tools', '//:pants_toml', '//:3rdparty_directory', '//:isort_cfg', diff --git a/src/python/pants/testutil/jvm/BUILD b/src/python/pants/testutil/jvm/BUILD index c51b00cdaee..7bdc59c8e11 100644 --- a/src/python/pants/testutil/jvm/BUILD +++ b/src/python/pants/testutil/jvm/BUILD @@ -5,7 +5,6 @@ python_library( name='jvm_tool_task_test_base', sources=['jvm_tool_task_test_base.py'], dependencies=[ - '//:build_tools', '//:3rdparty_directory', ':jvm_task_test_base', 'src/python/pants/backend/jvm/subsystems:jvm_tool_mixin', diff --git a/testprojects/src/java/org/pantsbuild/testproject/BUILD b/testprojects/src/java/org/pantsbuild/testproject/BUILD index e0458d5201e..7e60b13077a 100644 --- a/testprojects/src/java/org/pantsbuild/testproject/BUILD +++ b/testprojects/src/java/org/pantsbuild/testproject/BUILD @@ -47,7 +47,6 @@ target( ':runtime_directory', ':shading_directory', ':shadingdep_directory', - ':thriftdeptest_directory', ':typeparameters_directory', ':unicode_directory', # NB: See `:javasources_directory` for why this must be declared here. @@ -314,14 +313,6 @@ files( sources = ['shadingdep/**/*'], ) -files( - name = 'thriftdeptest_directory', - sources = ['thriftdeptest/**/*'], - dependencies = [ - 'testprojects/src/thrift/org/pantsbuild:testproject_directory', - ], -) - files( name = 'typeparameters_directory', sources = ['typeparameters/**/*'], diff --git a/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/BUILD b/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/BUILD deleted file mode 100644 index 489e2e829e7..00000000000 --- a/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/BUILD +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -java_library( - dependencies = [ - 'testprojects/src/thrift/org/pantsbuild/testproject:thrift-java', - ], - sources = ['**/*.java'], -) diff --git a/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/README.md b/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/README.md deleted file mode 100644 index 434ddfaf86f..00000000000 --- a/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This tests that a project that depends on a scrooge generated class doesn't -produce an incorrect missing dependency warning. diff --git a/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/ThriftDepTestJava.java b/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/ThriftDepTestJava.java deleted file mode 100644 index 25e686fe483..00000000000 --- a/testprojects/src/java/org/pantsbuild/testproject/thriftdeptest/ThriftDepTestJava.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.pantsbuild.testproject.thriftdeptest; - -import org.pantsbuild.testproject.thriftjava.TestService; - -class ThriftDepTestJava extends TestService {} \ No newline at end of file diff --git a/testprojects/src/scala/org/pantsbuild/testproject/BUILD b/testprojects/src/scala/org/pantsbuild/testproject/BUILD index 637d90ce6b8..c5f90e8df43 100644 --- a/testprojects/src/scala/org/pantsbuild/testproject/BUILD +++ b/testprojects/src/scala/org/pantsbuild/testproject/BUILD @@ -19,7 +19,6 @@ target( ':rsc_compat_directory', ':scaladepsonboth_directory', ':sharedsources_directory', - ':thriftdeptest_directory', ':unicode_directory', ], ) @@ -109,14 +108,6 @@ files( sources = ['sharedsources/**/*'], ) -files( - name = 'thriftdeptest_directory', - sources = ['thriftdeptest/**/*'], - dependencies = [ - 'testprojects/src/thrift/org/pantsbuild:testproject_directory', - ], -) - files( name = 'unicode_directory', sources = ['unicode/**/*'], diff --git a/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/BUILD b/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/BUILD deleted file mode 100644 index a963760f0de..00000000000 --- a/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/BUILD +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md). -# Licensed under the Apache License, Version 2.0 (see LICENSE). - -scala_library( - dependencies = [ - 'testprojects/src/thrift/org/pantsbuild/testproject:thrift-java', - ], - sources = ['**/*.scala'], - # NB: this setting is a temporary way to get tests passing, as Scrooge and Thrift - # require JDK 8 to function properly. This constraint should really be specified in - # source code, not in test BUILD files. See #6956 - platform='java8', -) diff --git a/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/README.md b/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/README.md deleted file mode 100644 index 434ddfaf86f..00000000000 --- a/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/README.md +++ /dev/null @@ -1,2 +0,0 @@ -This tests that a project that depends on a scrooge generated class doesn't -produce an incorrect missing dependency warning. diff --git a/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/ThriftDepTestScala.scala b/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/ThriftDepTestScala.scala deleted file mode 100644 index c95e8043e83..00000000000 --- a/testprojects/src/scala/org/pantsbuild/testproject/thriftdeptest/ThriftDepTestScala.scala +++ /dev/null @@ -1,5 +0,0 @@ -package org.pantsbuild.testproject.thriftdeptest - -import org.pantsbuild.testproject.thriftjava.TestService - -class ThriftDepTestScala extends TestService {} \ No newline at end of file diff --git a/testprojects/src/thrift/org/pantsbuild/BUILD b/testprojects/src/thrift/org/pantsbuild/BUILD index 01eda9b6bc3..d94d52eaa66 100644 --- a/testprojects/src/thrift/org/pantsbuild/BUILD +++ b/testprojects/src/thrift/org/pantsbuild/BUILD @@ -5,8 +5,6 @@ target( name = 'all_directories', dependencies = [ ':constants_only_directory', - ':testproject_directory', - ':thrift_exports_directory', ], ) @@ -17,19 +15,3 @@ files( 'examples/3rdparty:python_directory', ], ) - -files( - name='testproject_directory', - sources=['testproject/**/*'], - dependencies = [ - 'examples/3rdparty:python_directory', - ], -) - -files( - name='thrift_exports_directory', - sources=['thrift_exports/**/*'], - dependencies = [ - 'examples/3rdparty:python_directory', - ], -) diff --git a/testprojects/src/thrift/org/pantsbuild/testproject/BUILD b/testprojects/src/thrift/org/pantsbuild/testproject/BUILD deleted file mode 100644 index cfd15cf0d1a..00000000000 --- a/testprojects/src/thrift/org/pantsbuild/testproject/BUILD +++ /dev/null @@ -1,10 +0,0 @@ -java_thrift_library( - name='thrift-java', - sources=['**/*.thrift'], - compiler='scrooge', - language='java', - # NB: this setting is a temporary way to get tests passing, as Scrooge and Thrift - # require JDK 8 to function properly. This constraint should really be specified in - # source code, not in test BUILD files. See #6956 - platform='java8', -) diff --git a/testprojects/src/thrift/org/pantsbuild/testproject/testservice.thrift b/testprojects/src/thrift/org/pantsbuild/testproject/testservice.thrift deleted file mode 100644 index d5bdf404fba..00000000000 --- a/testprojects/src/thrift/org/pantsbuild/testproject/testservice.thrift +++ /dev/null @@ -1,6 +0,0 @@ -namespace java org.pantsbuild.testproject.thriftjava -#@namespace scala org.pantsbuild.testproject.thriftscala - -service TestService { - void test(1: string request) -} \ No newline at end of file diff --git a/testprojects/src/thrift/org/pantsbuild/thrift_exports/A.thrift b/testprojects/src/thrift/org/pantsbuild/thrift_exports/A.thrift deleted file mode 100644 index 6a71a4aabfc..00000000000 --- a/testprojects/src/thrift/org/pantsbuild/thrift_exports/A.thrift +++ /dev/null @@ -1,6 +0,0 @@ -namespace java org.pantsbuild.thrift_exports.thriftjava -#@namespace scala org.pantsbuild.thrift_exports.thriftscala - -enum FooA { - NORMAL = 0 -} diff --git a/testprojects/src/thrift/org/pantsbuild/thrift_exports/B.thrift b/testprojects/src/thrift/org/pantsbuild/thrift_exports/B.thrift deleted file mode 100644 index c1403f37c32..00000000000 --- a/testprojects/src/thrift/org/pantsbuild/thrift_exports/B.thrift +++ /dev/null @@ -1,9 +0,0 @@ -namespace java org.pantsbuild.thrift_exports.thriftjava -#@namespace scala org.pantsbuild.thrift_exports.thriftscala - -include "org/pantsbuild/thrift_exports/A.thrift" - -struct FooB { - 1: i64 id, - 2: optional A.FooA foo_a -}(persisted='true') diff --git a/testprojects/src/thrift/org/pantsbuild/thrift_exports/BUILD b/testprojects/src/thrift/org/pantsbuild/thrift_exports/BUILD deleted file mode 100644 index 7f029c130f4..00000000000 --- a/testprojects/src/thrift/org/pantsbuild/thrift_exports/BUILD +++ /dev/null @@ -1,61 +0,0 @@ -java_thrift_library( - name='A', - sources=[ - 'A.thrift', - ], - language='scala', - compiler='scrooge', -) - -java_thrift_library( - name='B-with-exports', - sources=[ - 'B.thrift', - ], - dependencies=[ - ':A', - ], - exports=[ - ':A', - ], - language='scala', - compiler='scrooge', -) - -java_thrift_library( - name='B-without-exports', - sources=[ - 'B.thrift', - ], - dependencies=[ - ':A', - ], - language='scala', - compiler='scrooge', -) - -java_thrift_library( - name='C-with-exports', - sources=[ - 'C.thrift', - ], - dependencies=[ - ':B-with-exports', - ], - language='scala', - compiler='scrooge', - strict_deps=True, -) - -java_thrift_library( - name='C-without-exports', - sources=[ - 'C.thrift', - ], - dependencies=[ - ':B-without-exports', - ], - language='scala', - compiler='scrooge', - strict_deps=True, -) diff --git a/testprojects/src/thrift/org/pantsbuild/thrift_exports/C.thrift b/testprojects/src/thrift/org/pantsbuild/thrift_exports/C.thrift deleted file mode 100644 index 0d97a453771..00000000000 --- a/testprojects/src/thrift/org/pantsbuild/thrift_exports/C.thrift +++ /dev/null @@ -1,8 +0,0 @@ -namespace java org.pantsbuild.thrift_exports.thriftjava -#@namespace scala org.pantsbuild.thrift_exports.thriftscala - -include "org/pantsbuild/thrift_exports/B.thrift" - -struct FooC { - 1: B.FooB foo_b -}(persisted='true') diff --git a/tests/python/pants_test/base/BUILD b/tests/python/pants_test/base/BUILD index 52dd1103098..fc95ebbe213 100644 --- a/tests/python/pants_test/base/BUILD +++ b/tests/python/pants_test/base/BUILD @@ -158,12 +158,12 @@ python_tests( sources = ['test_exception_sink.py'], dependencies = [ 'src/python/pants/base:exception_sink', + 'src/python/pants/testutil/option', + 'src/python/pants/testutil:test_base', 'src/python/pants/util:contextutil', 'src/python/pants/util:dirutil', 'src/python/pants/util:enums', 'src/python/pants/util:osutil', - 'src/python/pants/testutil:test_base', - 'src/python/pants/testutil/option', ], tags={'platform_specific_behavior', 'partially_type_checked'}, ) @@ -172,6 +172,7 @@ python_tests( name = 'exception_sink_integration', sources = ['test_exception_sink_integration.py'], dependencies = [ + 'examples/src/python/example:hello_directory', 'src/python/pants/base:exception_sink', 'src/python/pants/testutil:int-test', 'src/python/pants/util:osutil', diff --git a/tests/python/pants_test/base/test_exception_sink_integration.py b/tests/python/pants_test/base/test_exception_sink_integration.py index fe71913e9c1..36be1410bdf 100644 --- a/tests/python/pants_test/base/test_exception_sink_integration.py +++ b/tests/python/pants_test/base/test_exception_sink_integration.py @@ -14,10 +14,10 @@ class ExceptionSinkIntegrationTest(PantsDaemonIntegrationTestBase): - def _assert_unhandled_exception_log_matches(self, pid, file_contents): + def _assert_unhandled_exception_log_matches(self, pid, file_contents, namespace): self.assertRegex( file_contents, - """\ + f"""\ timestamp: ([^\n]+) process title: ([^\n]+) sys\\.argv: ([^\n]+) @@ -27,10 +27,8 @@ def _assert_unhandled_exception_log_matches(self, pid, file_contents): Exception message:.* 1 Exception encountered: - ResolveError: "this-target-does-not-exist" was not found in namespace ""\\. Did you mean one of: -""".format( - pid=pid - ), + ResolveError: "this-target-does-not-exist" was not found in namespace "{namespace}"\\. Did you mean one of: +""", ) # Ensure we write all output such as stderr and reporting files before closing any streams. self.assertNotIn("Exception message: I/O operation on closed file.", file_contents) @@ -99,9 +97,10 @@ def test_fails_ctrl_c_on_import(self): self.assertEqual("", read_file(shared_log_file)) def test_logs_unhandled_exception(self): + directory = "examples/src/python/example/hello/main" with temporary_dir() as tmpdir: pants_run = self.run_pants_with_workdir( - ["--no-pantsd", "list", "//:this-target-does-not-exist"], + ["--no-pantsd", "list", f"{directory}:this-target-does-not-exist"], workdir=tmpdir, # The backtrace should be omitted when --print-exception-stacktrace=False. print_exception_stacktrace=False, @@ -109,15 +108,17 @@ def test_logs_unhandled_exception(self): self.assert_failure(pants_run) self.assertRegex( pants_run.stderr_data, - """\ -"this-target-does-not-exist" was not found in namespace ""\\. Did you mean one of: + f"""\ +"this-target-does-not-exist" was not found in namespace "{directory}"\\. Did you mean one of: """, ) pid_specific_log_file, shared_log_file = self._get_log_file_paths(tmpdir, pants_run.pid) self._assert_unhandled_exception_log_matches( - pants_run.pid, read_file(pid_specific_log_file) + pants_run.pid, read_file(pid_specific_log_file), namespace=directory + ) + self._assert_unhandled_exception_log_matches( + pants_run.pid, read_file(shared_log_file), namespace=directory ) - self._assert_unhandled_exception_log_matches(pants_run.pid, read_file(shared_log_file)) def _assert_graceful_signal_log_matches(self, pid, signum, signame, contents): self.assertRegex( diff --git a/tests/python/pants_test/core_tasks/BUILD b/tests/python/pants_test/core_tasks/BUILD index 6566d357fb8..5b9c92128a7 100644 --- a/tests/python/pants_test/core_tasks/BUILD +++ b/tests/python/pants_test/core_tasks/BUILD @@ -1,17 +1,6 @@ # Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). # Licensed under the Apache License, Version 2.0 (see LICENSE). -python_tests( - name='bash_completion', - sources=['test_bash_completion.py'], - coverage=['pants.core_tasks.bash_completion'], - dependencies=[ - 'src/python/pants/core_tasks', - 'src/python/pants/testutil:task_test_base', - ], - tags = {"partially_type_checked"}, -) - python_tests( name = 'prep_command_integration', sources = ['test_prep_command_integration.py'], diff --git a/tests/python/pants_test/integration/BUILD b/tests/python/pants_test/integration/BUILD index b3e8c3d5f0a..52671c4382c 100644 --- a/tests/python/pants_test/integration/BUILD +++ b/tests/python/pants_test/integration/BUILD @@ -57,7 +57,7 @@ python_tests( sources = ['goal_rule_integration_test.py'], dependencies = [ 'tests/python/pants_test/pantsd:pantsd_integration_test_base', - 'examples/src/scala/org/pantsbuild/example:hello_directory', + 'examples/src/python/example:hello_directory', 'testprojects/tests/python/pants:dummies_directory', ], tags = {'integration', 'partially_type_checked'}, diff --git a/tests/python/pants_test/integration/goal_rule_integration_test.py b/tests/python/pants_test/integration/goal_rule_integration_test.py index 3dbb1d937bd..aa634f9bc45 100644 --- a/tests/python/pants_test/integration/goal_rule_integration_test.py +++ b/tests/python/pants_test/integration/goal_rule_integration_test.py @@ -13,20 +13,20 @@ class TestGoalRuleIntegration(PantsDaemonIntegrationTestBase): - list_target = "examples/src/java/org/pantsbuild/example/hello::" + target = "examples/src/python/example/hello::" @ensure_daemon def test_v2_list(self): - result = self.do_command("list", self.list_target, success=True) + result = self.do_command("list", self.target, success=True) output_lines = result.stdout_data.splitlines() - self.assertEqual(len(output_lines), 4) - self.assertIn("examples/src/java/org/pantsbuild/example/hello/main:main-bin", output_lines) + self.assertEqual(len(output_lines), 3) + self.assertIn("examples/src/python/example/hello/main:main", output_lines) def test_v2_list_does_not_cache(self): with self.pantsd_successful_run_context() as ctx: def run_list(): - result = ctx.runner(["list", self.list_target]) + result = ctx.runner(["list", self.target]) ctx.checker.assert_started() return result @@ -42,7 +42,7 @@ def test_v2_goal_validation(self): @ensure_daemon def test_v2_goal_validation_both(self): - self.do_command("--v1", "--v2", "filedeps", ":", success=True) + self.do_command("--v1", "--v2", "filedeps", self.target, success=True) def test_v2_list_loop(self): # Create a BUILD file in a nested temporary directory, and add additional targets to it. diff --git a/tests/python/pants_test/projects/projects_test_base.py b/tests/python/pants_test/projects/projects_test_base.py index 84eec63c7ea..bd304d21c3b 100644 --- a/tests/python/pants_test/projects/projects_test_base.py +++ b/tests/python/pants_test/projects/projects_test_base.py @@ -15,8 +15,6 @@ def skipped_targets(self) -> List[str]: # to be first in the context, and test.junit mixes all classpaths. "testprojects/maven_layout/resource_collision/example_b/src/test/java/org/pantsbuild/duplicateres/exampleb:exampleb", "testprojects/maven_layout/resource_collision/example_c/src/test/java/org/pantsbuild/duplicateres/examplec:examplec", - # TODO: This one has a missing dependency, but is intended to succeed... should it? - "testprojects/src/java/org/pantsbuild/testproject/thriftdeptest", # TODO(Eric Ayers): I don't understand why this fails "testprojects/src/java/org/pantsbuild/testproject/jvmprepcommand:compile-prep-command", # TODO(#7903): failing to find -ltensorflow_framework @@ -40,7 +38,6 @@ def skipped_targets(self) -> List[str]: "testprojects/src/java/org/pantsbuild/testproject/runtime:compile-fail", "testprojects/src/scala/org/pantsbuild/testproject/compilation_failure", "testprojects/src/scala/org/pantsbuild/testproject/compilation_warnings:fatal", - "testprojects/src/thrift/org/pantsbuild/thrift_exports:C-without-exports", "testprojects/src/thrift/org/pantsbuild/thrift_linter:", "testprojects/src/java/org/pantsbuild/testproject/provided:c", "testprojects/tests/java/org/pantsbuild/testproject/dummies:failing_target",