forked from facebook/buck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DEFS
233 lines (210 loc) · 7.5 KB
/
DEFS
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# This is a quick hack to make it so that all Java rules build using Java 7.
# TODO(bolinfest): Find a less hacky way to do this, likely something in .buckconfig.
original_java_library = java_library
def java_library(
name,
**kwargs
):
original_java_library(
name,
**kwargs
)
def java_immutables_library(
name,
# These must be relative to the package implied by the path to the BUCK file.
immutable_types=None,
**kwargs
):
if not immutable_types:
build_target = '//%s:%s' % (get_base_path(), name)
raise Exception(('%s is a java_immutables_library(), ' +
'but does not specify any immutable_types.') % build_target)
generated_symbols = map(fully_qualified_name_for_immutable_type, immutable_types)
all_generated_symbols = generated_symbols + kwargs.get('generated_symbols', [])
deps = kwargs.get('deps', [])
needed_deps = [
'//src/com/facebook/buck/util/immutables:immutables',
'//third-party/java/immutables:processor',
'//third-party/java/guava:guava',
'//third-party/java/jsr:jsr305',
]
for dep in needed_deps:
if not dep in deps:
deps.append(dep)
exported_deps = kwargs.get('exported_deps', [])
needed_exported_deps = [
'//third-party/java/immutables:processor',
]
for dep in needed_exported_deps:
if not dep in exported_deps:
exported_deps.append(dep)
annotation_processors = kwargs.get('annotation_processors', [])
if not 'org.immutables.value.internal.$processor$.$Processor' in annotation_processors:
annotation_processors.append('org.immutables.value.internal.$processor$.$Processor')
annotation_processor_deps = kwargs.get('annotation_processor_deps', [])
if not '//third-party/java/immutables:processor' in annotation_processor_deps:
annotation_processor_deps.append('//third-party/java/immutables:processor')
keys_to_remove = [
'annotation_processors',
'annotation_processor_deps',
'deps',
'exported_deps',
'generated_symbols',
]
args = {}
for k in kwargs:
if not k in keys_to_remove:
args[k] = kwargs[k]
return java_library(
name,
generated_symbols=all_generated_symbols,
deps=deps,
annotation_processors=annotation_processors,
annotation_processor_deps=annotation_processor_deps,
exported_deps=exported_deps,
**args)
def fully_qualified_name_for_immutable_type(immutable_type):
base_path = get_base_path()
# Strip off src/ or test/ prefix, as appropriate, from base_path.
if base_path.startswith('src/'):
base_path = base_path[len('src/'):]
elif base_path.startswith('test/'):
base_path = base_path[len('test/'):]
else:
raise Exception(src + ' must start with src/ or test/')
package_name = base_path.replace('/', '.')
return package_name + '.' + immutable_type
original_java_test = java_test
def java_test(
name,
deps=[],
vm_args=[],
**kwargs
):
original_java_test(
name,
deps=deps + [
# When actually running Buck, the launcher script loads the bootstrapper,
# and the bootstrapper loads the rest of Buck. For unit tests, which don't
# run Buck, we have to add a direct dependency on the bootstrapper in case
# they exercise code that uses it.
'//src/com/facebook/buck/cli/bootstrapper:bootstrapper_lib',
],
vm_args=[
# Add -XX:-UseSplitVerifier by default to work around:
# http://arihantwin.blogspot.com/2012/08/getting-error-illegal-local-variable.html
'-XX:-UseSplitVerifier',
# Don't use the system-installed JNA; extract it from the local jar.
'-Djna.nosys=true',
# Add -Dsun.zip.disableMemoryMapping=true to work around a JDK issue
# related to modifying JAR/ZIP files that have been loaded into memory:
#
# http://bugs.sun.com/view_bug.do?bug_id=7129299
#
# This has been observed to cause a problem in integration tests such as
# CachedTestIntegrationTest where `buck build //:test` is run repeatedly
# such that a corresponding `test.jar` file is overwritten several times.
# The CompiledClassFileFinder in JavaTestRule creates a java.util.zip.ZipFile
# to enumerate the zip entries in order to find the set of .class files
# in `test.jar`. This interleaving of reads and writes appears to match
# the conditions to trigger the issue reported on bugs.sun.com.
#
# Currently, we do not set this flag in bin/buck_common, as Buck does not
# normally modify the contents of buck-out after they are loaded into
# memory. However, we may need to use this flag when running buckd where
# references to zip files may be long-lived.
#
# Finally, note that when you specify this flag,
# `System.getProperty("sun.zip.disableMemoryMapping")` will return `null`
# even though you have specified the flag correctly. Apparently sun.misc.VM
# (http://www.docjar.com/html/api/sun/misc/VM.java.html) saves the property
# internally, but removes it from the set of system properties that are
# publicly accessible.
'-Dsun.zip.disableMemoryMapping=true',
] + vm_args,
**kwargs
)
def _get_name():
base_path = get_base_path()
with allow_unsafe_import():
import os.path
return os.path.basename(base_path)
def standard_java_library(
srcs = None,
immutable_types = None,
tests = None,
resources = None,
provided_deps = None,
visibility = None,
):
'''By default, generates a java_library() with the following args:
java_library(
name = <DIRECTORY_NAME>,
srcs = glob(['*.java']),
autodeps = True,
visibility = [
'PUBLIC',
],
)
Some of these fields can be overridden.
'''
if srcs is None:
srcs = glob(['*.java'])
if tests is None:
tests = []
if resources is None:
resources = []
if provided_deps is None:
provided_deps = []
if visibility is None:
visibility = [ 'PUBLIC' ]
kwargs = {}
if immutable_types:
build_rule = java_immutables_library
kwargs['immutable_types'] = immutable_types
else:
build_rule = java_library
build_rule(
name = _get_name(),
srcs = srcs,
resources = resources,
tests = tests,
autodeps = True,
provided_deps = provided_deps,
visibility = visibility,
**kwargs
)
def standard_java_test(run_test_separately = False, vm_args = None, fork_mode = 'none'):
if vm_args is None:
vm_args = ['-Xmx256M']
srcs = glob(['*.java'])
test_srcs = []
testutil_srcs = []
for src in srcs:
if src.endswith('Test.java'):
test_srcs.append(src)
else:
testutil_srcs.append(src)
if len(testutil_srcs) > 0:
java_library(
name = 'testutil',
srcs = testutil_srcs,
autodeps = True,
visibility = [
'//test/...',
]
)
if len(test_srcs) > 0:
name = _get_name()
if name == 'testutil':
# Having a com.facebook.buck.testutil package was probably a bad choice.
name = 'testutil_test'
java_test(
name = name,
srcs = test_srcs,
autodeps = True,
resources = glob(['testdata/**'], include_dotfiles=True),
vm_args = vm_args,
run_test_separately = run_test_separately,
fork_mode = fork_mode,
)