From 7a61dcffe8ea52d96a794e394bb4b7fc2d172ce9 Mon Sep 17 00:00:00 2001 From: Olafur Pall Geirsson Date: Fri, 29 Nov 2019 10:12:23 +0000 Subject: [PATCH] Include strict_deps in export output. Previously, the `./pants export` output did not include information whether a target has enabled strict dependencies or not. This information is needed in order to faithfully reproduce the compilation outside of Pants, for example with the IntelliJ compiler or with Bloop see (https://github.com/scalameta/metals/pull/935). --- .../backend/project_info/tasks/export.py | 6 ++++++ .../backend/project_info/tasks/test_export.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/python/pants/backend/project_info/tasks/export.py b/src/python/pants/backend/project_info/tasks/export.py index d6461a2071f3..d2390d366f17 100644 --- a/src/python/pants/backend/project_info/tasks/export.py +++ b/src/python/pants/backend/project_info/tasks/export.py @@ -276,6 +276,12 @@ def iter_transitive_jars(jar_lib): if classpath_products: info['libraries'] = [self._jar_id(lib) for lib in target_libraries] + + strict_deps = False + if hasattr(current_target, 'strict_deps'): + strict_deps = True == getattr(current_target, 'strict_deps') + info['strict_deps'] = strict_deps + targets_map[current_target.address.spec] = info for target in targets: diff --git a/tests/python/pants_test/backend/project_info/tasks/test_export.py b/tests/python/pants_test/backend/project_info/tasks/test_export.py index 81ea4b47da81..5859cf808325 100644 --- a/tests/python/pants_test/backend/project_info/tasks/test_export.py +++ b/tests/python/pants_test/backend/project_info/tasks/test_export.py @@ -237,6 +237,18 @@ def setUp(self): target_type=JvmTarget, ) + self.make_target( + 'strict_deps:enabled', + target_type=JvmTarget, + strict_deps=True + ) + + self.make_target( + 'strict_deps:disabled', + target_type=JvmTarget, + strict_deps=False + ) + self.add_to_build_file('src/python/x/BUILD', """ python_library(name="x", sources=globs("*.py")) """.strip()) @@ -358,6 +370,12 @@ def test_scala_platform_standard(self): scala_jars = scala_platform['compiler_classpath'] self.assertTrue(any('2.12' in jar_path for jar_path in scala_jars)) + def test_strict_deps(self): + enabled_result = self.execute_export_json('strict_deps:enabled')['targets']['strict_deps:enabled'] + disabled_result = self.execute_export_json('strict_deps:disabled')['targets']['strict_deps:disabled'] + self.assertTrue(enabled_result['strict_deps']) + self.assertFalse(disabled_result['strict_deps']) + def test_sources(self): self.set_options(sources=True) result = self.execute_export_json('project_info:third') @@ -418,6 +436,7 @@ def test_jvm_target(self): }, ], 'scope' : 'default', + 'strict_deps' : False, 'target_type': 'SOURCE', 'transitive' : True, 'pants_target_type': 'scala_library',