It may be necessary to just suppress duplication of some templates while others are safe and intended to occur multiple times. As information about the intended duplication cannot easily be placed into the template file itself without additional introspection measures, this patch allows to suppress duplication via an option in the template markers. Signed-off-by: Dominik Fischer <d.f.fischer@web.de> --- doc/makepkg-template.1.txt | 10 +++++++--- scripts/makepkg-template.pl.in | 10 ++++++++-- .../makepkg-template-tests/diamond-input-key/PKGBUILD | 5 +++++ .../diamond-input-key/PKGBUILD.expanded | 10 ++++++++++ .../diamond-input-key/templates/base-1.template | 1 + .../templates/first-include-1.template | 1 + .../templates/second-include-1.template | 1 + .../diamond-input-key/testcase-config | 17 +++++++++++++++++ 8 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 test/scripts/makepkg-template-tests/diamond-input-key/PKGBUILD create mode 100644 test/scripts/makepkg-template-tests/diamond-input-key/PKGBUILD.expanded create mode 100644 test/scripts/makepkg-template-tests/diamond-input-key/templates/base-1.template create mode 100644 test/scripts/makepkg-template-tests/diamond-input-key/templates/first-include-1.template create mode 100644 test/scripts/makepkg-template-tests/diamond-input-key/templates/second-include-1.template create mode 100644 test/scripts/makepkg-template-tests/diamond-input-key/testcase-config diff --git a/doc/makepkg-template.1.txt b/doc/makepkg-template.1.txt index bd2355c..a368b1e 100644 --- a/doc/makepkg-template.1.txt +++ b/doc/makepkg-template.1.txt @@ -34,8 +34,9 @@ and # template end; -Currently used keys are: name (mandatory) and version. Template names are limited to -alphanumerics, "@", "+", ".", "-", and "_". Versions are limited to numbers and ".". +Currently used keys are: name (mandatory), version and duplicate. Template names are +limited to alphanumerics, "@", "+", ".", "-", and "_". Versions are limited to +numbers and ".". For initial creation there is a one line short cut which does not need an end marker: @@ -80,7 +81,10 @@ Options Do not include any template twice, even when templates recursively include other templates. Only the first occurrence of each template will be expanded, all further references to the same name, also with different - version numbers, will be ignored. + version numbers, will be ignored. To only suppress the duplication of + selected templates, add "duplicate=no;" to all relevant template markers. + Note that all occurrences of the template have to be marked, not just the + first one. Example PKGBUILD diff --git a/scripts/makepkg-template.pl.in b/scripts/makepkg-template.pl.in index e9f6e08..5ac8bef 100755 --- a/scripts/makepkg-template.pl.in +++ b/scripts/makepkg-template.pl.in @@ -78,6 +78,8 @@ sub parse_template_line { $values{$key} = $val; } + $values{duplicate} = not(defined($values{duplicate}) and $values{duplicate} =~ /no|false/); + # end doesn't take arguments if ($values{command} ne "end") { if (!$values{name}) { @@ -98,7 +100,7 @@ sub parse_template_line { sub load_template { my ($values) = @_; - if ($opts{dups}) { + if ($opts{dups} or not $values->{duplicate}) { # omit already included templates. if (exists $seen{$values->{name}}) { return ""; @@ -127,7 +129,11 @@ sub load_template { my $parsed = process_file($path); - $ret .= "# template start; name=$values->{name}; version=$version;\n"; + $ret .= "# template start; name=$values->{name}; version=$version;"; + if (not $values->{duplicate}) { + $ret .= " duplicate=no;"; + } + $ret .= "\n"; $ret .= $parsed; $ret .= "# template end;\n"; return $ret; diff --git a/test/scripts/makepkg-template-tests/diamond-input-key/PKGBUILD b/test/scripts/makepkg-template-tests/diamond-input-key/PKGBUILD new file mode 100644 index 0000000..6bb4fa5 --- /dev/null +++ b/test/scripts/makepkg-template-tests/diamond-input-key/PKGBUILD @@ -0,0 +1,5 @@ +pkgname=foo +pkgver=1 + +# template input; name=first-include; version=1; +# template input; name=second-include; version=1; diff --git a/test/scripts/makepkg-template-tests/diamond-input-key/PKGBUILD.expanded b/test/scripts/makepkg-template-tests/diamond-input-key/PKGBUILD.expanded new file mode 100644 index 0000000..c5dc8cd --- /dev/null +++ b/test/scripts/makepkg-template-tests/diamond-input-key/PKGBUILD.expanded @@ -0,0 +1,10 @@ +pkgname=foo +pkgver=1 + +# template start; name=first-include; version=1; +# template start; name=base; version=1;duplicate=false; +package() {} +# template end; +# template end; +# template start; name=second-include; version=1; +# template end; diff --git a/test/scripts/makepkg-template-tests/diamond-input-key/templates/base-1.template b/test/scripts/makepkg-template-tests/diamond-input-key/templates/base-1.template new file mode 100644 index 0000000..056096f --- /dev/null +++ b/test/scripts/makepkg-template-tests/diamond-input-key/templates/base-1.template @@ -0,0 +1 @@ +package() {} diff --git a/test/scripts/makepkg-template-tests/diamond-input-key/templates/first-include-1.template b/test/scripts/makepkg-template-tests/diamond-input-key/templates/first-include-1.template new file mode 100644 index 0000000..3a27d66 --- /dev/null +++ b/test/scripts/makepkg-template-tests/diamond-input-key/templates/first-include-1.template @@ -0,0 +1 @@ +# template input; name=base; version=1; duplicate=no; diff --git a/test/scripts/makepkg-template-tests/diamond-input-key/templates/second-include-1.template b/test/scripts/makepkg-template-tests/diamond-input-key/templates/second-include-1.template new file mode 100644 index 0000000..b862538 --- /dev/null +++ b/test/scripts/makepkg-template-tests/diamond-input-key/templates/second-include-1.template @@ -0,0 +1 @@ +# template input; name=base; version=1; duplicate=false; diff --git a/test/scripts/makepkg-template-tests/diamond-input-key/testcase-config b/test/scripts/makepkg-template-tests/diamond-input-key/testcase-config new file mode 100644 index 0000000..bf86efb --- /dev/null +++ b/test/scripts/makepkg-template-tests/diamond-input-key/testcase-config @@ -0,0 +1,17 @@ +expected_exitcode=0 + +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +pkgname=foo +pkgver=1 + +# template start; name=first-include; version=1; +# template start; name=base; version=1; duplicate=no; +package() {} +# template end; +# template end; +# template start; name=second-include; version=1; +# template end; +EOF -- 2.4.2