[CRIU] [PATCH 2/9] protobuf: generate python modules

Cyrill Gorcunov gorcunov at gmail.com
Thu Oct 9 11:57:59 PDT 2014


On Wed, Oct 08, 2014 at 07:10:04PM +0300, Ruslan Kuprieiev wrote:
> >>  $(obj)/%.pb-c.c $(obj)/%.pb-c.h: $(obj)/%.proto $(obj)/%.proto.c.d
> >>  	$(E) "  PBCC    " $@
> >>  	$(Q) protoc-c --proto_path=$(obj)/ --c_out=$(obj)/ $<
> >>+	$(E) "  PBCC    " $(@:.pb-c.c=_pb2.py)
> >>+	$(Q) protoc -I=$(obj)/ --python_out=$(obj)/ $<
> >I don't think that adding action to another target file is good idea.
> >You should declare separate target: deps line for .py files.
> 
> Ok. I wasn't sure how to make that in a nicer way =).
> 
> >
> >Cyrill can help.
> Will ask Cyrill for the help.
> >>  ifeq ($(SRCARCH),arm)
> >>  	$(Q) sed -i -e 's/4294967295/0xFFFFFFFF/g' $@
> >>  	$(Q) sed -i -e 's/4294967295/0xFFFFFFFF/g' $(patsubst %.c,%.h,$@)
> >>@@ -123,3 +125,4 @@ endif
> >>  cleanup-y += $(obj)/*.c.d $(obj)/*.pb-c.c $(obj)/*.pb-c.h
> >>  cleanup-y += $(obj)/*.d $(obj)/*.i $(obj)/*.s $(obj)/*.o
> >>+cleanup-y += $(obj)/*_pb2.py $(obj)/*.pyc

I would rather do ($criu is root directory where our sources live)

1) In criu/Makefile

crit:
	$(Q) $(Q) $(MAKE) $(build)=protobuf crit
	$(Q) $(MAKE) -C pycriu all

2) In criu/protobuf/Makefile

proto-pycriu:= $(proto-obj-y:.o=_pb2.py)

$(obj)/%_pb2.py: $(obj)/%.proto $(obj)/%.proto.c.d
	$(E) "  PBCC    " $(@)
	$(Q) protoc -I=$(obj)/ --python_out=$(obj)/ $<

crit: $(addprefix $(obj)/,$(proto-py))
	@true

Thus py files won't be generated until "make crit" requested. IOW, on top of your repo
---
diff --git a/Makefile b/Makefile
index cf6ee2a54322..a854d0068a95 100644
--- a/Makefile
+++ b/Makefile
@@ -195,6 +195,7 @@ $(PROGRAM): $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS)
 	$(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(LDFLAGS) $(GMONLDOPT) -rdynamic -o $@
 
 crit:
+	$(Q) $(Q) $(MAKE) $(build)=protobuf crit
 	$(Q) $(MAKE) -C pycriu all
 
 zdtm: all
diff --git a/protobuf/Makefile b/protobuf/Makefile
index fa91d40a55e0..4ea694a63c74 100644
--- a/protobuf/Makefile
+++ b/protobuf/Makefile
@@ -66,6 +66,7 @@ proto-obj-y	+= cgroup.o
 proto		:= $(proto-obj-y:.o=)
 proto-c		:= $(proto-obj-y:.o=.pb-c.c)
 proto-h		:= $(proto-obj-y:.o=.pb-c.h)
+proto-py	:= $(proto-obj-y:.o=_pb2.py)
 
 .SECONDARY:
 
@@ -89,14 +90,19 @@ $(obj)/%.proto.c.d: $(obj)/%.proto | $(obj)/%.proto.d
 $(obj)/%.pb-c.c $(obj)/%.pb-c.h: $(obj)/%.proto $(obj)/%.proto.c.d
 	$(E) "  PBCC    " $@
 	$(Q) protoc-c --proto_path=$(obj)/ --c_out=$(obj)/ $<
-	$(E) "  PBCC    " $(@:.pb-c.c=_pb2.py)
-	$(Q) protoc -I=$(obj)/ --python_out=$(obj)/ $<
 ifeq ($(SRCARCH),arm)
 	$(Q) sed -i -e 's/4294967295/0xFFFFFFFF/g' $@
 	$(Q) sed -i -e 's/4294967295/0xFFFFFFFF/g' $(patsubst %.c,%.h,$@)
 	$(Q) sed -i -e 's/4294967295/0xFFFFFFFF/g' $(patsubst %.h,%.c,$@)
 endif
 
+$(obj)/%_pb2.py: $(obj)/%.proto $(obj)/%.proto.c.d
+	$(E) "  PBCC    " $(@)
+	$(Q) protoc -I=$(obj)/ --python_out=$(obj)/ $<
+
+crit: $(addprefix $(obj)/,$(proto-py))
+	@true
+
 _first_stage := $(addprefix $(obj)/,$(proto-obj-y:.o=.pb-c.c))
 _first_stage += $(addprefix $(obj)/,$(proto-obj-y:.o=.pb-c.h))
 $(obj)/%.pb-c.d: $(_first_stage)


More information about the CRIU mailing list