Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only compile non-module exports for export-dep-as-jar goal #8914

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/python/pants/backend/jvm/tasks/jvm_compile/jvm_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def __init__(self, *args, **kwargs):
self._worker_count = worker_count

self._size_estimator = self.size_estimator_by_name(self.get_options().size_estimator)
self._classpath_product_key = "runtime_classpath"

@memoized_property
def _missing_deps_finder(self):
Expand Down Expand Up @@ -432,7 +433,7 @@ def execute(self):
return

# Clone the compile_classpath to the runtime_classpath.
classpath_product = self.create_runtime_classpath()
classpath_product = self.create_classpath_product()

fingerprint_strategy = DependencyContext.global_instance().create_fingerprint_strategy(
classpath_product)
Expand Down Expand Up @@ -467,11 +468,13 @@ def _classpath_for_context(self, context):
return context.jar_file
return context.classes_dir

def create_runtime_classpath(self):
def create_classpath_product(self):
if self.context.products.is_required_data("export_dep_as_jar_classpath"):
self._classpath_product_key = "export_dep_as_jar_classpath"
compile_classpath = self.context.products.get_data('compile_classpath')
classpath_product = self.context.products.get_data('runtime_classpath')
classpath_product = self.context.products.get_data(self._classpath_product_key)
if not classpath_product:
classpath_product = self.context.products.get_data('runtime_classpath', compile_classpath.copy)
classpath_product = self.context.products.get_data(self._classpath_product_key, compile_classpath.copy)
else:
classpath_product.update(compile_classpath)

Expand All @@ -483,6 +486,12 @@ def do_compile(self, invalidation_check, compile_contexts, classpath_product):
invalid_targets = [vt.target for vt in invalidation_check.invalid_vts]
valid_targets = [vt.target for vt in invalidation_check.all_vts if vt.valid]

if self.context.products.is_required_data("export_dep_as_jar_classpath"):
# filter modulized targets from invalid targets list.
target_root_addresses = [t.address for t in set(self.context.target_roots)]
dependees_of_target_roots = self.context.build_graph.transitive_dependees_of_addresses(target_root_addresses)
hrfuller marked this conversation as resolved.
Show resolved Hide resolved
invalid_targets = list(set(invalid_targets) - dependees_of_target_roots)

if self.execution_strategy == self.ExecutionStrategy.hermetic:
self._set_directory_digests_for_valid_target_classpath_directories(valid_targets, compile_contexts)

Expand Down Expand Up @@ -805,7 +814,7 @@ def create_compile_jobs(self, compile_target, all_compile_contexts, invalid_depe
self._default_work_for_vts,
ivts,
compile_context,
'runtime_classpath',
self._classpath_product_key,
hrfuller marked this conversation as resolved.
Show resolved Hide resolved
counter,
all_compile_contexts,
classpath_product),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ class ZincCompile(BaseZincCompile):

@classmethod
def product_types(cls):
return ['runtime_classpath', 'zinc_analysis', 'zinc_args']
return ['runtime_classpath', 'export_dep_as_jar_classpath', 'zinc_analysis', 'zinc_args']

def select(self, target):
# Require that targets are marked for JVM compilation, to differentiate from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def register_options(cls, register):
@classmethod
def prepare(cls, options, round_manager):
super().prepare(options, round_manager)
round_manager.require_data('runtime_classpath')
round_manager.require_data('export_dep_as_jar_classpath')

@property
def _output_folder(self):
Expand Down Expand Up @@ -354,7 +354,7 @@ def generate_targets_map(self, targets, runtime_classpath):
return graph_info

def console_output(self, targets):
runtime_classpath = self.context.products.get_data('runtime_classpath')
runtime_classpath = self.context.products.get_data('export_dep_as_jar_classpath')
if runtime_classpath is None:
raise TaskError("There was an error compiling the targets - There is no runtime classpath")
graph_info = self.generate_targets_map(targets, runtime_classpath=runtime_classpath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_if_runtime_classpath_exists(self):
runtime_classpath.add_for_targets([target], [('default', pre_init_runtime_entry)])

task = self.create_task(context)
resulting_classpath = task.create_runtime_classpath()
resulting_classpath = task.create_classpath_product()
self.assertEqual([('default', pre_init_runtime_entry), ('default', compile_entry)],
resulting_classpath.get_for_target(target))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def execute_export(self, *specs, **options_overrides):
for_task_types=[BootstrapJvmTools])

runtime_classpath = self.create_runtime_classpath_for_targets(self.scala_with_source_dep)
context.products.safe_create_data('runtime_classpath',
context.products.safe_create_data('export_dep_as_jar_classpath',
init_func=lambda: runtime_classpath)

bootstrap_task = BootstrapJvmTools(context, self.pants_workdir)
Expand Down