From 44b1bdc8081f4968e70313463059e1ce77806ce2 Mon Sep 17 00:00:00 2001 From: José Bollo Date: Thu, 16 May 2019 09:13:59 +0200 Subject: afm-unit.conf: cleanup of generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The generation files are reworked to improve their evolution and maintainability: - the Makefile now refers to any .inc file - the macros are isolated from the skeleton - main iterators are managed in the skeleton - improve management of UNIT_NAME_BASE Bug-AGL: SPEC-2436 Change-Id: I0877eb0149c9362be3290ed2c146cc69fc6bf718 Signed-off-by: José Bollo --- conf/unit/generate-unit-conf/Makefile | 2 +- conf/unit/generate-unit-conf/afm-unit | 94 ++++++----------------- conf/unit/generate-unit-conf/macros.inc | 67 ++++++++++++++++ conf/unit/generate-unit-conf/provided-api.inc | 11 --- conf/unit/generate-unit-conf/provided-binding.inc | 8 -- conf/unit/generate-unit-conf/service.inc | 24 +++--- 6 files changed, 102 insertions(+), 104 deletions(-) create mode 100644 conf/unit/generate-unit-conf/macros.inc (limited to 'conf/unit/generate-unit-conf') diff --git a/conf/unit/generate-unit-conf/Makefile b/conf/unit/generate-unit-conf/Makefile index 2849d6f..51cb9c8 100644 --- a/conf/unit/generate-unit-conf/Makefile +++ b/conf/unit/generate-unit-conf/Makefile @@ -2,7 +2,7 @@ MAIN = afm-unit -FILES = $(MAIN) binder.inc provided-api.inc provided-binding.inc service.inc Makefile +FILES = $(MAIN) $(shell ls *.inc) Makefile DIR = .. diff --git a/conf/unit/generate-unit-conf/afm-unit b/conf/unit/generate-unit-conf/afm-unit index 47ba469..2a91067 100644 --- a/conf/unit/generate-unit-conf/afm-unit +++ b/conf/unit/generate-unit-conf/afm-unit @@ -1,74 +1,12 @@ divert(-1) +-------------------------------------------------------------------------------- dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: ------------------------------------------------------------------------ +include(macros.inc) -- Set the comment character of m4 to ; instead of # -- This is needed for substitution within lines starting with # changecom( ';') - ------------------------------------------------------------------------ --- -define( `X_EMITS', 1) -define( `X_DIVERTS', `divert(eval(-!X_EMITS()))') -define( `X_PUSH_DIVERTS', `pushdef(`X_EMITS', eval(X_EMITS() && $1))X_DIVERTS()') - -define( `X_IF', `pushdef(`X_COND', $1)X_PUSH_DIVERTS($1)') -define( `X_ELSE', `popdef(`X_EMITS')X_PUSH_DIVERTS(eval(!X_COND))') -define( `X_ELIF', `X_ELSE()X_IF($1)') -define( `X_ENDIF', `popdef(`X_EMITS')popdef(`X_COND')X_DIVERTS()') - -define( `IF', `pushdef(`ELSE',`X_ELSE()')pushdef(`ELIF',`X_ELIF($1)')pushdef(`ENDIF',`X_ENDIF()popdef(`ELSE',`ELIF',`ENDIF')')X_IF($1)') - ------------------------------------------------------------------------ --- -define( `MUSTACH_ON', `ifelse(`$2',,,`{{#$1}}`$2'{{/$1}}')ifelse(`$3',,,`{{^$1}}`$3'{{/$1}}')') -define( `MUSTACH_IF', `{{#$1}}pushdef(`ELSE',`{{/$1}}{{^$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')') -define( `MUSTACH_IF_NOT', `{{^$1}}pushdef(`ELSE',`{{/$1}}{{#$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')') - ------------------------------------------------------------------------ --- -define( `PERM', `@afm_prefix@permission:$1') -define( `REQPERM', `required-permission.PERM($1)') - -define( `ON_PERM', `MUSTACH_ON(REQPERM($1),$2,$3)') -define( `IF_PERM', `MUSTACH_IF(REQPERM($1))') -define( `IF_NOT_PERM', `MUSTACH_IF_NOT(REQPERM($1))') - -define( `ON_CONTENT', `MUSTACH_ON(content.type=$1,$2,$3)') -define( `IF_CONTENT', `MUSTACH_IF(content.type=$1)') -define( `IF_NOT_CONTENT', `MUSTACH_IF_NOT(content.type=$1)') - -define( `ON_VALUE', `MUSTACH_ON(value=$1,$2,$3)') -define( `IF_VALUE', `MUSTACH_IF(value=$1)') -define( `IF_NOT_VALUE', `MUSTACH_IF_NOT(value=$1)') - ------------------------------------------------------------------------ --- - when home screen will use real ids - use TARGET={{:id}}--{{:ver}}--{{:#target}} - instead of TARGET={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} - -define( `TARGET', `{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}') -define( `UNIT_NAME_BASE', `afm-ON_PERM(`:public:hidden', `service', `appli')-{{:id}}--{{:ver}}--{{:#target}}@') -define( `UNIT_NAME_SERVICE', `UNIT_NAME_BASE%i.service') -define( `UNIT_NAME_API_BASE', `afm-api-$1') -define( `UNIT_NAME_API_SERVICE', `UNIT_NAME_API_BASE($1)@$2.service') -define( `UNIT_NAME_API_SOCKET', `UNIT_NAME_API_BASE($1)@$2.socket') -define( `UNIT_NAME_BINDING_BASE', `afm-link-$1') -define( `UNIT_NAME_BINDING_SERVICE', `UNIT_NAME_BINDING_BASE($1)@$2.service') -define( `APP_DATA_DIR', `/home/%i/app-data') -define( `USER_RUN_DIR', `@afm_users_rundir@/%i') -define( `DEBUGGING_DIR', `@afm_platform_rundir@/debug') -define( `API_PATH', `USER_RUN_DIR/apis') -define( `API_PATH_WS', `API_PATH/ws') -define( `API_PATH_LINK', `API_PATH/link') - ------------------------------------------------------------------------ --- -define( `ON_AGL_DEVEL', `ifdef(`AGL_DEVEL', $1, $2)') -define( `IF_AGL_DEVEL', `IF(ON_AGL_DEVEL(1,0))') - divert(0)dnl -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- ; File: ; ; afm-unit.conf @@ -144,16 +82,28 @@ divert(0)dnl ; Records the installation directory path in the field "wgtdir" ; of the private object only. ; -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- +;---- F O R E A C H T A R G E T ---- +;------------------------------------------------------------------------------- {{#targets}} - +;------------------------------------------------------------------------------- include(service.inc) - +;------------------------------------------------------------------------------- +;---- F O R E A C H P R O V I D E D A P I S ---- +;------------------------------------------------------------------------------- +{{#provided-api}} +{{#value=ws|auto}} include(provided-api.inc) - +{{/value=ws|auto}} +{{/provided-api}} +;------------------------------------------------------------------------------- +;---- F O R E A C H P R O V I D E D B I N D I N G ---- +;------------------------------------------------------------------------------- +{{#provided-binding}} include(provided-binding.inc) - +{{/provided-binding}} +;------------------------------------------------------------------------------- {{/targets}} -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- ; End of file afm-unit.conf mode ON_AGL_DEVEL(DEVEL, RELEASE) -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- diff --git a/conf/unit/generate-unit-conf/macros.inc b/conf/unit/generate-unit-conf/macros.inc new file mode 100644 index 0000000..a764765 --- /dev/null +++ b/conf/unit/generate-unit-conf/macros.inc @@ -0,0 +1,67 @@ +dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: +-------------------------------------------------------------------------------- +-- GLOBAL IMPORTANT DEFINITIONS +-------------------------------------------------------------------------------- +define( `X_EMITS', 1) +define( `X_DIVERTS', `divert(eval(-!X_EMITS()))') +define( `X_PUSH_DIVERTS', `pushdef(`X_EMITS', eval(X_EMITS() && $1))X_DIVERTS()') + +define( `X_IF', `pushdef(`X_COND', $1)X_PUSH_DIVERTS($1)') +define( `X_ELSE', `popdef(`X_EMITS')X_PUSH_DIVERTS(eval(!X_COND))') +define( `X_ELIF', `X_ELSE()X_IF($1)') +define( `X_ENDIF', `popdef(`X_EMITS')popdef(`X_COND')X_DIVERTS()') + +define( `IF', `pushdef(`ELSE',`X_ELSE()')pushdef(`ELIF',`X_ELIF($1)')pushdef(`ENDIF',`X_ENDIF()popdef(`ELSE',`ELIF',`ENDIF')')X_IF($1)') +-------------------------------------------------------------------------------- +-- MUSTACH SPECIFIC DEFINITIONS +-------------------------------------------------------------------------------- +define( `MUSTACH_ON', `ifelse(`$2',,,`{{#$1}}`$2'{{/$1}}')ifelse(`$3',,,`{{^$1}}`$3'{{/$1}}')') +define( `MUSTACH_IF', `{{#$1}}pushdef(`ELSE',`{{/$1}}{{^$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')') +define( `MUSTACH_IF_NOT', `{{^$1}}pushdef(`ELSE',`{{/$1}}{{#$1}}')pushdef(`ENDIF',`{{/$1}}popdef(`ELSE',`ENDIF')')') +-------------------------------------------------------------------------------- +-- CONDITIONAL HELPERS +-------------------------------------------------------------------------------- +define( `PERM', `@afm_prefix@permission:$1') +define( `REQPERM', `required-permission.PERM($1)') + +define( `ON_PERM', `MUSTACH_ON(REQPERM($1),$2,$3)') +define( `IF_PERM', `MUSTACH_IF(REQPERM($1))') +define( `IF_NOT_PERM', `MUSTACH_IF_NOT(REQPERM($1))') + +define( `ON_CONTENT', `MUSTACH_ON(content.type=$1,$2,$3)') +define( `IF_CONTENT', `MUSTACH_IF(content.type=$1)') +define( `IF_NOT_CONTENT', `MUSTACH_IF_NOT(content.type=$1)') + +define( `ON_VALUE', `MUSTACH_ON(value=$1,$2,$3)') +define( `IF_VALUE', `MUSTACH_IF(value=$1)') +define( `IF_NOT_VALUE', `MUSTACH_IF_NOT(value=$1)') +-------------------------------------------------------------------------------- +-- AFM DEFINITION +-------------------------------------------------------------------------------- +-- NOTE: +-- when home screen will use real ids +-- use TARGET={{:id}}--{{:ver}}--{{:#target}} +-- instead of TARGET={{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}} +-------------------------------------------------------------------------------- +define( `TARGET', `{{idaver}}{{^#target=main}}@{{:#target}}{{/#target=main}}') +define( `NEWTARGET', `{{:id}}--{{:ver}}--{{:#target}}') +define( `UNIT_NAME_BASE', `afm-ON_PERM(`:public:hidden', `service', `appli')-NEWTARGET') +define( `UNIT_NAME_SERVICE', `UNIT_NAME_BASE@%i.service') +define( `UNIT_NAME_API_BASE', `afm-api-$1') +define( `UNIT_NAME_API_SERVICE', `UNIT_NAME_API_BASE($1)@$2.service') +define( `UNIT_NAME_API_SOCKET', `UNIT_NAME_API_BASE($1)@$2.socket') +define( `UNIT_NAME_BINDING_BASE', `afm-link-$1') +define( `UNIT_NAME_BINDING_SERVICE', `UNIT_NAME_BINDING_BASE($1)@$2.service') +define( `APP_DATA_DIR', `/home/%i/app-data') +define( `USER_RUN_DIR', `@afm_users_rundir@/%i') +define( `DEBUGGING_DIR', `@afm_platform_rundir@/debug') +define( `API_PATH', `USER_RUN_DIR/apis') +define( `API_PATH_WS', `API_PATH/ws') +define( `API_PATH_LINK', `API_PATH/link') +-------------------------------------------------------------------------------- +-- AGL_DEVEL SPECIFIC PARTS +-------------------------------------------------------------------------------- +define( `ON_AGL_DEVEL', `ifdef(`AGL_DEVEL', $1, $2)') +define( `ON_NOT_AGL_DEVEL', `ifdef(`AGL_DEVEL', $2, $1)') +define( `IF_AGL_DEVEL', `IF(ON_AGL_DEVEL(1,0))') +define( `IF_NOT_AGL_DEVEL', `IF(ON_AGL_DEVEL(0,1))') diff --git a/conf/unit/generate-unit-conf/provided-api.inc b/conf/unit/generate-unit-conf/provided-api.inc index ddf7c51..bdee6c9 100644 --- a/conf/unit/generate-unit-conf/provided-api.inc +++ b/conf/unit/generate-unit-conf/provided-api.inc @@ -1,11 +1,4 @@ dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: -;------------------------------------------------------------------------------- -;---- P R O V I D E D A P I S ---- -;------------------------------------------------------------------------------- - -{{#provided-api}} -{{#value=ws|auto}} - ;------------------------------------------------------------------------------- ;---- T H E S E R V I C E O F T H E A P I ---- ;------------------------------------------------------------------------------- @@ -60,8 +53,4 @@ Service=UNIT_NAME_SERVICE %end systemd-unit -{{/value=ws|auto}} - -{{/provided-api}} - diff --git a/conf/unit/generate-unit-conf/provided-binding.inc b/conf/unit/generate-unit-conf/provided-binding.inc index 64c453d..3737126 100644 --- a/conf/unit/generate-unit-conf/provided-binding.inc +++ b/conf/unit/generate-unit-conf/provided-binding.inc @@ -1,10 +1,4 @@ dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: -;------------------------------------------------------------------------------- -;---- P R O V I D E D B I N D I N G ---- -;------------------------------------------------------------------------------- - -{{#provided-binding}} - ;------------------------------------------------------------------------------- ;---- T H E S E R V I C E O F T H E B I N D I N G ---- ;------------------------------------------------------------------------------- @@ -28,6 +22,4 @@ ExecStart=/bin/ln -sf {{:#metadata.install-dir}}/{{value}} API_PATH_LINK/{{name} %end systemd-unit -{{/provided-binding}} - diff --git a/conf/unit/generate-unit-conf/service.inc b/conf/unit/generate-unit-conf/service.inc index dd585d5..88c1454 100644 --- a/conf/unit/generate-unit-conf/service.inc +++ b/conf/unit/generate-unit-conf/service.inc @@ -1,14 +1,14 @@ dnl vim: set filetype=sysctl.conf.m4 syntax=sysctl.conf.m4: -;--------------------------------------------------------------------------------- -;---- M A I N P A R T O F T H E S E R V I C E ---- -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- +;---- M A I N P A R T O F T H E S E R V I C E ---- +;------------------------------------------------------------------------------- %begin systemd-unit # auto generated by wgtpkg-unit for {{:id}} version {{:version}} target {{:#target}} of {{:idaver}} %nl %systemd-unit system -%systemd-unit service UNIT_NAME_BASE +%systemd-unit service UNIT_NAME_BASE@ [Unit] Description={{description}} @@ -105,24 +105,24 @@ StandardInput=null StandardOutput=journal StandardError=journal -;--------------------------------------------------------------------------------- -;---- text/html application/vnd.agl.native application/vnd.agl.service ---- -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- +;---- text/html application/vnd.agl.native application/vnd.agl.service ---- +;------------------------------------------------------------------------------- {{#content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} include(binder.inc) {{/content.type=text/html|application/vnd.agl.native|application/vnd.agl.service}} -;--------------------------------------------------------------------------------- -;---- application/x-executable ---- -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- +;---- application/x-executable ---- +;------------------------------------------------------------------------------- {{#content.type=application/x-executable}} ExecStart={{:#metadata.install-dir}}/{{content.src}} {{/content.type=application/x-executable}} IF_PERM(:system:run-by-default) -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- ; auto start -;--------------------------------------------------------------------------------- +;------------------------------------------------------------------------------- [Install] WantedBy=afm-user-session@.target %systemd-unit wanted-by afm-user-session@.target -- cgit 1.2.3-korg