Skip to content

Commit

Permalink
Merge pull request #853 from sappo/master
Browse files Browse the repository at this point in the history
New snippet interface
  • Loading branch information
bluca committed Feb 3, 2017
2 parents dfb1af3 + 85c6a1f commit de9a672
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 158 deletions.
218 changes: 158 additions & 60 deletions README.md

Large diffs are not rendered by default.

39 changes: 38 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,44 @@ with --with-systemd-units.

**config**
This will install additional configuration files to
$(sysconfdir)/$(project.name)/$(name).
$\(sysconfdir)/$\(project.name)/$\(name).

## Notes for Writing Targets

### Snippets

If you write a new target or extend one you might be in the situtation where you
need to put code fragments into files which are not specific to your target. For
example the `systemd` target has to extend files from the `autotools`, `debian`
and `redhat` targets. In order to keep those files as maintainable as possible
you'll include a snippet which is pull from your targets file. To include
a snippet call:

```
insert_snippet (target)
```

Where target is the identifier for the insertion point i.e. the filename. To
register a snippet to be inserted simply call.

```
register_snippet (target, name)
```

Target is must match the one in `insert_snippet` and the name identifies your
snippet. Then you can create a function or macro with the following form
(without the brackets):

```
function snippet_<target>_<name>

.macro snippet_<target>_<name>
```

This function will be called by the `insert_snippet` function. You can have an
arbitrary amount of registered snippets per insertion point which will be
inserted in arbitrary order so don't make any assumption on the order of the
snippets per insertion point.

## Notes for Writing Language Targets

Expand Down
Empty file removed builds/zinstall/Makemodule.am
Empty file.
Empty file removed builds/zinstall/configure.ac
Empty file.
Empty file removed builds/zinstall/zproject.install
Empty file.
Empty file removed builds/zinstall/zproject.spec
Empty file.
2 changes: 1 addition & 1 deletion packaging/debian/zproject.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ usr/bin/zproject_bench.gsl
usr/bin/zproject_class.gsl
usr/bin/zproject_git.gsl
usr/bin/zproject_valgrind.gsl
usr/bin/zproject_install.gsl
usr/bin/zproject_android.gsl
usr/bin/zproject_autotools.gsl
usr/bin/zproject_cmake.gsl
Expand All @@ -29,6 +28,7 @@ usr/bin/zproject_qt.gsl
usr/bin/zproject_redhat.gsl
usr/bin/zproject_rpi.gsl
usr/bin/zproject_ruby.gsl
usr/bin/zproject_systemd.gsl
usr/bin/zproject_travis.gsl
usr/bin/zproject_vagrant.gsl
usr/bin/zproject_vs2008.gsl
Expand Down
2 changes: 1 addition & 1 deletion packaging/redhat/zproject.spec
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ find %{buildroot} -name '*.la' | xargs rm -f
%{_bindir}/zproject_class.gsl
%{_bindir}/zproject_git.gsl
%{_bindir}/zproject_valgrind.gsl
%{_bindir}/zproject_install.gsl
%{_bindir}/zproject_android.gsl
%{_bindir}/zproject_autotools.gsl
%{_bindir}/zproject_cmake.gsl
Expand All @@ -97,6 +96,7 @@ find %{buildroot} -name '*.la' | xargs rm -f
%{_bindir}/zproject_redhat.gsl
%{_bindir}/zproject_rpi.gsl
%{_bindir}/zproject_ruby.gsl
%{_bindir}/zproject_systemd.gsl
%{_bindir}/zproject_travis.gsl
%{_bindir}/zproject_vagrant.gsl
%{_bindir}/zproject_vs2008.gsl
Expand Down
4 changes: 1 addition & 3 deletions project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@
<bin name = "zproject_git.gsl" />
<bin name = "zproject_valgrind.gsl" />

<!-- zinstall must run before all the targets -->
<bin name = "zproject_install.gsl" />

<!-- Targets -->
<bin name = "zproject_android.gsl" />
<bin name = "zproject_autotools.gsl" />
Expand All @@ -202,6 +199,7 @@
<bin name = "zproject_redhat.gsl" />
<bin name = "zproject_rpi.gsl" />
<bin name = "zproject_ruby.gsl" />
<bin name = "zproject_systemd.gsl" />
<bin name = "zproject_travis.gsl" />
<bin name = "zproject_vagrant.gsl" />
<bin name = "zproject_vs2008.gsl" />
Expand Down
2 changes: 1 addition & 1 deletion src/Makemodule.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dist_bin_SCRIPTS = \
zproject_class.gsl \
zproject_git.gsl \
zproject_valgrind.gsl \
zproject_install.gsl \
zproject_android.gsl \
zproject_autotools.gsl \
zproject_cmake.gsl \
Expand All @@ -42,6 +41,7 @@ dist_bin_SCRIPTS = \
zproject_redhat.gsl \
zproject_rpi.gsl \
zproject_ruby.gsl \
zproject_systemd.gsl \
zproject_travis.gsl \
zproject_vagrant.gsl \
zproject_vs2008.gsl \
Expand Down
17 changes: 14 additions & 3 deletions zproject.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ function chmod_x (filename)
my.shell.run ()
endfunction

function register_snippet (target, name)
new snippet to project
snippet.target = my.target
snippet.name = my.name
endnew
endfunction

function insert_snippet (target)
for project.snippet where snippet.target = my.target
snippet_$(snippet.target:c)_$(snippet.name:c) ()
endfor
endfunction

function register_target (target, detail)
new handler to project
handler.target = my.target
Expand Down Expand Up @@ -172,9 +185,6 @@ gsl from "zproject_bench.gsl"
gsl from "zproject_git.gsl"
gsl from "zproject_valgrind.gsl"

# zinstall must run before all the targets
gsl from "zproject_install.gsl"

# Load all targets
gsl from "zproject_android.gsl"
gsl from "zproject_autotools.gsl"
Expand All @@ -197,6 +207,7 @@ gsl from "zproject_qt.gsl"
gsl from "zproject_redhat.gsl"
gsl from "zproject_rpi.gsl"
gsl from "zproject_ruby.gsl"
gsl from "zproject_systemd.gsl"
gsl from "zproject_travis.gsl"
gsl from "zproject_vagrant.gsl"
gsl from "zproject_vs2008.gsl"
Expand Down
4 changes: 2 additions & 2 deletions zproject_autotools.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ AM_COND_IF([WITH_SYSTEMD_UNITS],
[])

.endif
.zinstall_include ("builds/zinstall/configure.ac")
.insert_snippet ("configure.ac")
AC_OUTPUT

# Print configure summary and list make options
Expand Down Expand Up @@ -1260,7 +1260,7 @@ coverage: src/$(project.prefix)_selftest
\t@echo "call make clean && configure --with-gcov to enable code coverage"
\t@exit 1
endif
.zinstall_include ("builds/zinstall/Makemodule.am")
.insert_snippet ("Makemodule")

$(project.GENERATED_WARNING_HEADER:)
.close
Expand Down
2 changes: 1 addition & 1 deletion zproject_debian.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ lib/systemd/system/$(main.name).service
lib/systemd/system/$(main.name)@.service
. endif
. endfor
.zinstall_include ("builds/zinstall/$(project.name).install")
.insert_snippet ("debian.install")
.endif

.if project.exports_classes
Expand Down
84 changes: 0 additions & 84 deletions zproject_install.gsl

This file was deleted.

2 changes: 1 addition & 1 deletion zproject_redhat.gsl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ find %{buildroot} -name '*.la' | xargs rm -f
.if etc_exists ?= 1
%dir %{_sysconfdir}/$(project.name)
.endif
.zinstall_include ("builds/zinstall/$(project.name).spec")
.insert_snippet ("redhat.spec")
.if systemd ?= 1
%if 0%{?suse_version} > 1315
%post
Expand Down
86 changes: 86 additions & 0 deletions zproject_systemd.gsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Generate systemd snippets and files for zproject
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/imatix/gsl for details.
#
# Copyright (c) the Contributors as noted in the AUTHORS file.
# This file is part of zproject.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

register_snippet("configure.ac", "systemd")
function snippet_configure_ac_systemd ()
for project.main where defined (main->install)
for install
if install.type = "systemd-tmpfiles"
>AM_COND_IF([WITH_SYSTEMD_UNITS],
> [AC_CONFIG_FILES([
> src/$(main.name).conf
> ])],
> [])
>
elsif install.type = "config"
>AC_CONFIG_FILES([
> src/$(main.name).cfg
>])
>
endif
endfor
endfor
endfunction

register_snippet("Makemodule", "systemd")
function snippet_makemodule_systemd ()
for project.main where defined (main->install)
for install
if install.type = "systemd-tmpfiles"
>if ENABLE_$(MAIN.NAME:c)
>if WITH_SYSTEMD_UNITS
>$(main.name:c)_tmpfiles_ddir = /usr/lib/tmpfiles.d/
>$(main.name:c)_tmpfiles_d_DATA = src/$(main.name).conf
>endif #WITH_SYSTEMD_UNITS
>endif #$(MAIN.NAME:c)
>
elsif install.type = "config"
>if ENABLE_$(MAIN.NAME:c)
>src_$(project.name:c)_config_DATA += src/$(main.name).cfg
>endif
>
endif
endfor
endfor
endfunction

register_snippet("redhat.spec", "systemd")
function snippet_redhat_spec_systemd ()
for project.main where defined (main->install)
for install
if install.type = "systemd-tmpfiles"
>AM_COND_IF([WITH_SYSTEMD_UNITS],
>%dir /usr/lib/tmpfiles.d/
>%config /usr/lib/tmpfiles.d/$(main.name).conf
>
elsif install.type = "config"
>%config (noreplace) %{sysconfdir}/$(project.name)/$(main.name).cfg
>
endif
endfor
endfor
endfunction

register_snippet("debian.install", "systemd")
function snippet_debian_install_systemd ()
for project.main where defined (main->install)
for install
if install.type = "systemd-tmpfiles"
>usr/lib/tmpfiles.d/$(main.name).conf
>
elsif install.type = "config"
>etc/$(project.name)/$(main.name).cfg
endif
endfor
endfor
endfunction

0 comments on commit de9a672

Please sign in to comment.