Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Commit

Permalink
Collapse SyntheticAddress up into Address. [API]
Browse files Browse the repository at this point in the history
This makes Address concrete with only a single BuildFileAddress subclass
that may be removed later.  SyntheticAddress use is removed from the
pants codebase but the class is kept around for a deprecation cycle for
plugin writers with forwardings set up to Address.

Testing Done:
CI went green here:
  https://travis-ci.org/pantsbuild/pants/builds/77975439

Bugs closed: 2093, 2095

Reviewed at https://rbcommons.com/s/twitter/r/2730/
  • Loading branch information
jsirois committed Aug 31, 2015
1 parent 53f517e commit 0d9e045
Show file tree
Hide file tree
Showing 40 changed files with 163 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import sys
from difflib import unified_diff

from pants.base.address import BuildFileAddress, SyntheticAddress
from pants.base.address import Address, BuildFileAddress


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -338,7 +338,7 @@ def __init__(self,
self._dependencies_by_address = {}

for dep in dependencies:
dep_address = SyntheticAddress.parse(dep.spec, relative_to=build_file.spec_path)
dep_address = Address.parse(dep.spec, relative_to=build_file.spec_path)
if dep_address in self._dependencies_by_address:
raise BuildTargetParseError('The address {dep_address} occurred multiple times in the '
'dependency specs for target {name} in {build_file}. '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from textwrap import dedent

from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants_test.base_test import BaseTest

from pants.contrib.buildgen.build_file_manipulator import (BuildFileManipulator,
Expand Down Expand Up @@ -154,15 +154,15 @@ def test_simple_targets(self):
build_file = self.add_to_build_file('BUILD', simple_targets)

for no_deps_name in ['no_deps', 'empty_deps', 'empty_deps_inline']:
no_deps = BuildFileManipulator.load(build_file, no_deps_name, set(['target_type']))
no_deps = BuildFileManipulator.load(build_file, no_deps_name, {'target_type'})
self.assertEqual(tuple(no_deps.dependency_lines()), tuple())
no_deps.add_dependency(SyntheticAddress.parse(':fake_dep'))
no_deps.add_dependency(Address.parse(':fake_dep'))
self.assertEqual(tuple(no_deps.dependency_lines()),
tuple([' dependencies = [',
" ':fake_dep',",
' ],']))
no_deps.add_dependency(SyntheticAddress.parse(':b_fake_dep'))
no_deps.add_dependency(SyntheticAddress.parse(':a_fake_dep'))
no_deps.add_dependency(Address.parse(':b_fake_dep'))
no_deps.add_dependency(Address.parse(':a_fake_dep'))
self.assertEqual(tuple(no_deps.dependency_lines()),
tuple([' dependencies = [',
" ':a_fake_dep',",
Expand Down Expand Up @@ -267,8 +267,8 @@ def test_target_insertion_bottom(self):

build_file = self.add_to_build_file('BUILD', self.multi_target_build_string)

multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_bottom', set(['target_type']))
multi_targ_bfm.add_dependency(SyntheticAddress.parse(':new_dep'))
multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_bottom', {'target_type'})
multi_targ_bfm.add_dependency(Address.parse(':new_dep'))
build_file_str = '\n'.join(multi_targ_bfm.build_file_lines())
self.assertEqual(build_file_str, expected_build_string)

Expand Down Expand Up @@ -301,8 +301,8 @@ def test_target_insertion_top(self):

build_file = self.add_to_build_file('BUILD', self.multi_target_build_string)

multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_top', set(['target_type']))
multi_targ_bfm.add_dependency(SyntheticAddress.parse(':new_dep'))
multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_top', {'target_type'})
multi_targ_bfm.add_dependency(Address.parse(':new_dep'))
build_file_str = '\n'.join(multi_targ_bfm.build_file_lines())
self.assertEqual(build_file_str, expected_build_string)

Expand Down Expand Up @@ -335,8 +335,8 @@ def test_target_insertion_middle(self):

build_file = self.add_to_build_file('BUILD', self.multi_target_build_string)

multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_middle', set(['target_type']))
multi_targ_bfm.add_dependency(SyntheticAddress.parse(':new_dep'))
multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_middle', {'target_type'})
multi_targ_bfm.add_dependency(Address.parse(':new_dep'))
build_file_str = '\n'.join(multi_targ_bfm.build_file_lines())
self.assertEqual(build_file_str, expected_build_string)

Expand Down Expand Up @@ -370,8 +370,8 @@ def test_target_write(self):

build_file = self.add_to_build_file('BUILD', self.multi_target_build_string + '\n')

multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_middle', set(['target_type']))
multi_targ_bfm.add_dependency(SyntheticAddress.parse(':new_dep'))
multi_targ_bfm = BuildFileManipulator.load(build_file, 'target_middle', {'target_type'})
multi_targ_bfm.add_dependency(Address.parse(':new_dep'))
multi_targ_bfm.write(dry_run=False)

with open(build_file.full_path, 'r') as bf:
Expand Down
8 changes: 4 additions & 4 deletions contrib/go/src/python/pants/contrib/go/tasks/go_buildgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections import defaultdict, namedtuple
from textwrap import dedent

from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.base.generator import Generator, TemplateData
Expand Down Expand Up @@ -84,7 +84,7 @@ def _generate_missing(self, gopath, local_address, name, import_paths, visited):
remote_root = fetcher.root(import_path)
remote_pkg_path = GoRemoteLibrary.remote_package_path(remote_root, import_path)
name = remote_pkg_path or os.path.basename(import_path)
address = SyntheticAddress(os.path.join(self._remote_source_root, remote_root), name)
address = Address(os.path.join(self._remote_source_root, remote_root), name)
found = self._build_graph.get_target(address)
if not found:
if not self._generate_remotes:
Expand All @@ -95,8 +95,8 @@ def _generate_missing(self, gopath, local_address, name, import_paths, visited):
pkg=remote_pkg_path)
else:
# Recurse on local targets.
address = SyntheticAddress(os.path.join(self._local_source_root, import_path),
os.path.basename(import_path))
address = Address(os.path.join(self._local_source_root, import_path),
os.path.basename(import_path))
name, import_paths = self._list_deps(gopath, address)
self._generate_missing(gopath, address, name, import_paths, visited)
visited[import_path] = address
Expand Down
4 changes: 2 additions & 2 deletions contrib/go/src/python/pants/contrib/go/tasks/go_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import shutil
from collections import defaultdict

from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.address_lookup_error import AddressLookupError
from pants.base.exceptions import TaskError
from pants.util.contextutil import temporary_dir
Expand Down Expand Up @@ -134,7 +134,7 @@ def _transitive_download_remote_libs(self, go_remote_libs, all_known_addresses=N
package_path = GoRemoteLibrary.remote_package_path(remote_root, remote_import_path)
target_name = package_path or os.path.basename(remote_root)

address = SyntheticAddress(spec_path, target_name)
address = Address(spec_path, target_name)
if address not in all_known_addresses:
try:
# If we've already resolved a package from this remote root, its ok to define an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import shutil
from collections import defaultdict

from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.source_root import SourceRoot
from pants.util.contextutil import temporary_dir
from pants_test.tasks.task_test_base import TaskTestBase
Expand All @@ -21,7 +21,7 @@

class GoFetchTest(TaskTestBase):

address = SyntheticAddress.parse
address = Address.parse

@classmethod
def task_type(cls):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.backend.jvm.targets.scala_library import ScalaLibrary
from pants.backend.jvm.tasks.nailgun_task import NailgunTask
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.address_lookup_error import AddressLookupError
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TargetDefinitionException, TaskError
Expand Down Expand Up @@ -234,7 +234,7 @@ def createtarget(self, gentarget, dependees, outdir, gen_files_for_source):

def create_target(files, deps, target_type):
spec = '{spec_path}:{name}'.format(spec_path=outdir, name=gentarget.id)
address = SyntheticAddress.parse(spec=spec)
address = Address.parse(spec=spec)
return self.context.add_new_target(address,
target_type,
sources=files,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pants.backend.codegen.targets.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.address import SyntheticAddress
from pants.base.address import Address
from pants.base.build_environment import get_buildroot
from pants.base.build_file_aliases import BuildFileAliases
from pants.base.exceptions import TaskError
Expand Down Expand Up @@ -134,7 +134,7 @@ def _test_help(self, build_string, library_type, sources):
task.execute()
relative_task_outdir = os.path.relpath(self.task_outdir, get_buildroot())
spec = '{spec_path}:{name}'.format(spec_path=relative_task_outdir, name='test_smoke.a')
address = SyntheticAddress.parse(spec=spec)
address = Address.parse(spec=spec)
Context.add_new_target.assert_called_once_with(address,
library_type,
sources=sources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.backend.jvm.targets.scala_library import ScalaLibrary
from pants.backend.jvm.tasks.nailgun_task import NailgunTask
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.base.source_root import SourceRoot
Expand Down Expand Up @@ -121,7 +121,7 @@ def execute(self):
java_synthetic_name = '{0}-{1}'.format(target.id, 'java')
java_sources_rel_path = os.path.relpath(self.namespace_out, get_buildroot())
java_spec_path = java_sources_rel_path
java_synthetic_address = SyntheticAddress(java_spec_path, java_synthetic_name)
java_synthetic_address = Address(java_spec_path, java_synthetic_name)
java_generated_sources = [
os.path.join(os.path.dirname(source), 'java_{0}.java'.format(os.path.basename(source)))
for source in self.sources_generated_by_target(target)
Expand Down Expand Up @@ -162,7 +162,7 @@ def execute(self):
synthetic_name = '{0}-{1}'.format(target.id, 'scala')
sources_rel_path = os.path.relpath(self.namespace_out, get_buildroot())
spec_path = sources_rel_path
synthetic_address = SyntheticAddress(spec_path, synthetic_name)
synthetic_address = Address(spec_path, synthetic_name)
generated_sources = [
'{0}.{1}'.format(source, 'scala')
for source in self.sources_generated_by_target(target)
Expand Down
14 changes: 7 additions & 7 deletions src/python/pants/backend/android/tasks/aapt_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pants.backend.jvm.targets.jar_dependency import JarDependency
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.base.workunit import WorkUnitLabel
Expand Down Expand Up @@ -70,7 +70,7 @@ def create_sdk_jar_deps(self, binaries):
if sdk not in self._jar_library_by_sdk:
jar_url = 'file://{0}'.format(self.android_jar(binary))
jar = JarDependency(org='com.google', name='android', rev=sdk, url=jar_url)
address = SyntheticAddress(self.workdir, 'android-{0}.jar'.format(sdk))
address = Address(self.workdir, 'android-{0}.jar'.format(sdk))
self._jar_library_by_sdk[sdk] = self.context.add_new_target(address, JarLibrary, jars=[jar])

def _render_args(self, binary, manifest, resource_dirs):
Expand Down Expand Up @@ -150,13 +150,13 @@ def create_target(self, binary, gentarget):
:rtype::class:`pants.backend.jvm.targets.java_library.JavaLibrary`
"""
spec_path = os.path.join(os.path.relpath(self.aapt_out(binary), get_buildroot()))
address = SyntheticAddress(spec_path=spec_path, target_name=gentarget.id)
address = Address(spec_path=spec_path, target_name=gentarget.id)
deps = [self._jar_library_by_sdk[binary.target_sdk]]
new_target = self.context.add_new_target(address,
JavaLibrary,
derived_from=gentarget,
sources=[self._relative_genfile(gentarget)],
dependencies=deps)
JavaLibrary,
derived_from=gentarget,
sources=[self._relative_genfile(gentarget)],
dependencies=deps)
return new_target

def aapt_out(self, binary):
Expand Down
8 changes: 4 additions & 4 deletions src/python/pants/backend/android/tasks/unpack_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from pants.backend.core.tasks.task import Task
from pants.backend.jvm.targets.jar_dependency import JarDependency
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.build_environment import get_buildroot
from pants.base.fingerprint_strategy import DefaultFingerprintStrategy
from pants.fs.archive import ZIP
Expand Down Expand Up @@ -92,7 +92,7 @@ def create_classes_jar_target(self, target, archive, jar_file):
archive_version = os.path.splitext(archive)[0].rpartition('-')[-1]
jar_url = 'file://{0}'.format(jar_file)
jar_dep = JarDependency(org=target.id, name=archive, rev=archive_version, url=jar_url)
address = SyntheticAddress(self.workdir, '{}-classes.jar'.format(archive))
address = Address(self.workdir, '{}-classes.jar'.format(archive))
new_target = self.context.add_new_target(address, JarLibrary, jars=[jar_dep],
derived_from=target)
return new_target
Expand All @@ -107,7 +107,7 @@ def create_resource_target(self, target, archive, manifest, resource_dir):
:rtype::class:`pants.backend.android.targets.AndroidResources`
"""

address = SyntheticAddress(self.workdir, '{}-resources'.format(archive))
address = Address(self.workdir, '{}-resources'.format(archive))
new_target = self.context.add_new_target(address, AndroidResources,
manifest=manifest, resource_dir=resource_dir,
derived_from=target)
Expand Down Expand Up @@ -143,7 +143,7 @@ def create_android_library_target(self, target, archive, unpacked_aar_location):
if os.path.isfile(jar_file):
deps.append(self.create_classes_jar_target(target, archive, jar_file))

address = SyntheticAddress(self.workdir, '{}-android_library'.format(archive))
address = Address(self.workdir, '{}-android_library'.format(archive))
new_target = self.context.add_new_target(address, AndroidLibrary,
manifest=manifest,
include_patterns=target.include_patterns,
Expand Down
7 changes: 3 additions & 4 deletions src/python/pants/backend/codegen/tasks/protobuf_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pants.backend.codegen.tasks.simple_codegen_task import SimpleCodegenTask
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.base.source_root import SourceRoot
Expand Down Expand Up @@ -100,9 +100,8 @@ def synthetic_target_extra_dependencies(self, target):
deps = OrderedSet()
if target.imported_jars:
# We need to add in the proto imports jars.
jars_address = SyntheticAddress(
os.path.relpath(self.codegen_workdir(target), get_buildroot()),
target.id + '-rjars')
jars_address = Address(os.path.relpath(self.codegen_workdir(target), get_buildroot()),
target.id + '-rjars')
jars_target = self.context.add_new_target(jars_address,
JarLibrary,
jars=target.imported_jars,
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/codegen/tasks/simple_codegen_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from twitter.common.collections import OrderedSet

from pants.backend.core.tasks.task import Task
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.address_lookup_error import AddressLookupError
from pants.base.build_environment import get_buildroot
from pants.base.build_graph import sort_targets
Expand Down Expand Up @@ -222,7 +222,7 @@ def execute(self):
target_workdir = self.codegen_workdir(target)
synthetic_name = target.id
sources_rel_path = os.path.relpath(target_workdir, get_buildroot())
synthetic_address = SyntheticAddress(sources_rel_path, synthetic_name)
synthetic_address = Address(sources_rel_path, synthetic_name)
raw_generated_sources = list(self.codegen_strategy.find_sources(target))
# Make the sources robust regardless of whether subclasses return relative paths, or
# absolute paths that are subclasses of the workdir.
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/core/tasks/markdown_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from pants.backend.core.targets.doc import Page
from pants.backend.core.tasks.task import Task
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.build_environment import get_buildroot
from pants.base.exceptions import TaskError
from pants.base.generator import Generator
Expand Down Expand Up @@ -332,7 +332,7 @@ def process_md(self, output_path, source, fragmented, url_builder, css=None):
def parse_url(spec):
match = self.PANTS_LINK.match(spec)
if match:
address = SyntheticAddress.parse(match.group(1), relative_to=get_buildroot())
address = Address.parse(match.group(1), relative_to=get_buildroot())
page = self.context.build_graph.get_target(address)
anchor = match.group(2) or ''
if not page:
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/jvm/targets/jar_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import six

from pants.backend.jvm.targets.jar_dependency import JarDependency
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.exceptions import TargetDefinitionException
from pants.base.payload import Payload
from pants.base.payload_field import ExcludesField, JarsField
Expand Down Expand Up @@ -72,7 +72,7 @@ def to_jar_dependencies(relative_to, jar_library_specs, build_graph):
.format(address=relative_to.spec,
found_class=type(spec).__name__))

lookup = SyntheticAddress.parse(spec, relative_to=relative_to.spec_path)
lookup = Address.parse(spec, relative_to=relative_to.spec_path)
target = build_graph.get_target(lookup)
if not isinstance(target, JarLibrary):
raise JarLibrary.WrongTargetTypeError(
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/jvm/targets/scala_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pants.backend.jvm.subsystems.scala_platform import ScalaPlatform
from pants.backend.jvm.targets.exportable_jvm_library import ExportableJvmLibrary
from pants.base.address import SyntheticAddress
from pants.base.address import Address
from pants.base.exceptions import TargetDefinitionException


Expand Down Expand Up @@ -68,7 +68,7 @@ def get_jar_dependencies(self):
@property
def java_sources(self):
for spec in self._java_sources_specs:
address = SyntheticAddress.parse(spec, relative_to=self.address.spec_path)
address = Address.parse(spec, relative_to=self.address.spec_path)
target = self._build_graph.get_target(address)
if target is None:
raise TargetDefinitionException(self, 'No such java target: {}'.format(spec))
Expand Down
Loading

0 comments on commit 0d9e045

Please sign in to comment.