Skip to content

Commit

Permalink
Remove java_sources as target roots for scala library in depmap proje…
Browse files Browse the repository at this point in the history
…ct info pantsbuild#670

Testing Done:
ci passes

Reviewed at https://rbcommons.com/s/twitter/r/1190/
  • Loading branch information
fkorotkov authored and fkorotkov committed Oct 28, 2014
1 parent d97b7b9 commit dbd339f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
16 changes: 6 additions & 10 deletions src/python/pants/backend/jvm/tasks/depmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,19 +298,15 @@ def get_transitive_jars(jar_lib):
if isinstance(dep, Resources):
resource_target_map[dep] = current_target

java_sources_targets = list(current_target.java_sources) if isinstance(current_target,
ScalaLibrary) else []
"""
:type java_sources_targets:list[pants.base.target.Target]
"""
if isinstance(current_target, ScalaLibrary):
for dep in current_target.java_sources:
info['targets'].append(self._address(dep.address))

roots = set(itertools.chain(
*[self._source_roots_for_target(t) for t in java_sources_targets + [current_target]]
))
info['roots'] = map(lambda (source_root, package_prefix): {
'source_root': source_root,
'package_prefix': package_prefix
}, roots)
}, self._source_roots_for_target(current_target))

info['libraries'] = [self._jar_id(lib) for lib in target_libraries]
targets_map[self._address(current_target.address)] = info

Expand Down Expand Up @@ -344,5 +340,5 @@ def _source_roots_for_target(target):
def root_package_prefix(source_file):
source = os.path.dirname(source_file)
return os.path.join(get_buildroot(), target.target_base, source), source.replace(os.sep, '.')
return map(root_package_prefix, target.sources_relative_to_source_root())
return set(map(root_package_prefix, target.sources_relative_to_source_root()))

31 changes: 13 additions & 18 deletions tests/python/pants_test/tasks/test_depmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,28 +362,23 @@ def test_with_dependencies(self):
args=['--test-project-info'],
targets=[self.target('project_info:third')]
))
self.assertEqual(['org.apache:apache-jar:12.12.2012'], result['targets']['project_info:third']['libraries'])
self.assertEqual(2, len(result['targets']['project_info:third']['roots']))
self.assertEqual(
'com.foo',
result['targets']['project_info:third']['roots'][0]['package_prefix']
)
self.assertEqual(
'com.foo',
result['targets']['project_info:third']['roots'][1]['package_prefix']
)

self.assertEqual(
[
'%s/java/project_info/com/foo' % self.build_root,
'%s/project_info/com/foo' % self.build_root
'java/project_info:java_lib',
'project_info:jar_lib'
],
sorted([
result['targets']['project_info:third']['roots'][0]['source_root'],
result['targets']['project_info:third']['roots'][1]['source_root']
])
sorted(result['targets']['project_info:third']['targets'])
)
self.assertEqual(['org.apache:apache-jar:12.12.2012'], result['targets']['project_info:third']['libraries'])

self.assertEqual(1, len(result['targets']['project_info:third']['roots']))
source_root = result['targets']['project_info:third']['roots'][0]
self.assertEqual('com.foo', source_root['package_prefix'])
self.assertEqual(
'%s/project_info/com/foo' % self.build_root,
source_root['source_root']
)
self.assertEqual(['org.apache:apache-jar:12.12.2012'],
result['targets']['project_info:third']['libraries'])

def test_jvm_app(self):
result = get_json(self.execute_console_task(
Expand Down

0 comments on commit dbd339f

Please sign in to comment.