From 947c4cdf1c7653b7aacafca38955234a5a33f364 Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Mon, 25 Jan 2016 16:49:27 +0000 Subject: binary: Allow specifying a path for generated proto headers protobuf compilation defaults to dropping the generated objects and headers onto a path derived from the origin source path. This poses a problem with some of our repositories since they're not placed in their original paths, and may include hard references to pb headers assuming the original directory. Typical use of this will be to place a LOCAL_PROTOC_OUTPUT := line in the relevant module block (for example, "hardware/ril" for our "hardware/ril-caf") Change-Id: Ib9b0cadd47e29a0d2e693b331cfc18e71b048ee5 --- core/binary.mk | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'core/binary.mk') diff --git a/core/binary.mk b/core/binary.mk index 4206597..46fd492 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -538,17 +538,32 @@ proto_generated_headers := $(patsubst %.pb$(my_proto_source_suffix),%.pb.h, $(pr proto_generated_objects := $(addprefix $(proto_generated_obj_dir)/, \ $(patsubst %.proto,%.pb.o,$(proto_sources_fullpath))) +define copy-proto-files +$(if $(PRIVATE_PROTOC_OUTPUT), \ + $(eval proto_generated_path := $(dir $(subst $(PRIVATE_PROTOC_INPUT),$(PRIVATE_PROTOC_OUTPUT),$@))) + @mkdir -p $(dir $(proto_generated_path)) + @echo "Protobuf relocation: $@ => $(proto_generated_path)" + @cp -f $@ $(proto_generated_path) ,) +endef + + # Ensure the transform-proto-to-cc rule is only defined once in multilib build. ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined $(proto_generated_sources): PRIVATE_PROTO_INCLUDES := $(TOP) $(proto_generated_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags) +$(proto_generated_sources): PRIVATE_PROTOC_OUTPUT := $(LOCAL_PROTOC_OUTPUT) +$(proto_generated_sources): PRIVATE_PROTOC_INPUT := $(LOCAL_PATH) $(proto_generated_sources): $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix): %.proto $(PROTOC) $(transform-proto-to-cc) + $(copy-proto-files) # This is just a dummy rule to make sure gmake doesn't skip updating the dependents. +$(proto_generated_headers): PRIVATE_PROTOC_OUTPUT := $(LOCAL_PROTOC_OUTPUT) +$(proto_generated_headers): PRIVATE_PROTOC_INPUT := $(LOCAL_PATH) $(proto_generated_headers): $(proto_generated_sources_dir)/%.pb.h: $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix) @echo "Updated header file $@." $(hide) touch $@ + $(copy-proto-files) $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true endif # transform-proto-to-cc rule included only once -- cgit v1.1