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

add java_sources to scala_library() snapshot #7840

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -394,6 +394,17 @@ def _compile_hermetic(self, jvm_options, ctx, classes_dir, jar_file, zinc_args,
ctx.target.sources_snapshot(self.context._scheduler),
]

# scala_library() targets with java_sources have circular dependencies on those java source
# files, and we provide them to the same zinc command line that compiles the scala, so we need
# to make sure those source files are available in the hermetic execution sandbox.
java_sources_targets = getattr(ctx.target, 'java_sources', [])
java_sources_snapshots = [
tgt.sources_snapshot(self.context._scheduler)
for tgt in java_sources_targets
]
snapshots.extend(java_sources_snapshots)

# Ensure the dependencies and compiler bridge jars are available in the execution sandbox.
relevant_classpath_entries = dependency_classpath + [compiler_bridge_classpath_entry]
directory_digests = tuple(
entry.directory_digest for entry in relevant_classpath_entries if entry.directory_digest
Expand All @@ -405,7 +416,6 @@ def _compile_hermetic(self, jvm_options, ctx, classes_dir, jar_file, zinc_args,
"ClasspathEntry {} didn't have a Digest, so won't be present for hermetic "
"execution".format(dep)
)

snapshots.extend(
classpath_entry.directory_digest for classpath_entry in scalac_classpath_entries
)
Expand All @@ -417,15 +427,15 @@ def _compile_hermetic(self, jvm_options, ctx, classes_dir, jar_file, zinc_args,
"unsupported. jvm_options received: {}".format(self.options_scope, safe_shlex_join(jvm_options))
)
native_image_path, native_image_snapshot = self._zinc.native_image(self.context)
additional_snapshots = (native_image_snapshot.directory_digest,)
native_image_snapshots = (native_image_snapshot.directory_digest,)
scala_boot_classpath = [
classpath_entry.path for classpath_entry in scalac_classpath_entries
] + [
# We include rt.jar on the scala boot classpath because the compiler usually gets its
# contents from the VM it is executing in, but not in the case of a native image. This
# resolves a `object java.lang.Object in compiler mirror not found.` error.
'.jdk/jre/lib/rt.jar',
# The same goes for the rce.jar, which provides javax.crypto.
# The same goes for the jce.jar, which provides javax.crypto.
'.jdk/jre/lib/jce.jar',
]
image_specific_argv = [
Expand All @@ -437,7 +447,7 @@ def _compile_hermetic(self, jvm_options, ctx, classes_dir, jar_file, zinc_args,
else:
# TODO: Extract something common from Executor._create_command to make the command line
# TODO: Lean on distribution for the bin/java appending here
additional_snapshots = ()
native_image_snapshots = ()
image_specific_argv = ['.jdk/bin/java'] + jvm_options + [
'-cp', zinc_relpath,
Zinc.ZINC_COMPILE_MAIN
Expand All @@ -446,7 +456,7 @@ def _compile_hermetic(self, jvm_options, ctx, classes_dir, jar_file, zinc_args,
merged_input_digest = self.context._scheduler.merge_directories(
tuple(s.directory_digest for s in snapshots) +
directory_digests +
additional_snapshots +
native_image_snapshots +
(self.extra_resources_digest(ctx),)
)

Expand Down
Expand Up @@ -86,3 +86,9 @@ def test_java_with_transitive_exported_scala_dep(self, config):
self.do_command(
'compile', 'testprojects/src/scala/org/pantsbuild/testproject/javadepsonscalatransitive:java-in-different-package',
config=config)

@_for_all_supported_execution_environments
def test_java_sources(self, config):
self.do_command(
'compile', 'testprojects/src/scala/org/pantsbuild/testproject/javasources',
config=config)