forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rsc_compile_integration.py
94 lines (80 loc) · 3.57 KB
/
test_rsc_compile_integration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# coding=utf-8
# Copyright 2018 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import absolute_import, division, print_function, unicode_literals
import os
from functools import wraps
from pants.backend.jvm.subsystems.resolve_subsystem import JvmResolveSubsystem
from pants.backend.jvm.tasks.jvm_compile.rsc.rsc_compile import RscCompile
from pants.util.contextutil import temporary_dir
from pants_test.backend.jvm.tasks.jvm_compile.base_compile_integration_test import BaseCompileIT
def _for_all_supported_execution_environments(func):
@wraps(func)
def wrapper_self(*args, **kwargs):
for worker_count in [1, 2]:
for resolver in JvmResolveSubsystem.CHOICES:
for execution_strategy in RscCompile.ExecutionStrategy.all_variants:
with temporary_dir() as cache_dir:
config = {
'cache.compile.rsc': {'write_to': [cache_dir]},
'jvm-platform': {'compiler': 'rsc'},
'compile.rsc': {
'execution_strategy': execution_strategy.value,
'worker_count': worker_count,
},
'resolver': {
'resolver': resolver,
}
}
def populate_necessary_hermetic_options():
config['compile.rsc'].update({
'incremental': False,
'use_classpath_jars': False,
})
if resolver == 'ivy':
resolver_scope = 'resolve.ivy'
else:
assert resolver == 'coursier'
resolver_scope = 'resolve.coursier'
config[resolver_scope] = {
'capture_snapshots': True,
}
execution_strategy.resolve_for_enum_variant({
'nailgun': lambda: None,
'subprocess': lambda: None,
'hermetic': populate_necessary_hermetic_options,
})()
func(*args, config=config, **kwargs)
return wrapper_self
class RscCompileIntegration(BaseCompileIT):
@_for_all_supported_execution_environments
def test_basic_binary(self, config):
with self.do_command_yielding_workdir(
'compile', 'testprojects/src/scala/org/pantsbuild/testproject/mutual:bin',
config=config) as pants_run:
zinc_compiled_classfile = os.path.join(
pants_run.workdir,
'compile/rsc/current/testprojects.src.scala.org.pantsbuild.testproject.mutual.mutual/current/zinc',
'classes/org/pantsbuild/testproject/mutual/A.class')
self.assertIsFile(zinc_compiled_classfile)
rsc_header_jar = os.path.join(
pants_run.workdir,
'compile/rsc/current/testprojects.src.scala.org.pantsbuild.testproject.mutual.mutual/current/rsc',
'm.jar')
self.assertIsFile(rsc_header_jar)
@_for_all_supported_execution_environments
def test_executing_multi_target_binary(self, config):
pants_run = self.do_command(
'run', 'examples/src/scala/org/pantsbuild/example/hello/exe',
config=config)
self.assertIn('Hello, Resource World!', pants_run.stdout_data)
@_for_all_supported_execution_environments
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)