1# Copyright (C) 2015 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Manages use of annotation processors.
16#
17# At the moment both the -processorpath and the -processor
18# flags must be specified in order to use annotation processors
19# as a code indexing tool that wraps javac doesn't as yet support
20# the same behaviour as standard javac with regard to use of
21# annotation processors. In particular it:
22# - doesn't default -processorpath to be the same as -classpath
23# - doesn't scan processorpath to automatically discover processors
24# - doesn't support a comma separated list of processor class names
25#   on a single -processor option so need on option per class name.
26#
27# Input variables:
28#
29#   PROCESSOR_LIBRARIES := <list of library names>
30#     Similar to names added to LOCAL_JAVA_LIBRARIES.
31#
32#   PROCESSOR_CLASSES := <list of processor class names>
33#
34# Upon exit various LOCAL_ variables have been updated and the
35# input variables have been cleared.
36
37# Map the library names to actual JARs.
38PROCESSOR_JARS := $(call java-lib-deps, $(PROCESSOR_LIBRARIES), true)
39
40# Add a javac -processorpath flag.
41LOCAL_JAVACFLAGS += -processorpath $(call normalize-path-list,$(PROCESSOR_JARS))
42
43# Specify only one processor class per -processor option as
44# the indexing tool does not parse the -processor value as a
45# comma separated list.
46LOCAL_JAVACFLAGS += $(foreach class,$(PROCESSOR_CLASSES),-processor $(class))
47
48# Create a source directory into which the code will be generated.
49GENERATED_SOURCE_DIR := $(local-generated-sources-dir)/annotation_processor_output/
50
51# Tell javac to generate source files in the source directory.
52LOCAL_JAVACFLAGS += -s $(GENERATED_SOURCE_DIR)
53
54# Add dependency between the jar being built and the processor jars so that
55# they are built before this one.
56LOCAL_ADDITIONAL_DEPENDENCIES += $(PROCESSOR_JARS) $(GENERATED_SOURCE_DIR)
57
58$(GENERATED_SOURCE_DIR):
59	mkdir -p $@
60
61# Clean up all the extra variables to make sure that they don't escape to
62# another module.
63PROCESSOR_LIBRARIES :=
64PROCESSOR_CLASSES :=
65PROCESSOR_JARS :=
66GENERATED_SOURCE_DIR :=
67