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

[rsc-compile] extract helper methods for tests #7294

Merged
merged 3 commits into from Mar 5, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -41,55 +41,34 @@ def task_type(cls):
return RscCompile

def test_no_dependencies_between_scala_and_java_targets(self):
# Init dependencies for scala library targets.
init_subsystem(
ScalaPlatform,
{ScalaPlatform.options_scope: {
'version': 'custom',
'suffix_version': '2.12',
}}
)
self.make_target(
'//:scala-library',
target_type=JarLibrary,
jars=[JarDependency(org='com.example', name='scala', rev='0.0.0')]
)
self.init_dependencies_for_scala_libraries()

java_target = self.make_target(
'java/classpath:java_lib',
target_type=JavaLibrary,
sources=['com/example/Foo.java'],
dependencies=[]
)

scala_target = self.make_target(
'scala/classpath:scala_lib',
target_type=ScalaLibrary,
sources=['com/example/Foo.scala'],
dependencies=[]
)

context = self.context(target_roots=[java_target])

context.products.get_data('compile_classpath', ClasspathProducts.init_func(self.pants_workdir))
context.products.get_data('runtime_classpath', ClasspathProducts.init_func(self.pants_workdir))

task = self.create_task(context)
# tried for options, but couldn't get it to reconfig
task._size_estimator = lambda srcs: 0
with temporary_dir() as tmp_dir:
compile_contexts = {target: task.create_compile_context(target, os.path.join(tmp_dir, target.id))
for target in [java_target, scala_target]}

invalid_targets = [java_target, scala_target]
task = self.create_task_with_target_roots(
target_roots=[java_target]
)

jobs = task._create_compile_jobs(
compile_contexts=self.create_compile_contexts([java_target, scala_target], task, tmp_dir),
invalid_targets=invalid_targets,
invalid_vts=self.wrap_in_vts(invalid_targets),
classpath_product=None)

jobs = task._create_compile_jobs(compile_contexts,
invalid_targets,
invalid_vts=[LightWeightVTS(t) for t in invalid_targets],
classpath_product=None)

exec_graph = ExecutionGraph(jobs, task.get_options().print_exception_stacktrace)
dependee_graph = exec_graph.format_dependee_graph()
dependee_graph = self.construct_dependee_graph_str(jobs, task)
print(dependee_graph)
self.assertEqual(dedent("""
zinc(java/classpath:java_lib) -> {}
@@ -100,19 +79,7 @@ def test_no_dependencies_between_scala_and_java_targets(self):
dependee_graph)

def test_scala_dep_for_scala_and_java_targets(self):
# Init dependencies for scala library targets.
init_subsystem(
ScalaPlatform,
{ScalaPlatform.options_scope: {
'version': 'custom',
'suffix_version': '2.12',
}}
)
self.make_target(
'//:scala-library',
target_type=JarLibrary,
jars=[JarDependency(org='com.example', name='scala', rev='0.0.0')]
)
self.init_dependencies_for_scala_libraries()

scala_dep = self.make_target(
'scala/classpath:scala_dep',
@@ -125,36 +92,27 @@ def test_scala_dep_for_scala_and_java_targets(self):
sources=['com/example/Foo.java'],
dependencies=[scala_dep]
)

scala_target = self.make_target(
'scala/classpath:scala_lib',
target_type=ScalaLibrary,
sources=['com/example/Foo.scala'],
dependencies=[scala_dep]
)

context = self.context(target_roots=[scala_target, java_target])

context.products.get_data('compile_classpath', ClasspathProducts.init_func(self.pants_workdir))
context.products.get_data('runtime_classpath', ClasspathProducts.init_func(self.pants_workdir))

task = self.create_task(context)
# tried for options, but couldn't get it to reconfig
task._size_estimator = lambda srcs: 0
with temporary_dir() as tmp_dir:
compile_contexts = {target: task.create_compile_context(target, os.path.join(tmp_dir, target.id))
for target in [java_target, scala_target, scala_dep]}

invalid_targets = [java_target, scala_target, scala_dep]

jobs = task._create_compile_jobs(compile_contexts,
invalid_targets,
invalid_vts=[LightWeightVTS(t) for t in invalid_targets],
task = self.create_task_with_target_roots(
target_roots=[java_target, scala_target]
)

jobs = task._create_compile_jobs(
compile_contexts=self.create_compile_contexts(invalid_targets, task, tmp_dir),
invalid_targets=invalid_targets,
invalid_vts=self.wrap_in_vts(invalid_targets),
classpath_product=None)

exec_graph = ExecutionGraph(jobs, task.get_options().print_exception_stacktrace)
dependee_graph = exec_graph.format_dependee_graph()
print(dependee_graph)
dependee_graph = self.construct_dependee_graph_str(jobs, task)

self.assertEqual(dedent("""
zinc(java/classpath:java_lib) -> {}
rsc(scala/classpath:scala_lib) -> {
@@ -172,27 +130,14 @@ def test_scala_dep_for_scala_and_java_targets(self):
dependee_graph)

def test_scala_lib_with_java_sources_not_passed_to_rsc(self):
# Init dependencies for scala library targets.
init_subsystem(
ScalaPlatform,
{ScalaPlatform.options_scope: {
'version': 'custom',
'suffix_version': '2.12',
}}
)
self.make_target(
'//:scala-library',
target_type=JarLibrary,
jars=[JarDependency(org='com.example', name='scala', rev='0.0.0')]
)
self.init_dependencies_for_scala_libraries()

java_target = self.make_target(
'java/classpath:java_lib',
target_type=JavaLibrary,
sources=['com/example/Foo.java'],
dependencies=[]
)

scala_target_direct_java_sources = self.make_target(
'scala/classpath:scala_with_direct_java_sources',
target_type=ScalaLibrary,
@@ -207,35 +152,35 @@ def test_scala_lib_with_java_sources_not_passed_to_rsc(self):
dependencies=[]
)

context = self.context(
target_roots=[scala_target_direct_java_sources, scala_target_indirect_java_sources])

context.products.get_data('compile_classpath', ClasspathProducts.init_func(self.pants_workdir))
context.products.get_data('runtime_classpath', ClasspathProducts.init_func(self.pants_workdir))

task = self.create_task(context)
# tried for options, but couldn't get it to reconfig
task._size_estimator = lambda srcs: 0
with temporary_dir() as tmp_dir:
invalid_targets = [java_target, scala_target_direct_java_sources, scala_target_indirect_java_sources]
compile_contexts = {target: task.create_compile_context(target, os.path.join(tmp_dir, target.id))
for target in invalid_targets}

jobs = task._create_compile_jobs(compile_contexts,
invalid_targets,
invalid_targets = [
java_target,
scala_target_direct_java_sources,
scala_target_indirect_java_sources]
task = self.create_task_with_target_roots(
target_roots=[scala_target_indirect_java_sources, scala_target_direct_java_sources]
)

jobs = task._create_compile_jobs(
compile_contexts=self.create_compile_contexts(invalid_targets, task, tmp_dir),
invalid_targets=invalid_targets,
invalid_vts=[LightWeightVTS(t) for t in invalid_targets],
classpath_product=None)

exec_graph = ExecutionGraph(jobs, task.get_options().print_exception_stacktrace)
dependee_graph = exec_graph.format_dependee_graph()
print(dependee_graph)
dependee_graph = self.construct_dependee_graph_str(jobs, task)

self.assertEqual(dedent("""
zinc(java/classpath:java_lib) -> {}
zinc(scala/classpath:scala_with_direct_java_sources) -> {}
zinc(scala/classpath:scala_with_indirect_java_sources) -> {}""").strip(),
dependee_graph)

def construct_dependee_graph_str(self, jobs, task):
exec_graph = ExecutionGraph(jobs, task.get_options().print_exception_stacktrace)
dependee_graph = exec_graph.format_dependee_graph()
print(dependee_graph)
return dependee_graph

def test_desandbox_fn(self):
# TODO remove this after https://github.com/scalameta/scalameta/issues/1791 is released
desandbox = _create_desandboxify_fn(['.pants.d/cool/beans.*', '.pants.d/c/r/c/.*'])
@@ -253,3 +198,38 @@ def test_desandbox_fn(self):
self.assertEqual(desandbox('/some/path/.pants.d/tmp.pants.d/cool/beans'), '.pants.d/tmp.pants.d/cool/beans')
self.assertEqual(desandbox('/some/path/.pants.d/exec-location/.pants.d/tmp.pants.d/cool/beans'),
'.pants.d/tmp.pants.d/cool/beans')

def wrap_in_vts(self, invalid_targets):
return [LightWeightVTS(t) for t in invalid_targets]

def init_dependencies_for_scala_libraries(self):
init_subsystem(
ScalaPlatform,
{
ScalaPlatform.options_scope: {
'version': 'custom',
'suffix_version': '2.12',
}
}
)
self.make_target(
'//:scala-library',
target_type=JarLibrary,
jars=[JarDependency(org='com.example', name='scala', rev='0.0.0')]
)

def create_task_with_target_roots(self, target_roots):
context = self.context(target_roots=target_roots)
self.init_products(context)
task = self.create_task(context)
# tried for options, but couldn't get it to reconfig

This comment has been minimized.

Copy link
@cosmicexplorer

cosmicexplorer Feb 28, 2019

Contributor

Is this referring to not being able to set the size estimator using a task option?

This comment has been minimized.

Copy link
@baroquebobcat

baroquebobcat Feb 28, 2019

Author Contributor

yes.

task._size_estimator = lambda srcs: 0
return task

def init_products(self, context):
context.products.get_data('compile_classpath', ClasspathProducts.init_func(self.pants_workdir))
context.products.get_data('runtime_classpath', ClasspathProducts.init_func(self.pants_workdir))

def create_compile_contexts(self, invalid_targets, task, tmp_dir):
return {target: task.create_compile_context(target, os.path.join(tmp_dir, target.id))
for target in invalid_targets}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.