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

Commit

Permalink
Add is_target_root in export
Browse files Browse the repository at this point in the history
To reconstruct the build graph for import/indexing optimization, intellij pants plugin would need to know where roots start in the graph.

Testing Done:
https://travis-ci.org/pantsbuild/pants/builds/140961443

Bugs closed: 3610

Reviewed at https://rbcommons.com/s/twitter/r/4030/
  • Loading branch information
wisechengyi committed Jun 29, 2016
1 parent 22d9d82 commit ed5e22f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/docs/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ The following is an abbreviated export file from a command in the pants repo:

# Export Format Changes

## 1.0.9

Added 'is_target_root' field to target

## 1.0.8

Conditionally added 'transitive' and 'scope' fields to target
Expand Down
5 changes: 4 additions & 1 deletion src/python/pants/backend/project_info/tasks/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ExportTask(IvyTaskMixin, PythonTask):
#
# Note format changes in src/docs/export.md and update the Changelog section.
#
DEFAULT_EXPORT_VERSION = '1.0.8'
DEFAULT_EXPORT_VERSION = '1.0.9'

@classmethod
def subsystem_dependencies(cls):
Expand Down Expand Up @@ -173,6 +173,8 @@ def generate_targets_map(self, targets, classpath_products=None):
else:
classpath_products = None

target_roots_set = set(self.context.target_roots)

def process_target(current_target):
"""
:type current_target:pants.build_graph.target.Target
Expand Down Expand Up @@ -209,6 +211,7 @@ def get_target_type(target):

info['transitive'] = current_target.transitive
info['scope'] = str(current_target.scope)
info['is_target_root'] = current_target in target_roots_set

if isinstance(current_target, PythonRequirementLibrary):
reqs = current_target.payload.get_field_value('requirements', set())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_without_dependencies(self):
def test_version(self):
result = self.execute_export_json('project_info:first')
# If you have to update this test, make sure export.md is updated with changelog notes
self.assertEqual('1.0.8', result['version'])
self.assertEqual('1.0.9', result['version'])

def test_sources(self):
self.set_options(sources=True)
Expand Down Expand Up @@ -272,6 +272,7 @@ def test_jvm_target(self):
'is_code_gen': False,
'targets': ['project_info:jar_lib', '//:scala-library'],
'is_synthetic': False,
'is_target_root': True,
'roots': [
{
'source_root': '{root}/project_info/this/is/a/source'.format(root=self.build_root),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,14 @@ def test_intransitive_and_scope(self):
synthetic_target = '{}:shadow-unstable-intransitive-1'.format(test_path)
self.assertEquals(False, json_data['targets'][synthetic_target]['transitive'])
self.assertEquals('compile test', json_data['targets'][synthetic_target]['scope'])

def test_export_is_target_roots(self):
with self.temporary_workdir() as workdir:
test_target = 'examples/tests/java/org/pantsbuild/example/::'
json_data = self.run_export(test_target, workdir, load_libs=False)
for target_address, attributes in json_data['targets'].items():
# Make sure all targets under `test_target`'s directory are target roots.
self.assertEqual(
attributes['is_target_root'],
target_address.startswith("examples/tests/java/org/pantsbuild/example")
)

0 comments on commit ed5e22f

Please sign in to comment.