forked from pantsbuild/pants
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jvm-compile] Copy compile classpath into runtime classpath even if a…
…lready defined In pantsbuild#4309, the problem was caused by jvm_compile assuming it is always first in the compile order. This ensures the compile_classpath is mixed into the runtime classpath even if it has already been initialized. Another approach would be to move the NodeBuild task to later in the compile goal, and make it an error for jvm_compile to receive a runtime classpath.
- Loading branch information
1 parent
8bf2850
commit 421b759
Showing
4 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/python/pants_test/backend/jvm/tasks/jvm_compile/test_jvm_compile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# coding=utf-8 | ||
# Copyright 2017 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
import os | ||
|
||
from pants.backend.jvm.targets.java_library import JavaLibrary | ||
from pants.backend.jvm.tasks.classpath_products import ClasspathProducts | ||
from pants.backend.jvm.tasks.jvm_compile.jvm_compile import JvmCompile | ||
from pants_test.tasks.task_test_base import TaskTestBase | ||
|
||
|
||
class DummyJvmCompile(JvmCompile): | ||
|
||
def create_analysis_tools(self): | ||
return None | ||
|
||
|
||
class JvmCompileTest(TaskTestBase): | ||
DEFAULT_CONF = 'default' | ||
|
||
@classmethod | ||
def task_type(cls): | ||
return DummyJvmCompile | ||
|
||
def test_if_runtime_classpath_exists(self): | ||
target = self.make_target( | ||
'java/classpath:java_lib', | ||
target_type=JavaLibrary, | ||
sources=['com/foo/Bar.java'], | ||
) | ||
|
||
context = self.context(target_roots=[target]) | ||
compile_classpath = context.products.get_data('compile_classpath', ClasspathProducts.init_func(self.pants_workdir)) | ||
|
||
compile_entry = os.path.join(self.pants_workdir, 'compile-entry') | ||
pre_init_runtime_entry = os.path.join(self.pants_workdir, 'pre-inited-runtime-entry') | ||
compile_classpath.add_for_targets([target], [('default', compile_entry)]) | ||
runtime_classpath = context.products.get_data('runtime_classpath', ClasspathProducts.init_func(self.pants_workdir)) | ||
|
||
runtime_classpath.add_for_targets([target], [('default', pre_init_runtime_entry)]) | ||
|
||
task = self.create_task(context) | ||
resulting_classpath = task.create_runtime_classpath() | ||
self.assertEqual([('default', pre_init_runtime_entry), ('default', compile_entry)], | ||
resulting_classpath.get_for_target(target)) |
421b759
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.