From c1115c613988588aa78836bdb67a2befe9ce18e5 Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Wed, 20 Jun 2018 14:23:31 +0100 Subject: [PATCH] Fix up for go --- .../pants/contrib/go/targets/go_binary.py | 1 + .../pants/contrib/go/targets/go_library.py | 1 + src/python/pants/engine/legacy/structs.py | 17 ----------------- src/python/pants/init/engine_initializer.py | 13 +++++++++++++ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/contrib/go/src/python/pants/contrib/go/targets/go_binary.py b/contrib/go/src/python/pants/contrib/go/targets/go_binary.py index c9906ebc6b0..4044cf1ecbb 100644 --- a/contrib/go/src/python/pants/contrib/go/targets/go_binary.py +++ b/contrib/go/src/python/pants/contrib/go/targets/go_binary.py @@ -12,6 +12,7 @@ class GoBinary(GoLocalSource): """A local Go main package.""" default_sources_globs = '*' + default_sources_exclude_globs = ('BUILD', 'BUILD.*') @classmethod def alias(cls): diff --git a/contrib/go/src/python/pants/contrib/go/targets/go_library.py b/contrib/go/src/python/pants/contrib/go/targets/go_library.py index 436c98435cd..dd46eba6ec3 100644 --- a/contrib/go/src/python/pants/contrib/go/targets/go_library.py +++ b/contrib/go/src/python/pants/contrib/go/targets/go_library.py @@ -12,6 +12,7 @@ class GoLibrary(GoLocalSource): """A local Go package.""" default_sources_globs = '*' + default_sources_exclude_globs = ('BUILD', 'BUILD.*') @classmethod def alias(cls): diff --git a/src/python/pants/engine/legacy/structs.py b/src/python/pants/engine/legacy/structs.py index 27ad9e74db0..1f7d88c0da3 100644 --- a/src/python/pants/engine/legacy/structs.py +++ b/src/python/pants/engine/legacy/structs.py @@ -273,23 +273,6 @@ def default_sources_globs(self): return self.python_test_globs -class GoTargetAdaptor(TargetAdaptor): - - @property - def default_sources(self): - # Go has always used implicit_sources: override to ignore the option. - return True - - @property - def default_sources_globs(self): - # N.B. Go targets glob on `*` due to the way resources and .c companion files are handled. - return ('*',) - - @property - def default_sources_exclude_globs(self): - return ('BUILD', 'BUILD.*') - - class PantsPluginAdaptor(PythonTargetAdaptor): def get_sources(self): return ['register.py'] diff --git a/src/python/pants/init/engine_initializer.py b/src/python/pants/init/engine_initializer.py index 4698c4f7dd1..a0406f42ef5 100644 --- a/src/python/pants/init/engine_initializer.py +++ b/src/python/pants/init/engine_initializer.py @@ -58,6 +58,19 @@ def __init__(self, build_file_aliases): for alias, target_type in build_file_aliases.target_types.items() } + for alias, factory in build_file_aliases.target_macro_factories.items(): + # TargetMacro.Factory with more than one target type is deprecated. + # For default sources, this means that TargetMacro Factories with more than one target_type + # will not parse sources through the engine, and will fall back to the legacy python sources + # parsing. + # Conveniently, multi-target_type TargetMacro.Factory, and legacy python source parsing, are + # targeted to be removed in the same version of pants. + if len(factory.target_types) == 1: + self._table[alias] = self._make_target_adaptor( + TargetAdaptor, + tuple(factory.target_types)[0], + ) + # TODO: The alias replacement here is to avoid elevating "TargetAdaptors" into the public # API until after https://github.com/pantsbuild/pants/issues/3560 has been completed. # These should likely move onto Target subclasses as the engine gets deeper into beta