JavaLibrary.mk revision 757a7942eed2b0aa457f8517a0259d2ac82c5b18
1# -*- mode: makefile -*-
2# Copyright (C) 2007 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16#
17# Definitions for building the Java library and associated tests.
18#
19
20#
21# Common definitions for host and target.
22#
23
24# dalvik/libcore is divided into modules.
25#
26# The structure of each module is:
27#
28#   src/
29#       main/               # To be shipped on every device.
30#            java/          # Java source for library code.
31#            native/        # C++ source for library code.
32#            resources/     # Support files.
33#       test/               # Built only on demand, for testing.
34#            java/          # Java source for tests.
35#            native/        # C++ source for tests (rare).
36#            resources/     # Support files.
37#
38# All subdirectories are optional (hence the "2> /dev/null"s below).
39
40define all-main-java-files-under
41$(foreach dir,$(1),$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(dir)/src/main/java -name "*.java" 2> /dev/null)))
42endef
43
44define all-test-java-files-under
45$(patsubst ./%,%,$(shell cd $(LOCAL_PATH) && find $(1)/src/test/java -name "*.java" 2> /dev/null))
46endef
47
48define all-core-resource-dirs
49$(shell cd $(LOCAL_PATH) && ls -d */src/$(1)/{java,resources} 2> /dev/null)
50endef
51
52# The Java files and their associated resources.
53core_src_files := $(call all-main-java-files-under,annotation archive auth awt-kernel concurrent crypto dalvik dom icu json junit logging luni luni-kernel math nio nio_char openssl prefs regex security security-kernel sql suncompat support text x-net xml)
54core_resource_dirs := $(call all-core-resource-dirs,main)
55test_resource_dirs := $(call all-core-resource-dirs,test)
56
57
58#
59# Build for the target (device).
60#
61
62# Definitions to make the core library.
63
64include $(CLEAR_VARS)
65
66LOCAL_SRC_FILES := $(core_src_files)
67LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
68
69LOCAL_NO_STANDARD_LIBRARIES := true
70LOCAL_DX_FLAGS := --core-library
71
72LOCAL_NO_EMMA_INSTRUMENT := true
73LOCAL_NO_EMMA_COMPILE := true
74
75LOCAL_MODULE := core
76
77include $(BUILD_JAVA_LIBRARY)
78
79core-intermediates := ${intermediates}
80
81
82
83# Definitions to make the sqlite JDBC driver.
84
85include $(CLEAR_VARS)
86LOCAL_SRC_FILES := $(call all-main-java-files-under,sqlite-jdbc)
87LOCAL_NO_STANDARD_LIBRARIES := true
88LOCAL_JAVA_LIBRARIES := core
89LOCAL_MODULE := sqlite-jdbc
90include $(BUILD_JAVA_LIBRARY)
91
92
93# Definitions to make the core-tests libraries.
94#
95# We make a library per module, because otherwise the .jar files get too
96# large, to the point that dx(1) can't cope (and the build is
97# ridiculously slow).
98#
99# TODO: DalvikRunner will make this nonsense obsolete.
100
101include $(CLEAR_VARS)
102LOCAL_SRC_FILES := $(call all-test-java-files-under,annotation)
103LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
104LOCAL_NO_STANDARD_LIBRARIES := true
105LOCAL_JAVA_LIBRARIES := core core-tests-support
106LOCAL_DX_FLAGS := --core-library
107LOCAL_MODULE_TAGS := tests
108LOCAL_MODULE := core-tests-annotation
109include $(BUILD_JAVA_LIBRARY)
110
111include $(CLEAR_VARS)
112LOCAL_SRC_FILES := $(call all-test-java-files-under,archive)
113LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
114LOCAL_NO_STANDARD_LIBRARIES := true
115LOCAL_JAVA_LIBRARIES := core core-tests-support
116LOCAL_DX_FLAGS := --core-library
117LOCAL_MODULE_TAGS := tests
118LOCAL_MODULE := core-tests-archive
119include $(BUILD_JAVA_LIBRARY)
120
121include $(CLEAR_VARS)
122LOCAL_SRC_FILES := $(call all-test-java-files-under,concurrent)
123LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
124LOCAL_NO_STANDARD_LIBRARIES := true
125LOCAL_JAVA_LIBRARIES := core core-tests-support
126LOCAL_DX_FLAGS := --core-library
127LOCAL_MODULE_TAGS := tests
128LOCAL_MODULE := core-tests-concurrent
129include $(BUILD_JAVA_LIBRARY)
130
131include $(CLEAR_VARS)
132LOCAL_SRC_FILES := $(call all-test-java-files-under,crypto)
133LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
134LOCAL_NO_STANDARD_LIBRARIES := true
135LOCAL_JAVA_LIBRARIES := core core-tests-support
136LOCAL_DX_FLAGS := --core-library
137LOCAL_MODULE_TAGS := tests
138LOCAL_MODULE := core-tests-crypto
139include $(BUILD_JAVA_LIBRARY)
140
141include $(CLEAR_VARS)
142LOCAL_SRC_FILES := $(call all-test-java-files-under,dom)
143LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
144LOCAL_NO_STANDARD_LIBRARIES := true
145LOCAL_JAVA_LIBRARIES := core core-tests-support
146LOCAL_DX_FLAGS := --core-library
147LOCAL_MODULE_TAGS := tests
148LOCAL_MODULE := core-tests-dom
149include $(BUILD_JAVA_LIBRARY)
150
151include $(CLEAR_VARS)
152LOCAL_SRC_FILES := $(call all-test-java-files-under,json)
153LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
154LOCAL_NO_STANDARD_LIBRARIES := true
155LOCAL_JAVA_LIBRARIES := core core-tests-support
156LOCAL_DX_FLAGS := --core-library
157LOCAL_MODULE_TAGS := tests
158LOCAL_MODULE := core-tests-json
159include $(BUILD_JAVA_LIBRARY)
160
161include $(CLEAR_VARS)
162LOCAL_SRC_FILES := $(call all-test-java-files-under,logging)
163LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
164LOCAL_NO_STANDARD_LIBRARIES := true
165LOCAL_JAVA_LIBRARIES := core core-tests-support
166LOCAL_DX_FLAGS := --core-library
167LOCAL_MODULE_TAGS := tests
168LOCAL_MODULE := core-tests-logging
169include $(BUILD_JAVA_LIBRARY)
170
171include $(CLEAR_VARS)
172LOCAL_SRC_FILES := $(call all-test-java-files-under,luni-kernel)
173LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
174LOCAL_NO_STANDARD_LIBRARIES := true
175LOCAL_JAVA_LIBRARIES := core core-tests-support
176LOCAL_DX_FLAGS := --core-library
177LOCAL_MODULE_TAGS := tests
178LOCAL_MODULE := core-tests-luni-kernel
179include $(BUILD_JAVA_LIBRARY)
180
181include $(CLEAR_VARS)
182LOCAL_SRC_FILES := $(call all-test-java-files-under,luni)
183LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
184LOCAL_NO_STANDARD_LIBRARIES := true
185# This module contains the top-level "tests.AllTests" that ties everything
186# together, so it has compile-time dependencies on all the other test
187# libraries.
188# TODO: we should have a bogus module that just contains tests.AllTests for speed.
189LOCAL_JAVA_LIBRARIES := \
190        core \
191        core-tests-support \
192        core-tests-annotation \
193        core-tests-archive \
194        core-tests-concurrent \
195        core-tests-crypto \
196        core-tests-dom \
197        core-tests-json \
198        core-tests-logging \
199        core-tests-luni-kernel \
200        core-tests-math \
201        core-tests-nio \
202        core-tests-nio_char \
203        core-tests-prefs \
204        core-tests-regex \
205        core-tests-security \
206        core-tests-sql \
207        core-tests-suncompat \
208        core-tests-text \
209        core-tests-x-net \
210        core-tests-xml
211LOCAL_DX_FLAGS := --core-library
212LOCAL_MODULE_TAGS := tests
213LOCAL_MODULE := core-tests-luni
214include $(BUILD_JAVA_LIBRARY)
215
216include $(CLEAR_VARS)
217LOCAL_SRC_FILES := $(call all-test-java-files-under,math)
218LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
219LOCAL_NO_STANDARD_LIBRARIES := true
220LOCAL_JAVA_LIBRARIES := core core-tests-support
221LOCAL_DX_FLAGS := --core-library
222LOCAL_MODULE_TAGS := tests
223LOCAL_MODULE := core-tests-math
224include $(BUILD_JAVA_LIBRARY)
225
226include $(CLEAR_VARS)
227LOCAL_SRC_FILES := $(call all-test-java-files-under,nio)
228LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
229LOCAL_NO_STANDARD_LIBRARIES := true
230LOCAL_JAVA_LIBRARIES := core core-tests-support
231LOCAL_DX_FLAGS := --core-library
232LOCAL_MODULE_TAGS := tests
233LOCAL_MODULE := core-tests-nio
234include $(BUILD_JAVA_LIBRARY)
235
236include $(CLEAR_VARS)
237LOCAL_SRC_FILES := $(call all-test-java-files-under,nio_char)
238LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
239LOCAL_NO_STANDARD_LIBRARIES := true
240LOCAL_JAVA_LIBRARIES := core core-tests-support
241LOCAL_DX_FLAGS := --core-library
242LOCAL_MODULE_TAGS := tests
243LOCAL_MODULE := core-tests-nio_char
244include $(BUILD_JAVA_LIBRARY)
245
246include $(CLEAR_VARS)
247LOCAL_SRC_FILES := $(call all-test-java-files-under,prefs)
248LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
249LOCAL_NO_STANDARD_LIBRARIES := true
250LOCAL_JAVA_LIBRARIES := core core-tests-support
251LOCAL_DX_FLAGS := --core-library
252LOCAL_MODULE_TAGS := tests
253LOCAL_MODULE := core-tests-prefs
254include $(BUILD_JAVA_LIBRARY)
255
256include $(CLEAR_VARS)
257LOCAL_SRC_FILES := $(call all-test-java-files-under,regex)
258LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
259LOCAL_NO_STANDARD_LIBRARIES := true
260LOCAL_JAVA_LIBRARIES := core core-tests-support
261LOCAL_DX_FLAGS := --core-library
262LOCAL_MODULE_TAGS := tests
263LOCAL_MODULE := core-tests-regex
264include $(BUILD_JAVA_LIBRARY)
265
266include $(CLEAR_VARS)
267LOCAL_SRC_FILES := $(call all-test-java-files-under,security)
268LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
269LOCAL_NO_STANDARD_LIBRARIES := true
270LOCAL_JAVA_LIBRARIES := core core-tests-support
271LOCAL_DX_FLAGS := --core-library
272LOCAL_MODULE_TAGS := tests
273LOCAL_MODULE := core-tests-security
274include $(BUILD_JAVA_LIBRARY)
275
276include $(CLEAR_VARS)
277LOCAL_SRC_FILES := $(call all-test-java-files-under,sql)
278LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
279LOCAL_NO_STANDARD_LIBRARIES := true
280LOCAL_JAVA_LIBRARIES := core core-tests-support sqlite-jdbc
281LOCAL_DX_FLAGS := --core-library
282LOCAL_MODULE_TAGS := tests
283LOCAL_MODULE := core-tests-sql
284include $(BUILD_JAVA_LIBRARY)
285
286include $(CLEAR_VARS)
287LOCAL_SRC_FILES := $(call all-test-java-files-under,suncompat)
288LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
289LOCAL_NO_STANDARD_LIBRARIES := true
290LOCAL_JAVA_LIBRARIES := core core-tests-support
291LOCAL_DX_FLAGS := --core-library
292LOCAL_MODULE_TAGS := tests
293LOCAL_MODULE := core-tests-suncompat
294include $(BUILD_JAVA_LIBRARY)
295
296include $(CLEAR_VARS)
297LOCAL_SRC_FILES := $(call all-test-java-files-under,support)
298LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
299LOCAL_NO_STANDARD_LIBRARIES := true
300LOCAL_JAVA_LIBRARIES := core
301LOCAL_DX_FLAGS := --core-library
302LOCAL_MODULE_TAGS := tests
303LOCAL_MODULE := core-tests-support
304include $(BUILD_JAVA_LIBRARY)
305
306include $(CLEAR_VARS)
307LOCAL_SRC_FILES := $(call all-test-java-files-under,text)
308LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
309LOCAL_NO_STANDARD_LIBRARIES := true
310LOCAL_JAVA_LIBRARIES := core core-tests-support
311LOCAL_DX_FLAGS := --core-library
312LOCAL_MODULE_TAGS := tests
313LOCAL_MODULE := core-tests-text
314include $(BUILD_JAVA_LIBRARY)
315
316include $(CLEAR_VARS)
317LOCAL_SRC_FILES := $(call all-test-java-files-under,x-net)
318LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
319LOCAL_NO_STANDARD_LIBRARIES := true
320LOCAL_JAVA_LIBRARIES := core core-tests-support
321LOCAL_DX_FLAGS := --core-library
322LOCAL_MODULE_TAGS := tests
323LOCAL_MODULE := core-tests-x-net
324include $(BUILD_JAVA_LIBRARY)
325
326include $(CLEAR_VARS)
327LOCAL_SRC_FILES := $(call all-test-java-files-under,xml)
328LOCAL_JAVA_RESOURCE_DIRS := $(test_resource_dirs)
329LOCAL_NO_STANDARD_LIBRARIES := true
330LOCAL_JAVA_LIBRARIES := core core-tests-support
331LOCAL_DX_FLAGS := --core-library
332LOCAL_MODULE_TAGS := tests
333LOCAL_MODULE := core-tests-xml
334include $(BUILD_JAVA_LIBRARY)
335
336
337
338
339# This one's tricky. One of our tests needs to have a
340# resource with a "#" in its name, but Perforce doesn't
341# allow us to submit such a file. So we create it here
342# on-the-fly.
343TMP_RESOURCE_DIR := $(OUT_DIR)/tmp/
344TMP_RESOURCE_FILE := org/apache/harmony/luni/tests/java/lang/test\#.properties
345
346$(TMP_RESOURCE_DIR)$(TMP_RESOURCE_FILE):
347	@mkdir -p $(dir $@)
348	@echo "Hello, world!" > $@
349
350$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_EXTRA_JAR_ARGS := $(extra_jar_args) -C $(TMP_RESOURCE_DIR) $(TMP_RESOURCE_FILE)
351$(LOCAL_INTERMEDIATE_TARGETS): $(TMP_RESOURCE_DIR)$(TMP_RESOURCE_FILE)
352
353# Definitions for building a version of the core-tests.jar
354# that is suitable for execution on the RI. This JAR would
355# be better located in $HOST_OUT_JAVA_LIBRARIES, but it is
356# not possible to refer to that from a shell script (the
357# variable is not exported from envsetup.sh). There is also
358# some trickery involved: we need to include some classes
359# that reside in core.jar, but since we cannot incldue the
360# whole core.jar in the RI classpath, we copy those classses
361# over to our new file.
362HOST_CORE_JAR := $(HOST_COMMON_OUT_ROOT)/core-tests.jar
363
364$(HOST_CORE_JAR): PRIVATE_LOCAL_BUILT_MODULE := $(LOCAL_BUILT_MODULE)
365$(HOST_CORE_JAR): PRIVATE_CORE_INTERMEDIATES := $(core-intermediates)
366$(HOST_CORE_JAR): $(LOCAL_BUILT_MODULE)
367	@rm -rf $(dir $<)/hostctsclasses
368	$(call unzip-jar-files,$(dir $<)classes.jar,$(dir $<)hostctsclasses)
369	@unzip -qx -o $(PRIVATE_CORE_INTERMEDIATES)/classes.jar dalvik/annotation/* -d $(dir $<)hostctsclasses
370	@cp $< $@
371	@jar uf $@ -C $(dir $<)hostctsclasses .
372
373$(LOCAL_INSTALLED_MODULE): $(HOST_CORE_JAR)
374
375$(LOCAL_INSTALLED_MODULE): run-core-tests
376
377# Definitions to copy the core-tests runner script.
378
379include $(CLEAR_VARS)
380LOCAL_SRC_FILES := run-core-tests
381LOCAL_MODULE_CLASS := EXECUTABLES
382LOCAL_MODULE_TAGS := tests
383LOCAL_MODULE := run-core-tests
384include $(BUILD_PREBUILT)
385
386include $(CLEAR_VARS)
387LOCAL_SRC_FILES := run-core-tests-on-ri
388LOCAL_IS_HOST_MODULE := true
389LOCAL_MODULE_CLASS := EXECUTABLES
390LOCAL_MODULE_TAGS := tests
391LOCAL_MODULE := run-core-tests-on-ri
392include $(BUILD_PREBUILT)
393
394
395#
396# Build for the host.
397#
398
399ifeq ($(WITH_HOST_DALVIK),true)
400
401    # Definitions to make the core library.
402
403    include $(CLEAR_VARS)
404
405    LOCAL_SRC_FILES := $(core_src_files)
406    LOCAL_JAVA_RESOURCE_DIRS := $(core_resource_dirs)
407
408    LOCAL_NO_STANDARD_LIBRARIES := true
409    LOCAL_DX_FLAGS := --core-library
410
411    LOCAL_NO_EMMA_INSTRUMENT := true
412    LOCAL_NO_EMMA_COMPILE := true
413
414    LOCAL_MODULE := core
415
416    include $(BUILD_HOST_JAVA_LIBRARY)
417
418endif
419