Browse Source

Move all yml2 into own src folder "codegen"

JNI-106
heck 5 years ago
parent
commit
80c0b1e542
  1. 5
      .hgignore
  2. 54
      src/Makefile
  3. 57
      src/codegen/Makefile
  4. 4
      src/codegen/gen_cpp_Engine.ysl2
  5. 4
      src/codegen/gen_cpp_Message.ysl2
  6. 6
      src/codegen/gen_java_Engine.ysl2
  7. 10
      src/codegen/gen_java_Message.ysl2
  8. 6
      src/codegen/gen_throw_pEp_exception.ysl2
  9. 0
      src/codegen/pEp.yml2
  10. 0
      src/codegen/textutils.ysl2
  11. 0
      src/codegen/types_c.ysl2
  12. 0
      src/codegen/types_java.ysl2

5
.hgignore

@ -5,6 +5,7 @@ syntax: glob
*.class *.class
*.jar *.jar
*.swp *.swp
*.d
*.o *.o
*.a *.a
*.dylib *.dylib
@ -24,8 +25,8 @@ foundation_pEp_jniadapter_Engine.*
foundation_pEp_jniadapter_Identity.h foundation_pEp_jniadapter_Identity.h
foundation_pEp_jniadapter_Message.cc foundation_pEp_jniadapter_Message.cc
foundation_pEp_jniadapter_Message.h foundation_pEp_jniadapter_Message.h
#throw_pEp_exception.cc throw_pEp_exception.cc
#throw_pEp_exception.hh throw_pEp_exception.hh
CipherSuite.java CipherSuite.java
Color.java Color.java

54
src/Makefile

@ -45,26 +45,6 @@ JAVA_BUILD_ROOT=../build/java/
OBJ_DIR=. OBJ_DIR=.
DIST_DIR=../dist/ 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 # for "make clean" only
GENERATED_JAVA=\ GENERATED_JAVA=\
$(JAVA_PKG_ROOT)/Engine.java \ $(JAVA_PKG_ROOT)/Engine.java \
@ -79,7 +59,7 @@ GENERATED_JAVA=\
$(JAVA_PKG_ROOT)/SyncHandshakeResult.java \ $(JAVA_PKG_ROOT)/SyncHandshakeResult.java \
$(JAVA_PKG_ROOT)/SyncHandshakeSignal.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=\ GENERATED_CC=\
foundation_pEp_jniadapter_Engine.cc \ foundation_pEp_jniadapter_Engine.cc \
foundation_pEp_jniadapter_Message.cc \ foundation_pEp_jniadapter_Message.cc \
@ -109,7 +89,11 @@ SOURCES+=$(GENERATED_CC)
OBJECTS=$(SOURCES:.cc=.o) OBJECTS=$(SOURCES:.cc=.o)
DEPENDS=$(OBJECTS:.o=.d) 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 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 $(JAVA_BIN_DIR)/jar cf $(DIST_DIR)/$@ -C $(JAVA_BUILD_ROOT) foundation
$(LIB_CXX_DYN): compile-cxx $(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 $(LIB_CXX_STATIC): compile-cxx
$(AR) -r $(DIST_DIR)/$@ $(OBJ_DIR)/*.o $(AR) -r $(DIST_DIR)/$@ *.o
# -------------- Compile ----------------- # -------------- 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)/*.java
$(JAVA_BIN_DIR)/javac -d $(JAVA_BUILD_ROOT) $(JAVA_PKG_ROOT)/exceptions/*.java $(JAVA_BIN_DIR)/javac -d $(JAVA_BUILD_ROOT) $(JAVA_PKG_ROOT)/exceptions/*.java
# Compile C++ using implicit rules # Compile C++ using implicit rules
compile-cxx: create-dirs gen-jni-headers $(OBJECTS)
-include $(DEPENDS) -include $(DEPENDS)
@ -153,32 +137,28 @@ endif
# ------------- YML2 CodeGen -------------- # ------------- YML2 CodeGen --------------
codegen: gen-status-codes $(YML2_MARKERS) codegen:
$(MAKE) -C codegen
$(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)" $@
# ------------- Housekeeping --------------- # ------------- Housekeeping ---------------
create-dirs: create-dirs:
$(MAKE) -C codegen create-dirs
mkdir -p $(JAVA_BUILD_ROOT)/$(JAVA_PKG_ROOT) mkdir -p $(JAVA_BUILD_ROOT)/$(JAVA_PKG_ROOT)
mkdir -p $(JAVA_BUILD_ROOT)/$(JAVA_PKG_ROOT)/exceptions mkdir -p $(JAVA_BUILD_ROOT)/$(JAVA_PKG_ROOT)/exceptions
mkdir -p $(OBJ_DIR)
mkdir -p $(DIST_DIR) mkdir -p $(DIST_DIR)
#rm -rf is too dangerous for vars
remove-dirs: remove-dirs:
$(MAKE) -C codegen remove-dirs
rm -rf ../build rm -rf ../build
rm -rf ../dist rm -rf ../dist
clean: remove-dirs clean: remove-dirs
$(MAKE) -C codegen clean
rm -f $(GENERATED_JAVA) rm -f $(GENERATED_JAVA)
rm -f $(GENERATED_CC) rm -f $(GENERATED_CC)
rm -f $(GENERATED_HH) rm -f $(GENERATED_HH)
rm -f $(JNI_GENERATED_HH) rm -f $(JNI_GENERATED_HH)
rm -f $(YML2_MARKERS) rm -f $(DEPENDS)
rm -f status_list.yml2 rm -f $(OBJECTS)

57
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

4
src/gen_cpp_Engine.ysl2 → src/codegen/gen_cpp_Engine.ysl2

@ -7,10 +7,10 @@ tstylesheet {
template "/namespace[@name='pEp']" { template "/namespace[@name='pEp']" {
apply "interface", 0; 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 <pEp/blacklist.h> #include <pEp/blacklist.h>
#include <pEp/openpgp_compat.h> #include <pEp/openpgp_compat.h>

4
src/gen_cpp_Message.ysl2 → src/codegen/gen_cpp_Message.ysl2

@ -7,13 +7,13 @@ tstylesheet {
template "/namespace[@name='pEp']" { template "/namespace[@name='pEp']" {
apply "struct", 0; apply "struct", 0;
document("gen_cpp_Message.marker", "text") > "" document("../../build/marker/gen_cpp_Message.marker", "text") > ""
} }
template "struct" { template "struct" {
const "jname" call "CamelCase" with "text", "@name"; const "jname" call "CamelCase" with "text", "@name";
document("foundation_pEp_jniadapter_{$jname}.cc", "text") { document("../foundation_pEp_jniadapter_{$jname}.cc", "text") {
|| ||
#include <cassert> #include <cassert>
#include <pEp/mime.h> #include <pEp/mime.h>

6
src/gen_java_Engine.ysl2 → src/codegen/gen_java_Engine.ysl2

@ -6,12 +6,12 @@ tstylesheet {
template "/namespace[@name='pEp']" { template "/namespace[@name='pEp']" {
apply "interface", 0; apply "interface", 0;
document("gen_java_Engine.marker", "text") > "" document("../../build/marker/gen_java_Engine.marker", "text") > ""
} }
template "interface" { template "interface" {
const "cname" call "toJava" with "type", "@name"; 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; 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; package foundation.pEp.jniadapter;

10
src/gen_java_Message.ysl2 → src/codegen/gen_java_Message.ysl2

@ -6,12 +6,12 @@ tstylesheet {
template "/namespace[@name='pEp']" { template "/namespace[@name='pEp']" {
apply "struct|enum|exception", 0; apply "struct|enum|exception", 0;
document("gen_java_Message.marker", "text") > "" document("../../build/marker/gen_java_Message.marker", "text") > ""
} }
template "struct" { template "struct" {
const "cname" call "toJava" with "type", "@name"; 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; package foundation.pEp.jniadapter;
@ -64,7 +64,7 @@ tstylesheet {
`` apply "*[name(.)!='enum']", mode=entry `` 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; package foundation.pEp.jniadapter;
@ -83,7 +83,7 @@ tstylesheet {
template "enum" { template "enum" {
const "jname" call "toJava" with "type", "@name"; const "jname" call "toJava" with "type", "@name";
document("foundation/pEp/jniadapter/{$jname}.java", "text") document("../foundation/pEp/jniadapter/{$jname}.java", "text")
|| ||
// CodeGen template enum // CodeGen template enum
package foundation.pEp.jniadapter; package foundation.pEp.jniadapter;
@ -131,7 +131,7 @@ tstylesheet {
function "exception" { function "exception" {
param "name"; param "name";
document "foundation/pEp/jniadapter/exceptions/{$name}.java", "text" { document "../foundation/pEp/jniadapter/exceptions/{$name}.java", "text" {
| package foundation.pEp.jniadapter.exceptions; | package foundation.pEp.jniadapter.exceptions;
| |
| public class «$name» extends pEpException { | public class «$name» extends pEpException {

6
src/gen_throw_pEp_exception.ysl2 → src/codegen/gen_throw_pEp_exception.ysl2

@ -5,7 +5,7 @@ tstylesheet {
template "/" { template "/" {
apply "namespace", 0; apply "namespace", 0;
document "throw_pEp_exception.hh", "text" document "../throw_pEp_exception.hh", "text"
|| ||
#pragma once #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" template "namespace"
document("throw_pEp_exception.cc", "text") document("../throw_pEp_exception.cc", "text")
|| ||
#include <assert.h> #include <assert.h>
#include <pEp/pEpEngine.h> #include <pEp/pEpEngine.h>

0
src/pEp.yml2 → src/codegen/pEp.yml2

0
src/textutils.ysl2 → src/codegen/textutils.ysl2

0
src/types_c.ysl2 → src/codegen/types_c.ysl2

0
src/types_java.ysl2 → src/codegen/types_java.ysl2

Loading…
Cancel
Save