am 39f358b7
: Merge "Protobuf compiler support in the build system"
* commit '39f358b75f1c6a9a10823bf5e400d1ece0144a05': Protobuf compiler support in the build system
This commit is contained in:
commit
ad3e00724d
6 changed files with 130 additions and 6 deletions
|
@ -262,6 +262,38 @@ logtags_java_sources :=
|
|||
event_log_tags :=
|
||||
endif
|
||||
|
||||
###########################################################
|
||||
## .proto files: Compile proto files to .java
|
||||
###########################################################
|
||||
proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
|
||||
# Because names of the .java files compiled from .proto files are unknown until the
|
||||
# .proto files are compiled, we use a timestamp file as depedency.
|
||||
proto_java_sources_file_stamp :=
|
||||
ifneq ($(proto_sources),)
|
||||
proto_sources_fullpath := $(addprefix $(TOP_DIR)$(LOCAL_PATH)/, $(proto_sources))
|
||||
# By putting the generated java files into $(LOCAL_INTERMEDIATE_SOURCE_DIR), they will be
|
||||
# automatically found by the java compiling function transform-java-to-classes.jar.
|
||||
proto_java_intemediate_dir := $(LOCAL_INTERMEDIATE_SOURCE_DIR)/proto
|
||||
proto_java_sources_file_stamp := $(proto_java_intemediate_dir)/Proto.stamp
|
||||
proto_java_sources_dir := $(proto_java_intemediate_dir)/src
|
||||
|
||||
$(proto_java_sources_file_stamp): PRIVATE_PROTO_INCLUDES := $(TOP)
|
||||
$(proto_java_sources_file_stamp): PRIVATE_PROTO_SRC_FILES := $(proto_sources_fullpath)
|
||||
$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_DIR := $(proto_java_sources_dir)
|
||||
ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
|
||||
$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --javamicro_out
|
||||
else
|
||||
$(proto_java_sources_file_stamp): PRIVATE_PROTO_JAVA_OUTPUT_OPTION := --java_out
|
||||
endif
|
||||
$(proto_java_sources_file_stamp) : $(proto_sources_fullpath) $(PROTOC)
|
||||
$(call transform-proto-to-java)
|
||||
|
||||
#TODO: protoc should output the dependencies introduced by imports.
|
||||
|
||||
LOCAL_INTERMEDIATE_TARGETS += $(proto_java_sources_file_stamp)
|
||||
endif # proto_sources
|
||||
|
||||
|
||||
###########################################################
|
||||
## Java: Compile .java files to .class
|
||||
###########################################################
|
||||
|
|
|
@ -145,6 +145,43 @@ $(LOCAL_GENERATED_SOURCES): PRIVATE_MODULE := $(LOCAL_MODULE)
|
|||
ALL_GENERATED_SOURCES += $(LOCAL_GENERATED_SOURCES)
|
||||
|
||||
|
||||
###########################################################
|
||||
## Compile the .proto files to .cc and then to .o
|
||||
###########################################################
|
||||
proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
|
||||
proto_generated_objects :=
|
||||
proto_generated_headers :=
|
||||
ifneq ($(proto_sources),)
|
||||
proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
|
||||
proto_generated_cc_sources_dir := $(intermediates)/proto
|
||||
proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \
|
||||
$(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath)))
|
||||
proto_generated_objects := $(patsubst %.cc,%.o, $(proto_generated_cc_sources))
|
||||
|
||||
$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
|
||||
$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir)
|
||||
$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC)
|
||||
$(transform-proto-to-cc)
|
||||
|
||||
proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources))
|
||||
$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc
|
||||
|
||||
$(proto_generated_cc_sources): PRIVATE_ARM_MODE := $(normal_objects_mode)
|
||||
$(proto_generated_cc_sources): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
|
||||
$(proto_generated_objects): $(proto_generated_cc_sources_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc
|
||||
$(transform-$(PRIVATE_HOST)cpp-to-o)
|
||||
-include $(proto_generated_objects:%.o=%.P)
|
||||
|
||||
LOCAL_C_INCLUDES += external/protobuf/src $(proto_generated_cc_sources_dir)
|
||||
LOCAL_CFLAGS += -DGOOGLE_PROTOBUF_NO_RTTI
|
||||
ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
|
||||
LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-full
|
||||
else
|
||||
LOCAL_STATIC_LIBRARIES += libprotobuf-cpp-2.3.0-lite
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
###########################################################
|
||||
## YACC: Compile .y files to .cpp and the to .o.
|
||||
###########################################################
|
||||
|
@ -213,7 +250,7 @@ cpp_objects := $(cpp_arm_objects) $(cpp_normal_objects)
|
|||
ifneq ($(strip $(cpp_objects)),)
|
||||
$(cpp_objects): $(intermediates)/%.o: \
|
||||
$(TOPDIR)$(LOCAL_PATH)/%$(LOCAL_CPP_EXTENSION) \
|
||||
$(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
|
||||
$(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES)
|
||||
$(transform-$(PRIVATE_HOST)cpp-to-o)
|
||||
-include $(cpp_objects:%.o=%.P)
|
||||
endif
|
||||
|
@ -230,7 +267,7 @@ ifneq ($(strip $(gen_cpp_objects)),)
|
|||
# TODO: support compiling certain generated files as arm.
|
||||
$(gen_cpp_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
|
||||
$(gen_cpp_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
|
||||
$(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
|
||||
$(gen_cpp_objects): $(intermediates)/%.o: $(intermediates)/%$(LOCAL_CPP_EXTENSION) $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES)
|
||||
$(transform-$(PRIVATE_HOST)cpp-to-o)
|
||||
-include $(gen_cpp_objects:%.o=%.P)
|
||||
endif
|
||||
|
@ -277,7 +314,7 @@ $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
|
|||
c_objects := $(c_arm_objects) $(c_normal_objects)
|
||||
|
||||
ifneq ($(strip $(c_objects)),)
|
||||
$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
|
||||
$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES)
|
||||
$(transform-$(PRIVATE_HOST)c-to-o)
|
||||
-include $(c_objects:%.o=%.P)
|
||||
endif
|
||||
|
@ -294,7 +331,7 @@ ifneq ($(strip $(gen_c_objects)),)
|
|||
# TODO: support compiling certain generated files as arm.
|
||||
$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
|
||||
$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
|
||||
$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(LOCAL_ADDITIONAL_DEPENDENCIES)
|
||||
$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) $(LOCAL_ADDITIONAL_DEPENDENCIES)
|
||||
$(transform-$(PRIVATE_HOST)c-to-o)
|
||||
-include $(gen_c_objects:%.o=%.P)
|
||||
endif
|
||||
|
@ -307,7 +344,7 @@ objc_sources := $(filter %.m,$(LOCAL_SRC_FILES))
|
|||
objc_objects := $(addprefix $(intermediates)/,$(objc_sources:.m=.o))
|
||||
|
||||
ifneq ($(strip $(objc_objects)),)
|
||||
$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
|
||||
$(objc_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.m $(yacc_cpps) $(proto_generated_headers) $(PRIVATE_ADDITIONAL_DEPENDENCIES)
|
||||
$(transform-$(PRIVATE_HOST)m-to-o)
|
||||
-include $(objc_objects:%.o=%.P)
|
||||
endif
|
||||
|
@ -352,6 +389,7 @@ all_objects := \
|
|||
$(gen_c_objects) \
|
||||
$(yacc_objects) \
|
||||
$(lex_objects) \
|
||||
$(proto_generated_objects) \
|
||||
$(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES))
|
||||
|
||||
LOCAL_C_INCLUDES += $(TOPDIR)$(LOCAL_PATH) $(intermediates) $(base_intermediates)
|
||||
|
|
|
@ -100,6 +100,7 @@ LOCAL_WARNINGS_ENABLE:=
|
|||
LOCAL_MANIFEST_FILE:=
|
||||
LOCAL_BUILD_HOST_DEX:=
|
||||
LOCAL_DEX_PREOPT:=
|
||||
LOCAL_PROTOC_OPTIMIZE_TYPE:= # lite(default),micro,full
|
||||
|
||||
# Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to
|
||||
# iterate over thousands of entries every time.
|
||||
|
|
|
@ -200,6 +200,7 @@ YACC:= bison -d
|
|||
DOXYGEN:= doxygen
|
||||
AAPT := $(HOST_OUT_EXECUTABLES)/aapt$(HOST_EXECUTABLE_SUFFIX)
|
||||
AIDL := $(HOST_OUT_EXECUTABLES)/aidl$(HOST_EXECUTABLE_SUFFIX)
|
||||
PROTOC := $(HOST_OUT_EXECUTABLES)/aprotoc$(HOST_EXECUTABLE_SUFFIX)
|
||||
ICUDATA := $(HOST_OUT_EXECUTABLES)/icudata$(HOST_EXECUTABLE_SUFFIX)
|
||||
SIGNAPK_JAR := $(HOST_OUT_JAVA_LIBRARIES)/signapk$(COMMON_JAVA_PACKAGE_SUFFIX)
|
||||
MKBOOTFS := $(HOST_OUT_EXECUTABLES)/mkbootfs$(HOST_EXECUTABLE_SUFFIX)
|
||||
|
|
|
@ -235,6 +235,19 @@ $(patsubst ./%,%, \
|
|||
)
|
||||
endef
|
||||
|
||||
###########################################################
|
||||
## Find all of the .proto files under the named directories.
|
||||
## Meant to be used like:
|
||||
## SRC_FILES := $(call all-proto-files-under,src)
|
||||
###########################################################
|
||||
|
||||
define all-proto-files-under
|
||||
$(patsubst ./%,%, \
|
||||
$(shell cd $(LOCAL_PATH) ; \
|
||||
find $(1) -name "*.proto" -and -not -name ".*") \
|
||||
)
|
||||
endef
|
||||
|
||||
###########################################################
|
||||
## Find all of the html files under the named directories.
|
||||
## Meant to be used like:
|
||||
|
@ -745,6 +758,34 @@ $(hide) $(JAVATAGS) -o $@ $^
|
|||
endef
|
||||
|
||||
|
||||
###########################################################
|
||||
## Commands for running protoc to compile .proto into .java
|
||||
###########################################################
|
||||
|
||||
define transform-proto-to-java
|
||||
@mkdir -p $(dir $@)
|
||||
@echo "Protoc: $@ <= $(PRIVATE_PROTO_SRC_FILES)"
|
||||
@rm -rf $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
|
||||
@mkdir -p $(PRIVATE_PROTO_JAVA_OUTPUT_DIR)
|
||||
$(hide) $(PROTOC) \
|
||||
$(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
|
||||
$(PRIVATE_PROTO_JAVA_OUTPUT_OPTION)=$(PRIVATE_PROTO_JAVA_OUTPUT_DIR) \
|
||||
$(PRIVATE_PROTO_SRC_FILES)
|
||||
$(hide) touch $@
|
||||
endef
|
||||
|
||||
######################################################################
|
||||
## Commands for running protoc to compile .proto into .pb.cc and .pb.h
|
||||
######################################################################
|
||||
define transform-proto-to-cc
|
||||
@mkdir -p $(dir $@)
|
||||
@echo "Protoc: $@ <= $<"
|
||||
$(hide) $(PROTOC) \
|
||||
$(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
|
||||
--cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $<
|
||||
endef
|
||||
|
||||
|
||||
###########################################################
|
||||
## Commands for running gcc to compile a C++ file
|
||||
###########################################################
|
||||
|
|
13
core/java.mk
13
core/java.mk
|
@ -32,6 +32,16 @@ else
|
|||
LOCAL_JAVA_LIBRARIES := core core-junit ext framework $(LOCAL_JAVA_LIBRARIES)
|
||||
endif
|
||||
endif
|
||||
|
||||
proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES))
|
||||
ifneq ($(proto_sources),)
|
||||
ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),micro)
|
||||
LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-2.3.0-micro
|
||||
else
|
||||
LOCAL_STATIC_JAVA_LIBRARIES += libprotobuf-java-2.3.0-lite
|
||||
endif
|
||||
endif
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := $(sort $(LOCAL_JAVA_LIBRARIES))
|
||||
|
||||
LOCAL_BUILT_MODULE_STEM := $(strip $(LOCAL_BUILT_MODULE_STEM))
|
||||
|
@ -167,7 +177,8 @@ ALL_MODULES.$(LOCAL_MODULE).STUBS := $(full_classes_stubs_jar)
|
|||
# Deps for generated source files must be handled separately,
|
||||
# via deps on the target that generates the sources.
|
||||
$(full_classes_compiled_jar): PRIVATE_JAVACFLAGS := $(LOCAL_JAVACFLAGS)
|
||||
$(full_classes_compiled_jar): $(java_sources) $(java_resource_sources) $(full_java_lib_deps) $(jar_manifest_file)
|
||||
$(full_classes_compiled_jar): $(java_sources) $(java_resource_sources) $(full_java_lib_deps) $(jar_manifest_file) \
|
||||
$(RenderScript_file_stamp) $(proto_java_sources_file_stamp)
|
||||
$(transform-java-to-classes.jar)
|
||||
|
||||
# All of the rules after full_classes_compiled_jar are very unlikely
|
||||
|
|
Loading…
Reference in a new issue