From 80c0b1e542ccf5cc8dffa18bfa9af92b2a93b5de Mon Sep 17 00:00:00 2001 From: heck Date: Fri, 3 Jul 2020 00:47:46 +0200 Subject: [PATCH] Move all yml2 into own src folder "codegen" --- .hgignore | 5 +- src/Makefile | 54 ++++++------------ src/codegen/Makefile | 57 +++++++++++++++++++ src/{ => codegen}/gen_cpp_Engine.ysl2 | 4 +- src/{ => codegen}/gen_cpp_Message.ysl2 | 4 +- src/{ => codegen}/gen_java_Engine.ysl2 | 6 +- src/{ => codegen}/gen_java_Message.ysl2 | 10 ++-- .../gen_throw_pEp_exception.ysl2 | 6 +- src/{ => codegen}/pEp.yml2 | 0 src/{ => codegen}/textutils.ysl2 | 0 src/{ => codegen}/types_c.ysl2 | 0 src/{ => codegen}/types_java.ysl2 | 0 12 files changed, 92 insertions(+), 54 deletions(-) create mode 100644 src/codegen/Makefile rename src/{ => codegen}/gen_cpp_Engine.ysl2 (98%) rename src/{ => codegen}/gen_cpp_Message.ysl2 (97%) rename src/{ => codegen}/gen_java_Engine.ysl2 (98%) rename src/{ => codegen}/gen_java_Message.ysl2 (96%) rename src/{ => codegen}/gen_throw_pEp_exception.ysl2 (89%) rename src/{ => codegen}/pEp.yml2 (100%) rename src/{ => codegen}/textutils.ysl2 (100%) rename src/{ => codegen}/types_c.ysl2 (100%) rename src/{ => codegen}/types_java.ysl2 (100%) diff --git a/.hgignore b/.hgignore index 551e718..a885677 100644 --- a/.hgignore +++ b/.hgignore @@ -5,6 +5,7 @@ syntax: glob *.class *.jar *.swp +*.d *.o *.a *.dylib @@ -24,8 +25,8 @@ foundation_pEp_jniadapter_Engine.* foundation_pEp_jniadapter_Identity.h foundation_pEp_jniadapter_Message.cc foundation_pEp_jniadapter_Message.h -#throw_pEp_exception.cc -#throw_pEp_exception.hh +throw_pEp_exception.cc +throw_pEp_exception.hh CipherSuite.java Color.java diff --git a/src/Makefile b/src/Makefile index c23556b..0514014 100644 --- a/src/Makefile +++ b/src/Makefile @@ -45,26 +45,6 @@ JAVA_BUILD_ROOT=../build/java/ OBJ_DIR=. DIST_DIR=../dist/ -PEP_HEADER:=$(shell $(CXX) $(CXXFLAGS) -E -M get_header.cc | grep -oe '[^[:space:]]*pEpEngine\.h' | head -1) - -# Every ysl2 file that need to be "compiled" separately, needs to generate a "marker" file -# The marker serves as the make target. -# If the marker file is older than its corresponding ysl2 file, or not exsiting the ysl2 file will be "compiled" -# Naming: -# For a ysl2 file called "gen_example_stuff.ysl2", a marker file called "gen_example_stuff.marker" is expected. -YML2_MARKERS= \ - gen_java_Engine.marker \ - gen_java_Message.marker \ - gen_cpp_Engine.marker \ - gen_cpp_Message.marker \ - gen_throw_pEp_exception.marker - -# All code genration will be done upon change of these files -YML2_INCLUDES= \ - textutils.ysl2 \ - types_c.ysl2 \ - types_java.ysl2 - # for "make clean" only GENERATED_JAVA=\ $(JAVA_PKG_ROOT)/Engine.java \ @@ -79,7 +59,7 @@ GENERATED_JAVA=\ $(JAVA_PKG_ROOT)/SyncHandshakeResult.java \ $(JAVA_PKG_ROOT)/SyncHandshakeSignal.java -# Used to determine files to compile which are being generated +# files to compile which will be be generated GENERATED_CC=\ foundation_pEp_jniadapter_Engine.cc \ foundation_pEp_jniadapter_Message.cc \ @@ -109,7 +89,11 @@ SOURCES+=$(GENERATED_CC) OBJECTS=$(SOURCES:.cc=.o) DEPENDS=$(OBJECTS:.o=.d) -.PHONY: all lib-java lib-cxx compile-java compile-cxx gen-jni-headers codegen gen-status-codes clean create-dirs remove-dirs +.PHONY: all lib-java lib-cxx compile-java compile-cxx gen-jni-headers codegen clean create-dirs remove-dirs + +$(info SOURCES: $(SOURCES)) +$(info OBJECTS: $(OBJECTS)) +$(info DEPENDS: $(DEPENDS)) all: lib-java lib-cxx @@ -124,10 +108,10 @@ $(LIB_JAVA): compile-java $(JAVA_BIN_DIR)/jar cf $(DIST_DIR)/$@ -C $(JAVA_BUILD_ROOT) foundation $(LIB_CXX_DYN): compile-cxx - $(CXX) $(OBJ_DIR)/*.o $(LDFLAGS) $(LDLIBS) -o $(DIST_DIR)/$@ + $(CXX) *.o $(LDFLAGS) $(LDLIBS) -o $(DIST_DIR)/$@ $(LIB_CXX_STATIC): compile-cxx - $(AR) -r $(DIST_DIR)/$@ $(OBJ_DIR)/*.o + $(AR) -r $(DIST_DIR)/$@ *.o # -------------- Compile ----------------- @@ -135,8 +119,8 @@ compile-java: create-dirs codegen $(JAVA_BIN_DIR)/javac -d $(JAVA_BUILD_ROOT) $(JAVA_PKG_ROOT)/*.java $(JAVA_BIN_DIR)/javac -d $(JAVA_BUILD_ROOT) $(JAVA_PKG_ROOT)/exceptions/*.java - # Compile C++ using implicit rules +compile-cxx: create-dirs gen-jni-headers $(OBJECTS) -include $(DEPENDS) @@ -153,32 +137,28 @@ endif # ------------- YML2 CodeGen -------------- -codegen: gen-status-codes $(YML2_MARKERS) - -$(YML2_MARKERS): %.marker : %.ysl2 pEp.yml2 $(YML2_INCLUDES) - $(YML2_PROC) -y $< pEp.yml2 - -gen-status-codes: status_list.yml2 -status_list.yml2: pEp.yml2 - bash ../utils/extract_pEp_status_codes_from_engine.sh "$(PEP_HEADER)" $@ - +codegen: + $(MAKE) -C codegen # ------------- Housekeeping --------------- create-dirs: + $(MAKE) -C codegen create-dirs mkdir -p $(JAVA_BUILD_ROOT)/$(JAVA_PKG_ROOT) mkdir -p $(JAVA_BUILD_ROOT)/$(JAVA_PKG_ROOT)/exceptions - mkdir -p $(OBJ_DIR) mkdir -p $(DIST_DIR) +#rm -rf is too dangerous for vars remove-dirs: + $(MAKE) -C codegen remove-dirs rm -rf ../build rm -rf ../dist clean: remove-dirs + $(MAKE) -C codegen clean rm -f $(GENERATED_JAVA) rm -f $(GENERATED_CC) rm -f $(GENERATED_HH) rm -f $(JNI_GENERATED_HH) - rm -f $(YML2_MARKERS) - rm -f status_list.yml2 + rm -f $(DEPENDS) + rm -f $(OBJECTS) diff --git a/src/codegen/Makefile b/src/codegen/Makefile new file mode 100644 index 0000000..2f6fb48 --- /dev/null +++ b/src/codegen/Makefile @@ -0,0 +1,57 @@ +# Copyright 2018, pEp Foundation +# This file is part of pEp JNI Adapter +# This file may be used under the terms of the GNU General Public License version 3 +# see LICENSE.txt + +include ../../Makefile.conf + +MARKER_DIR=../../build/marker/ + +PEP_HEADER:=$(shell $(CXX) $(CXXFLAGS) -E -M ../get_header.cc | grep -oe '[^[:space:]]*pEpEngine\.h' | head -1) + +# Every ysl2 file that need to be "compiled" separately, needs to generate a "marker" file +# The marker serves as the make target. +# If the marker file is older than its corresponding ysl2 file, or not exsiting the ysl2 file will be "compiled" +# Naming: +# For a ysl2 file called "gen_example_stuff.ysl2", a marker file called "gen_example_stuff.marker" is expected. +YML2_MARKERS= \ + $(MARKER_DIR)/gen_java_Engine.marker \ + $(MARKER_DIR)/gen_java_Message.marker \ + $(MARKER_DIR)/gen_cpp_Engine.marker \ + $(MARKER_DIR)/gen_cpp_Message.marker \ + $(MARKER_DIR)/gen_throw_pEp_exception.marker + +# All code genration will be done upon change of these files +YML2_INCLUDES= \ + textutils.ysl2 \ + types_c.ysl2 \ + types_java.ysl2 + + +.PHONY: all codegen gen-status-codes create-dirs remove-dirs clean + +all: codegen + +# ------------- YML2 CodeGen -------------- +codegen: create-dirs gen-status-codes $(YML2_MARKERS) + +$(YML2_MARKERS): $(MARKER_DIR)/%.marker : %.ysl2 pEp.yml2 $(YML2_INCLUDES) + $(YML2_PROC) -y $< pEp.yml2 + +gen-status-codes: status_list.yml2 + +status_list.yml2: pEp.yml2 + bash ../../utils/extract_pEp_status_codes_from_engine.sh "$(PEP_HEADER)" $@ + + +# ------------- Housekeeping --------------- +create-dirs: + mkdir -p $(MARKER_DIR) + +#rm -rf is too dangerous for vars +remove-dirs: + rm -rf ../../build/marker + +clean: remove-dirs + rm -f status_list.yml2 + diff --git a/src/gen_cpp_Engine.ysl2 b/src/codegen/gen_cpp_Engine.ysl2 similarity index 98% rename from src/gen_cpp_Engine.ysl2 rename to src/codegen/gen_cpp_Engine.ysl2 index ab337bc..994fed3 100644 --- a/src/gen_cpp_Engine.ysl2 +++ b/src/codegen/gen_cpp_Engine.ysl2 @@ -7,10 +7,10 @@ tstylesheet { template "/namespace[@name='pEp']" { apply "interface", 0; - document("gen_cpp_Engine.marker", "text") > "" + document("../../build/marker/gen_cpp_Engine.marker", "text") > "" } - template "interface" document("foundation_pEp_jniadapter_{@name}.cc", "text") + template "interface" document("../foundation_pEp_jniadapter_{@name}.cc", "text") || #include #include diff --git a/src/gen_cpp_Message.ysl2 b/src/codegen/gen_cpp_Message.ysl2 similarity index 97% rename from src/gen_cpp_Message.ysl2 rename to src/codegen/gen_cpp_Message.ysl2 index 963c681..6aeea12 100644 --- a/src/gen_cpp_Message.ysl2 +++ b/src/codegen/gen_cpp_Message.ysl2 @@ -7,13 +7,13 @@ tstylesheet { template "/namespace[@name='pEp']" { apply "struct", 0; - document("gen_cpp_Message.marker", "text") > "" + document("../../build/marker/gen_cpp_Message.marker", "text") > "" } template "struct" { const "jname" call "CamelCase" with "text", "@name"; - document("foundation_pEp_jniadapter_{$jname}.cc", "text") { + document("../foundation_pEp_jniadapter_{$jname}.cc", "text") { || #include #include diff --git a/src/gen_java_Engine.ysl2 b/src/codegen/gen_java_Engine.ysl2 similarity index 98% rename from src/gen_java_Engine.ysl2 rename to src/codegen/gen_java_Engine.ysl2 index db69b7c..96a2fe1 100644 --- a/src/gen_java_Engine.ysl2 +++ b/src/codegen/gen_java_Engine.ysl2 @@ -6,12 +6,12 @@ tstylesheet { template "/namespace[@name='pEp']" { apply "interface", 0; - document("gen_java_Engine.marker", "text") > "" + document("../../build/marker/gen_java_Engine.marker", "text") > "" } template "interface" { const "cname" call "toJava" with "type", "@name"; - document("foundation/pEp/jniadapter/{$cname}.java", "text") + document("../foundation/pEp/jniadapter/{$cname}.java", "text") || package foundation.pEp.jniadapter; @@ -26,7 +26,7 @@ tstylesheet { } || - document("foundation/pEp/jniadapter/{$cname}Interface.java", "text") + document("../foundation/pEp/jniadapter/{$cname}Interface.java", "text") || package foundation.pEp.jniadapter; diff --git a/src/gen_java_Message.ysl2 b/src/codegen/gen_java_Message.ysl2 similarity index 96% rename from src/gen_java_Message.ysl2 rename to src/codegen/gen_java_Message.ysl2 index 2610d2f..d94eae0 100644 --- a/src/gen_java_Message.ysl2 +++ b/src/codegen/gen_java_Message.ysl2 @@ -6,12 +6,12 @@ tstylesheet { template "/namespace[@name='pEp']" { apply "struct|enum|exception", 0; - document("gen_java_Message.marker", "text") > "" + document("../../build/marker/gen_java_Message.marker", "text") > "" } template "struct" { const "cname" call "toJava" with "type", "@name"; - document("foundation/pEp/jniadapter/{$cname}.java", "text") + document("../foundation/pEp/jniadapter/{$cname}.java", "text") || package foundation.pEp.jniadapter; @@ -64,7 +64,7 @@ tstylesheet { `` apply "*[name(.)!='enum']", mode=entry } || - document("foundation/pEp/jniadapter/{$cname}Interface.java", "text") + document("../foundation/pEp/jniadapter/{$cname}Interface.java", "text") || package foundation.pEp.jniadapter; @@ -83,7 +83,7 @@ tstylesheet { template "enum" { const "jname" call "toJava" with "type", "@name"; - document("foundation/pEp/jniadapter/{$jname}.java", "text") + document("../foundation/pEp/jniadapter/{$jname}.java", "text") || // CodeGen template enum package foundation.pEp.jniadapter; @@ -131,7 +131,7 @@ tstylesheet { function "exception" { param "name"; - document "foundation/pEp/jniadapter/exceptions/{$name}.java", "text" { + document "../foundation/pEp/jniadapter/exceptions/{$name}.java", "text" { | package foundation.pEp.jniadapter.exceptions; | | public class «$name» extends pEpException { diff --git a/src/gen_throw_pEp_exception.ysl2 b/src/codegen/gen_throw_pEp_exception.ysl2 similarity index 89% rename from src/gen_throw_pEp_exception.ysl2 rename to src/codegen/gen_throw_pEp_exception.ysl2 index 01602ac..7371e01 100644 --- a/src/gen_throw_pEp_exception.ysl2 +++ b/src/codegen/gen_throw_pEp_exception.ysl2 @@ -5,7 +5,7 @@ tstylesheet { template "/" { apply "namespace", 0; - document "throw_pEp_exception.hh", "text" + document "../throw_pEp_exception.hh", "text" || #pragma once @@ -18,11 +18,11 @@ tstylesheet { }; || - document("gen_throw_pEp_exception.marker", "text") > "" + document("../../build/marker/gen_throw_pEp_exception.marker", "text") > "" } template "namespace" - document("throw_pEp_exception.cc", "text") + document("../throw_pEp_exception.cc", "text") || #include #include diff --git a/src/pEp.yml2 b/src/codegen/pEp.yml2 similarity index 100% rename from src/pEp.yml2 rename to src/codegen/pEp.yml2 diff --git a/src/textutils.ysl2 b/src/codegen/textutils.ysl2 similarity index 100% rename from src/textutils.ysl2 rename to src/codegen/textutils.ysl2 diff --git a/src/types_c.ysl2 b/src/codegen/types_c.ysl2 similarity index 100% rename from src/types_c.ysl2 rename to src/codegen/types_c.ysl2 diff --git a/src/types_java.ysl2 b/src/codegen/types_java.ysl2 similarity index 100% rename from src/types_java.ysl2 rename to src/codegen/types_java.ysl2