1#
2# Copyright (C) 2011 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########################################################################
18# Rules to build a smaller "core" image to support core libraries
19# (that is, non-Android frameworks) testing on the host and target
20#
21# The main rules to build the default "boot" image are in
22# build/core/dex_preopt_libart.mk
23
24include art/build/Android.common_build.mk
25
26LOCAL_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES_OPTION :=
27ifeq ($(DEX2OAT_HOST_INSTRUCTION_SET_FEATURES),)
28  LOCAL_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES_OPTION := --instruction-set-features=default
29else
30  LOCAL_DEX2OAT_HOST_INSTRUCTION_SET_FEATURES_OPTION := --instruction-set-features=$(DEX2OAT_HOST_INSTRUCTION_SET_FEATURES)
31endif
32LOCAL_$(HOST_2ND_ARCH_VAR_PREFIX)DEX2OAT_HOST_INSTRUCTION_SET_FEATURES_OPTION :=
33ifeq ($($(HOST_2ND_ARCH_VAR_PREFIX)DEX2OAT_HOST_INSTRUCTION_SET_FEATURES),)
34  LOCAL_$(HOST_2ND_ARCH_VAR_PREFIX)DEX2OAT_HOST_INSTRUCTION_SET_FEATURES_OPTION := --instruction-set-features=default
35else
36  LOCAL_$(HOST_2ND_ARCH_VAR_PREFIX)DEX2OAT_HOST_INSTRUCTION_SET_FEATURES_OPTION := --instruction-set-features=$($(HOST_2ND_ARCH_VAR_PREFIX)DEX2OAT_HOST_INSTRUCTION_SET_FEATURES)
37endif
38
39# Use dex2oat debug version for better error reporting
40# $(1): compiler - default, optimizing, jit, interpreter or interpreter-access-checks.
41# $(2): pic/no-pic
42# $(3): 2ND_ or undefined, 2ND_ for 32-bit host builds.
43# $(4): wrapper, e.g., valgrind.
44# $(5): dex2oat suffix, e.g, valgrind requires 32 right now.
45# $(6): multi-image.
46# NB depending on HOST_CORE_DEX_LOCATIONS so we are sure to have the dex files in frameworks for
47# run-test --no-image
48define create-core-oat-host-rules
49  core_compile_options :=
50  core_image_name :=
51  core_oat_name :=
52  core_infix :=
53  core_pic_infix :=
54  core_dex2oat_dependency := $(DEX2OAT_DEPENDENCY)
55
56  ifeq ($(1),default)
57    core_compile_options += --compiler-backend=Quick
58  endif
59  ifeq ($(1),optimizing)
60    core_compile_options += --compiler-backend=Optimizing
61    core_dex2oat_dependency := $(DEX2OAT)
62    core_infix := -optimizing
63  endif
64  ifeq ($(1),interpreter)
65    core_compile_options += --compiler-filter=interpret-only
66    core_infix := -interpreter
67  endif
68  ifeq ($(1),interp-ac)
69    core_compile_options += --compiler-filter=verify-at-runtime --runtime-arg -Xverify:softfail
70    core_infix := -interp-ac
71  endif
72  ifeq ($(1),jit)
73    core_compile_options += --compiler-filter=verify-at-runtime
74    core_infix := -jit
75  endif
76  ifeq ($(1),default)
77    # Default has no infix, no compile options.
78  endif
79  ifneq ($(filter-out default interpreter interp-ac jit optimizing,$(1)),)
80    #Technically this test is not precise, but hopefully good enough.
81    $$(error found $(1) expected default, interpreter, interpreter-access-checks, jit or optimizing)
82  endif
83
84  ifeq ($(2),pic)
85    core_compile_options += --compile-pic
86    core_pic_infix := -pic
87  endif
88  ifeq ($(2),no-pic)
89    # No change for non-pic
90  endif
91  ifneq ($(filter-out pic no-pic,$(2)),)
92    # Technically this test is not precise, but hopefully good enough.
93    $$(error found $(2) expected pic or no-pic)
94  endif
95
96  # If $(6) is true, generate a multi-image.
97  ifeq ($(6),true)
98    core_multi_infix := -multi
99    core_multi_param := --multi-image --no-inline-from=core-oj-hostdex.jar
100    core_multi_group := _multi
101  else
102    core_multi_infix :=
103    core_multi_param :=
104    core_multi_group :=
105  endif
106
107  core_image_name := $($(3)HOST_CORE_IMG_OUT_BASE)$$(core_infix)$$(core_pic_infix)$$(core_multi_infix)$(4)$(CORE_IMG_SUFFIX)
108  core_oat_name := $($(3)HOST_CORE_OAT_OUT_BASE)$$(core_infix)$$(core_pic_infix)$$(core_multi_infix)$(4)$(CORE_OAT_SUFFIX)
109
110  # Using the bitness suffix makes it easier to add as a dependency for the run-test mk.
111  ifeq ($(3),)
112    $(4)HOST_CORE_IMAGE_$(1)_$(2)$$(core_multi_group)_64 := $$(core_image_name)
113  else
114    $(4)HOST_CORE_IMAGE_$(1)_$(2)$$(core_multi_group)_32 := $$(core_image_name)
115  endif
116  $(4)HOST_CORE_IMG_OUTS += $$(core_image_name)
117  $(4)HOST_CORE_OAT_OUTS += $$(core_oat_name)
118
119  # If we have a wrapper, make the target phony.
120  ifneq ($(4),)
121.PHONY: $$(core_image_name)
122  endif
123$$(core_image_name): PRIVATE_CORE_COMPILE_OPTIONS := $$(core_compile_options)
124$$(core_image_name): PRIVATE_CORE_IMG_NAME := $$(core_image_name)
125$$(core_image_name): PRIVATE_CORE_OAT_NAME := $$(core_oat_name)
126$$(core_image_name): PRIVATE_CORE_MULTI_PARAM := $$(core_multi_param)
127$$(core_image_name): $$(HOST_CORE_DEX_LOCATIONS) $$(core_dex2oat_dependency)
128	@echo "host dex2oat: $$@"
129	@mkdir -p $$(dir $$@)
130	$$(hide) $(4) $$(DEX2OAT)$(5) --runtime-arg -Xms$(DEX2OAT_IMAGE_XMS) \
131	  --runtime-arg -Xmx$(DEX2OAT_IMAGE_XMX) \
132	  --image-classes=$$(PRELOADED_CLASSES) $$(addprefix --dex-file=,$$(HOST_CORE_DEX_FILES)) \
133	  $$(addprefix --dex-location=,$$(HOST_CORE_DEX_LOCATIONS)) --oat-file=$$(PRIVATE_CORE_OAT_NAME) \
134	  --oat-location=$$(PRIVATE_CORE_OAT_NAME) --image=$$(PRIVATE_CORE_IMG_NAME) \
135	  --base=$$(LIBART_IMG_HOST_BASE_ADDRESS) --instruction-set=$$($(3)ART_HOST_ARCH) \
136	  $$(LOCAL_$(3)DEX2OAT_HOST_INSTRUCTION_SET_FEATURES_OPTION) \
137	  --host --android-root=$$(HOST_OUT) --include-patch-information --generate-debug-info \
138	  $$(PRIVATE_CORE_MULTI_PARAM) $$(PRIVATE_CORE_COMPILE_OPTIONS)
139
140$$(core_oat_name): $$(core_image_name)
141
142  # Clean up locally used variables.
143  core_dex2oat_dependency :=
144  core_compile_options :=
145  core_image_name :=
146  core_oat_name :=
147  core_infix :=
148  core_pic_infix :=
149endef  # create-core-oat-host-rules
150
151# $(1): compiler - default, optimizing, jit, interpreter or interpreter-access-checks.
152# $(2): wrapper.
153# $(3): dex2oat suffix.
154# $(4): multi-image.
155define create-core-oat-host-rule-combination
156  $(call create-core-oat-host-rules,$(1),no-pic,,$(2),$(3),$(4))
157  $(call create-core-oat-host-rules,$(1),pic,,$(2),$(3),$(4))
158
159  ifneq ($(HOST_PREFER_32_BIT),true)
160    $(call create-core-oat-host-rules,$(1),no-pic,2ND_,$(2),$(3),$(4))
161    $(call create-core-oat-host-rules,$(1),pic,2ND_,$(2),$(3),$(4))
162  endif
163endef
164
165$(eval $(call create-core-oat-host-rule-combination,default,,,false))
166$(eval $(call create-core-oat-host-rule-combination,optimizing,,,false))
167$(eval $(call create-core-oat-host-rule-combination,interpreter,,,false))
168$(eval $(call create-core-oat-host-rule-combination,interp-ac,,,false))
169$(eval $(call create-core-oat-host-rule-combination,jit,,,false))
170$(eval $(call create-core-oat-host-rule-combination,default,,,true))
171$(eval $(call create-core-oat-host-rule-combination,optimizing,,,true))
172$(eval $(call create-core-oat-host-rule-combination,interpreter,,,true))
173$(eval $(call create-core-oat-host-rule-combination,interp-ac,,,true))
174$(eval $(call create-core-oat-host-rule-combination,jit,,,true))
175
176valgrindHOST_CORE_IMG_OUTS :=
177valgrindHOST_CORE_OAT_OUTS :=
178$(eval $(call create-core-oat-host-rule-combination,default,valgrind,32,false))
179$(eval $(call create-core-oat-host-rule-combination,optimizing,valgrind,32,false))
180$(eval $(call create-core-oat-host-rule-combination,interpreter,valgrind,32,false))
181$(eval $(call create-core-oat-host-rule-combination,interp-ac,valgrind,32,false))
182$(eval $(call create-core-oat-host-rule-combination,jit,valgrind,32,false))
183
184valgrind-test-art-host-dex2oat-host: $(valgrindHOST_CORE_IMG_OUTS)
185
186test-art-host-dex2oat-host: $(HOST_CORE_IMG_OUTS)
187
188define create-core-oat-target-rules
189  core_compile_options :=
190  core_image_name :=
191  core_oat_name :=
192  core_infix :=
193  core_pic_infix :=
194  core_dex2oat_dependency := $(DEX2OAT_DEPENDENCY)
195
196  ifeq ($(1),default)
197    core_compile_options += --compiler-backend=Quick
198  endif
199  ifeq ($(1),optimizing)
200    core_compile_options += --compiler-backend=Optimizing
201    # With the optimizing compiler, we want to rerun dex2oat whenever there is
202    # a dex2oat change to catch regressions early.
203    core_dex2oat_dependency := $(DEX2OAT)
204    core_infix := -optimizing
205  endif
206  ifeq ($(1),interpreter)
207    core_compile_options += --compiler-filter=interpret-only
208    core_infix := -interpreter
209  endif
210  ifeq ($(1),interp-ac)
211    core_compile_options += --compiler-filter=verify-at-runtime --runtime-arg -Xverify:softfail
212    core_infix := -interp-ac
213  endif
214  ifeq ($(1),jit)
215    core_compile_options += --compiler-filter=verify-at-runtime
216    core_infix := -jit
217  endif
218  ifeq ($(1),default)
219    # Default has no infix, no compile options.
220  endif
221  ifneq ($(filter-out default interpreter interp-ac jit optimizing,$(1)),)
222    # Technically this test is not precise, but hopefully good enough.
223    $$(error found $(1) expected default, interpreter, interpreter-access-checks, jit or optimizing)
224  endif
225
226  ifeq ($(2),pic)
227    core_compile_options += --compile-pic
228    core_pic_infix := -pic
229  endif
230  ifeq ($(2),no-pic)
231    # No change for non-pic
232  endif
233  ifneq ($(filter-out pic no-pic,$(2)),)
234    #Technically this test is not precise, but hopefully good enough.
235    $$(error found $(2) expected pic or no-pic)
236  endif
237
238  core_image_name := $($(3)TARGET_CORE_IMG_OUT_BASE)$$(core_infix)$$(core_pic_infix)$(4)$(CORE_IMG_SUFFIX)
239  core_oat_name := $($(3)TARGET_CORE_OAT_OUT_BASE)$$(core_infix)$$(core_pic_infix)$(4)$(CORE_OAT_SUFFIX)
240
241  # Using the bitness suffix makes it easier to add as a dependency for the run-test mk.
242  ifeq ($(3),)
243    ifdef TARGET_2ND_ARCH
244      $(4)TARGET_CORE_IMAGE_$(1)_$(2)_64 := $$(core_image_name)
245    else
246      $(4)TARGET_CORE_IMAGE_$(1)_$(2)_32 := $$(core_image_name)
247    endif
248  else
249    $(4)TARGET_CORE_IMAGE_$(1)_$(2)_32 := $$(core_image_name)
250  endif
251  $(4)TARGET_CORE_IMG_OUTS += $$(core_image_name)
252  $(4)TARGET_CORE_OAT_OUTS += $$(core_oat_name)
253
254  # If we have a wrapper, make the target phony.
255  ifneq ($(4),)
256.PHONY: $$(core_image_name)
257  endif
258$$(core_image_name): PRIVATE_CORE_COMPILE_OPTIONS := $$(core_compile_options)
259$$(core_image_name): PRIVATE_CORE_IMG_NAME := $$(core_image_name)
260$$(core_image_name): PRIVATE_CORE_OAT_NAME := $$(core_oat_name)
261$$(core_image_name): $$(TARGET_CORE_DEX_FILES) $$(core_dex2oat_dependency)
262	@echo "target dex2oat: $$@"
263	@mkdir -p $$(dir $$@)
264	$$(hide) $(4) $$(DEX2OAT)$(5) --runtime-arg -Xms$(DEX2OAT_IMAGE_XMS) \
265	  --runtime-arg -Xmx$(DEX2OAT_IMAGE_XMX) \
266	  --image-classes=$$(PRELOADED_CLASSES) $$(addprefix --dex-file=,$$(TARGET_CORE_DEX_FILES)) \
267	  $$(addprefix --dex-location=,$$(TARGET_CORE_DEX_LOCATIONS)) --oat-file=$$(PRIVATE_CORE_OAT_NAME) \
268	  --oat-location=$$(PRIVATE_CORE_OAT_NAME) --image=$$(PRIVATE_CORE_IMG_NAME) \
269	  --base=$$(LIBART_IMG_TARGET_BASE_ADDRESS) --instruction-set=$$($(3)TARGET_ARCH) \
270	  --instruction-set-variant=$$($(3)DEX2OAT_TARGET_CPU_VARIANT) \
271	  --instruction-set-features=$$($(3)DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES) \
272	  --android-root=$$(PRODUCT_OUT)/system --include-patch-information --generate-debug-info \
273	  $$(PRIVATE_CORE_COMPILE_OPTIONS) || (rm $$(PRIVATE_CORE_OAT_NAME); exit 1)
274
275$$(core_oat_name): $$(core_image_name)
276
277  # Clean up locally used variables.
278  core_dex2oat_dependency :=
279  core_compile_options :=
280  core_image_name :=
281  core_oat_name :=
282  core_infix :=
283  core_pic_infix :=
284endef  # create-core-oat-target-rules
285
286# $(1): compiler - default, optimizing, jit, interpreter or interpreter-access-checks.
287# $(2): wrapper.
288# $(3): dex2oat suffix.
289define create-core-oat-target-rule-combination
290  $(call create-core-oat-target-rules,$(1),no-pic,,$(2),$(3))
291  $(call create-core-oat-target-rules,$(1),pic,,$(2),$(3))
292
293  ifdef TARGET_2ND_ARCH
294    $(call create-core-oat-target-rules,$(1),no-pic,2ND_,$(2),$(3))
295    $(call create-core-oat-target-rules,$(1),pic,2ND_,$(2),$(3))
296  endif
297endef
298
299$(eval $(call create-core-oat-target-rule-combination,default,,))
300$(eval $(call create-core-oat-target-rule-combination,optimizing,,))
301$(eval $(call create-core-oat-target-rule-combination,interpreter,,))
302$(eval $(call create-core-oat-target-rule-combination,interp-ac,,))
303$(eval $(call create-core-oat-target-rule-combination,jit,,))
304
305valgrindTARGET_CORE_IMG_OUTS :=
306valgrindTARGET_CORE_OAT_OUTS :=
307$(eval $(call create-core-oat-target-rule-combination,default,valgrind,32))
308$(eval $(call create-core-oat-target-rule-combination,optimizing,valgrind,32))
309$(eval $(call create-core-oat-target-rule-combination,interpreter,valgrind,32))
310$(eval $(call create-core-oat-target-rule-combination,interp-ac,valgrind,32))
311$(eval $(call create-core-oat-target-rule-combination,jit,valgrind,32))
312
313valgrind-test-art-host-dex2oat-target: $(valgrindTARGET_CORE_IMG_OUTS)
314
315valgrind-test-art-host-dex2oat: valgrind-test-art-host-dex2oat-host valgrind-test-art-host-dex2oat-target
316