[pacman-dev] [PATCH] makepkg-template: support multiple --template-dirs
Especially when maintaining local templates in addition to the ones stored in /usr/share/makepkg-template, it can be useful to include templates stored in multiple different locations into one PKGBUILD. This patch makes this possible by allowing --template-dir to be specified multiple times. This also introduces a dedicated error message when a template cannot be found, in contrast to the already existing "Couldn't detect version for template '%s'". If a template of the same name is present in more than one of the given directories, the last one always takes precedence. Neither the default behaviour without the option given, nor the handling of a single template dir is changed. Signed-off-by: Dominik Fischer <d.f.fischer@web.de> --- I reused some already translated strings for the new error message. Perhaps a new string should be introduced here, but I do not know what to do to update the translation files appropriately. doc/makepkg-template.1.txt | 4 +++- scripts/makepkg-template.pl.in | 41 ++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/doc/makepkg-template.1.txt b/doc/makepkg-template.1.txt index a0a6303..03b2a38 100644 --- a/doc/makepkg-template.1.txt +++ b/doc/makepkg-template.1.txt @@ -72,7 +72,9 @@ Options Always use the newest available template file. *\--template-dir* <dir>:: - Change the dir where we are looking for template files. + Change the dir where we are looking for template files. This option may be + given multiple times in which case files found in directory given last will + take precedence. Example PKGBUILD diff --git a/scripts/makepkg-template.pl.in b/scripts/makepkg-template.pl.in index 71d2aae..6fc0171 100755 --- a/scripts/makepkg-template.pl.in +++ b/scripts/makepkg-template.pl.in @@ -27,7 +27,7 @@ use Module::Load::Conditional qw(can_load); my %opts = ( input => '@BUILDSCRIPT@', - template_dir => '@TEMPLATE_DIR@', + template_dir => ['@TEMPLATE_DIR@'], ); my $template_name_charset = qr/[[:alnum:]+_.@-]/; @@ -98,26 +98,33 @@ sub load_template { my $ret = ""; - my $path; + my $template_name = "$values->{name}"; if (!$opts{newest} and $values->{version}) { - $path = "$opts{template_dir}/$values->{name}-$values->{version}.template"; - } else { - $path = "$opts{template_dir}/$values->{name}.template"; + $template_name .= "-$values->{version}"; } + $template_name .= ".template"; - # resolve symlink(s) and use the real file's name for version detection - my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/); - - if (!$version) { - die sprintf(gettext("Couldn't detect version for template '%s'\n"), $values->{name}); - } + my $path; + foreach my $dir (reverse @{$opts{template_dir}}) { + $path = "$dir/$template_name"; + if ( -e $path ) { + # resolve symlink(s) and use the real file's name for version detection + my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/); + + if (!$version) { + die sprintf(gettext("Couldn't detect version for template '%s'\n"), $values->{name}); + } - my $parsed = process_file($path); + my $parsed = process_file($path); - $ret .= "# template start; name=$values->{name}; version=$version;\n"; - $ret .= $parsed; - $ret .= "# template end;\n"; - return $ret; + $ret .= "# template start; name=$values->{name}; version=$version;\n"; + $ret .= $parsed; + $ret .= "# template end;\n"; + return $ret; + } + } + die sprintf(gettext("failed to open '%s': %s\n"), $values->{name}, + sprintf(gettext("File '%s' not found."), $template_name)); } # process input file and load templates for all markers found @@ -199,7 +206,7 @@ GetOptions( "input|p=s" => \$opts{input}, "output|o=s" => \$opts{output}, "newest|n" => \$opts{newest}, - "template-dir=s" => \$opts{template_dir}, + "template-dir=s@" => \$opts{template_dir}, ) or usage(1); $opts{output} = $opts{input} unless $opts{output}; -- 2.3.5
On 22.04.2015 20:37, Dominik Fischer wrote:
Especially when maintaining local templates in addition to the ones stored in /usr/share/makepkg-template, it can be useful to include templates stored in multiple different locations into one PKGBUILD. This patch makes this possible by allowing --template-dir to be specified multiple times.
This also introduces a dedicated error message when a template cannot be found, in contrast to the already existing "Couldn't detect version for template '%s'".
If a template of the same name is present in more than one of the given directories, the last one always takes precedence.
Neither the default behaviour without the option given, nor the handling of a single template dir is changed.
Signed-off-by: Dominik Fischer <d.f.fischer@web.de> --- I reused some already translated strings for the new error message. Perhaps a new string should be introduced here, but I do not know what to do to update the translation files appropriately.
Just use gettext in your code, the translation files will be updated upon release. Also please make sure to adapt the existing tests (you broke a couple) and maybe add a test or two. They are in ./test/scripts/makepkg-template-tests/. Run them with make check and make distcheck (make sure both work).
Especially when maintaining local templates in addition to the ones stored in /usr/share/makepkg-template, it can be useful to include templates stored in multiple different locations into one PKGBUILD. This patch makes this possible by allowing --template-dir to be specified multiple times. If a template of the same name is present in more than one of the given directories, the last one always takes precedence. Neither the default behaviour without the option given, nor the handling of a single template dir is changed. Signed-off-by: Dominik Fischer <d.f.fischer@web.de> --- v2: - Templates are always checked to exist before process_file is ever called, so I moved the error message used therein up. No need for a new string any more. - Tests were adapted to the slight message and error code changes. doc/makepkg-template.1.txt | 4 ++- scripts/makepkg-template.pl.in | 42 ++++++++++++---------- .../compose-multiple-template-dirs/PKGBUILD | 5 +++ .../templates/build/build-1.template | 1 + .../templates/package/package-1.template | 1 + .../compose-multiple-template-dirs/testcase-config | 18 ++++++++++ .../last-template-dir-has-precedece/PKGBUILD | 4 +++ .../PKGBUILD.expanded | 6 ++++ .../templates/first/perl-module-1.0.template | 1 + .../templates/last/perl-module-1.0.template | 1 + .../testcase-config | 15 ++++++++ .../missing-template-file/testcase-config | 2 +- .../missing-template-symlink/testcase-config | 4 +-- 13 files changed, 82 insertions(+), 22 deletions(-) create mode 100644 test/scripts/makepkg-template-tests/compose-multiple-template-dirs/PKGBUILD create mode 100644 test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/build/build-1.template create mode 100644 test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/package/package-1.template create mode 100644 test/scripts/makepkg-template-tests/compose-multiple-template-dirs/testcase-config create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD.expanded create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/first/perl-module-1.0.template create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/last/perl-module-1.0.template create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/testcase-config diff --git a/doc/makepkg-template.1.txt b/doc/makepkg-template.1.txt index a0a6303..03b2a38 100644 --- a/doc/makepkg-template.1.txt +++ b/doc/makepkg-template.1.txt @@ -72,7 +72,9 @@ Options Always use the newest available template file. *\--template-dir* <dir>:: - Change the dir where we are looking for template files. + Change the dir where we are looking for template files. This option may be + given multiple times in which case files found in directory given last will + take precedence. Example PKGBUILD diff --git a/scripts/makepkg-template.pl.in b/scripts/makepkg-template.pl.in index 71d2aae..49e0e37 100755 --- a/scripts/makepkg-template.pl.in +++ b/scripts/makepkg-template.pl.in @@ -27,7 +27,7 @@ use Module::Load::Conditional qw(can_load); my %opts = ( input => '@BUILDSCRIPT@', - template_dir => '@TEMPLATE_DIR@', + template_dir => ['@TEMPLATE_DIR@'], ); my $template_name_charset = qr/[[:alnum:]+_.@-]/; @@ -98,26 +98,32 @@ sub load_template { my $ret = ""; - my $path; + my $template_name = "$values->{name}"; if (!$opts{newest} and $values->{version}) { - $path = "$opts{template_dir}/$values->{name}-$values->{version}.template"; - } else { - $path = "$opts{template_dir}/$values->{name}.template"; + $template_name .= "-$values->{version}"; } + $template_name .= ".template"; - # resolve symlink(s) and use the real file's name for version detection - my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/); - - if (!$version) { - die sprintf(gettext("Couldn't detect version for template '%s'\n"), $values->{name}); - } + my $path; + foreach my $dir (reverse @{$opts{template_dir}}) { + $path = "$dir/$template_name"; + if ( -e $path ) { + # resolve symlink(s) and use the real file's name for version detection + my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/); + + if (!$version) { + die sprintf(gettext("Couldn't detect version for template '%s'\n"), $values->{name}); + } - my $parsed = process_file($path); + my $parsed = process_file($path); - $ret .= "# template start; name=$values->{name}; version=$version;\n"; - $ret .= $parsed; - $ret .= "# template end;\n"; - return $ret; + $ret .= "# template start; name=$values->{name}; version=$version;\n"; + $ret .= $parsed; + $ret .= "# template end;\n"; + return $ret; + } + } + die sprintf(gettext("failed to open '%s': %s\n"), $template_name, $!) } # process input file and load templates for all markers found @@ -128,7 +134,7 @@ sub process_file { my $nesting_level = 0; my $linenumber = 0; - open (my $fh, "<", $filename) or die sprintf(gettext("failed to open '%s': %s\n"), $filename, $!); + open (my $fh, "<", $filename); my @lines = <$fh>; close $fh; @@ -199,7 +205,7 @@ GetOptions( "input|p=s" => \$opts{input}, "output|o=s" => \$opts{output}, "newest|n" => \$opts{newest}, - "template-dir=s" => \$opts{template_dir}, + "template-dir=s@" => \$opts{template_dir}, ) or usage(1); $opts{output} = $opts{input} unless $opts{output}; diff --git a/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/PKGBUILD b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/PKGBUILD new file mode 100644 index 0000000..f8e09f8 --- /dev/null +++ b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/PKGBUILD @@ -0,0 +1,5 @@ +pkgname=foo +pkgver=1 + +# template input; name=build; version=1; +# template input; name=package; version=1; diff --git a/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/build/build-1.template b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/build/build-1.template new file mode 100644 index 0000000..81f2745 --- /dev/null +++ b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/build/build-1.template @@ -0,0 +1 @@ +build() {} diff --git a/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/package/package-1.template b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/package/package-1.template new file mode 100644 index 0000000..056096f --- /dev/null +++ b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/package/package-1.template @@ -0,0 +1 @@ +package() {} diff --git a/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/testcase-config b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/testcase-config new file mode 100644 index 0000000..3c58a61 --- /dev/null +++ b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/testcase-config @@ -0,0 +1,18 @@ +arguments+=(--template-dir $testdir/$testcase/templates/build) +arguments+=(--template-dir $testdir/$testcase/templates/package) +expected_exitcode=0 + +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +pkgname=foo +pkgver=1 + +# template start; name=build; version=1; +build() {} +# template end; +# template start; name=package; version=1; +package() {} +# template end; +EOF diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD new file mode 100644 index 0000000..2813b75 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD @@ -0,0 +1,4 @@ +pkgname=foo +pkgver=1 + +# template input; name=perl-module; version=1.0; diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD.expanded b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD.expanded new file mode 100644 index 0000000..c1dbeb4 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD.expanded @@ -0,0 +1,6 @@ +pkgname=foo +pkgver=1 + +# template start; name=perl-module; version=1.0; +this should be included +# template end; diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/first/perl-module-1.0.template b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/first/perl-module-1.0.template new file mode 100644 index 0000000..2649f78 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/first/perl-module-1.0.template @@ -0,0 +1 @@ +this should be overwritten diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/last/perl-module-1.0.template b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/last/perl-module-1.0.template new file mode 100644 index 0000000..409e8d4 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/last/perl-module-1.0.template @@ -0,0 +1 @@ +this should be included diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/testcase-config b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/testcase-config new file mode 100644 index 0000000..fe38d65 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/testcase-config @@ -0,0 +1,15 @@ +arguments+=(--template-dir $testdir/$testcase/templates/first) +arguments+=(--template-dir $testdir/$testcase/templates/last) +expected_exitcode=0 + +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +pkgname=foo +pkgver=1 + +# template start; name=perl-module; version=1.0; +this should be included +# template end; +EOF diff --git a/test/scripts/makepkg-template-tests/missing-template-file/testcase-config b/test/scripts/makepkg-template-tests/missing-template-file/testcase-config index bdfde40..44444e4 100644 --- a/test/scripts/makepkg-template-tests/missing-template-file/testcase-config +++ b/test/scripts/makepkg-template-tests/missing-template-file/testcase-config @@ -7,7 +7,7 @@ _setup_testcase() { # set IFS="" if you want trailing new lines, otherwise remove it IFS="" read -d '' expected_output <<'EOF' -failed to open './makepkg-template-tests/missing-template-file/templates/perl-module-1.0.template': No such file or directory +failed to open 'perl-module-1.0.template': No such file or directory EOF IFS="" read -d '' expected_result <<'EOF' diff --git a/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config b/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config index c0eabe0..0654328 100644 --- a/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config +++ b/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config @@ -1,8 +1,8 @@ arguments+=() -expected_exitcode=255 +expected_exitcode=2 IFS="" read -d '' expected_output <<'EOF' -Couldn't detect version for template 'perl-module' +failed to open 'perl-module.template': No such file or directory EOF IFS="" read -d '' expected_result <<'EOF' -- 2.3.5
On 23.04.2015 13:59, Dominik Fischer wrote:
diff --git a/scripts/makepkg-template.pl.in b/scripts/makepkg-template.pl.in index 71d2aae..49e0e37 100755 --- a/scripts/makepkg-template.pl.in +++ b/scripts/makepkg-template.pl.in @@ -98,26 +98,32 @@ sub load_template {
my $ret = "";
- my $path; + my $template_name = "$values->{name}"; if (!$opts{newest} and $values->{version}) { - $path = "$opts{template_dir}/$values->{name}-$values->{version}.template"; - } else { - $path = "$opts{template_dir}/$values->{name}.template"; + $template_name .= "-$values->{version}"; } + $template_name .= ".template";
- # resolve symlink(s) and use the real file's name for version detection - my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/); - - if (!$version) { - die sprintf(gettext("Couldn't detect version for template '%s'\n"), $values->{name}); - } + my $path;
Please declare $path inside the loop.
+ foreach my $dir (reverse @{$opts{template_dir}}) { + $path = "$dir/$template_name"; + if ( -e $path ) { + # resolve symlink(s) and use the real file's name for version detection + my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/); + + if (!$version) { + die sprintf(gettext("Couldn't detect version for template '%s'\n"), $values->{name});
Since we now have multiple dirs this could be ambiguous and should probably use $path in the error instead of $values->{name}.
+ }
- my $parsed = process_file($path); + my $parsed = process_file($path);
- $ret .= "# template start; name=$values->{name}; version=$version;\n"; - $ret .= $parsed; - $ret .= "# template end;\n"; - return $ret; + $ret .= "# template start; name=$values->{name}; version=$version;\n"; + $ret .= $parsed; + $ret .= "# template end;\n"; + return $ret; + } + } + die sprintf(gettext("failed to open '%s': %s\n"), $template_name, $!)
You don't actually fail to open anything, you fail to find a matching template. die sprintf(gettext("Failed to find template file matching '%s'), $template_name); would better reflect that.
@@ -128,7 +134,7 @@ sub process_file { my $nesting_level = 0; my $linenumber = 0;
- open (my $fh, "<", $filename) or die sprintf(gettext("failed to open '%s': %s\n"), $filename, $!); + open (my $fh, "<", $filename);
Removing this die introduces a race condition and issues when the file has wrong permissions and is not readable (-e will succeed, open will not). I'd say keep it here (the way it was) in addition to the die after the for loop above. They catch different kinds of errors. The rest of the patch and the tests look good.
Especially when maintaining local templates in addition to the ones stored in /usr/share/makepkg-template, it can be useful to include templates stored in multiple different locations into one PKGBUILD. This patch makes this possible by allowing --template-dir to be specified multiple times. This also introduces a dedicated error message when a template cannot be found, in contrast to the already existing "Couldn't detect version for template '%s'". If a template of the same name is present in more than one of the given directories, the last one always takes precedence. Neither the default behaviour without the option given, nor the handling of a single template dir is changed. Signed-off-by: Dominik Fischer <d.f.fischer@web.de> --- v3 incorporates changes suggested in feedback from Florian Pritz: - Declare $path inside loop, - use full path in error message about failed version detection, - use dedicated error message for templates not found, - keep error handling of unreadable files. doc/makepkg-template.1.txt | 4 ++- scripts/makepkg-template.pl.in | 37 ++++++++++++---------- .../compose-multiple-template-dirs/PKGBUILD | 5 +++ .../templates/build/build-1.template | 1 + .../templates/package/package-1.template | 1 + .../compose-multiple-template-dirs/testcase-config | 18 +++++++++++ .../last-template-dir-has-precedece/PKGBUILD | 4 +++ .../PKGBUILD.expanded | 6 ++++ .../templates/first/perl-module-1.0.template | 1 + .../templates/last/perl-module-1.0.template | 1 + .../testcase-config | 15 +++++++++ .../missing-template-file/testcase-config | 2 +- .../missing-template-symlink/testcase-config | 4 +-- .../template-without-version/testcase-config | 2 +- 14 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 test/scripts/makepkg-template-tests/compose-multiple-template-dirs/PKGBUILD create mode 100644 test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/build/build-1.template create mode 100644 test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/package/package-1.template create mode 100644 test/scripts/makepkg-template-tests/compose-multiple-template-dirs/testcase-config create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD.expanded create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/first/perl-module-1.0.template create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/last/perl-module-1.0.template create mode 100644 test/scripts/makepkg-template-tests/last-template-dir-has-precedece/testcase-config diff --git a/doc/makepkg-template.1.txt b/doc/makepkg-template.1.txt index a0a6303..03b2a38 100644 --- a/doc/makepkg-template.1.txt +++ b/doc/makepkg-template.1.txt @@ -72,7 +72,9 @@ Options Always use the newest available template file. *\--template-dir* <dir>:: - Change the dir where we are looking for template files. + Change the dir where we are looking for template files. This option may be + given multiple times in which case files found in directory given last will + take precedence. Example PKGBUILD diff --git a/scripts/makepkg-template.pl.in b/scripts/makepkg-template.pl.in index 71d2aae..9877796 100755 --- a/scripts/makepkg-template.pl.in +++ b/scripts/makepkg-template.pl.in @@ -27,7 +27,7 @@ use Module::Load::Conditional qw(can_load); my %opts = ( input => '@BUILDSCRIPT@', - template_dir => '@TEMPLATE_DIR@', + template_dir => ['@TEMPLATE_DIR@'], ); my $template_name_charset = qr/[[:alnum:]+_.@-]/; @@ -98,26 +98,31 @@ sub load_template { my $ret = ""; - my $path; + my $template_name = "$values->{name}"; if (!$opts{newest} and $values->{version}) { - $path = "$opts{template_dir}/$values->{name}-$values->{version}.template"; - } else { - $path = "$opts{template_dir}/$values->{name}.template"; + $template_name .= "-$values->{version}"; } + $template_name .= ".template"; - # resolve symlink(s) and use the real file's name for version detection - my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/); + foreach my $dir (reverse @{$opts{template_dir}}) { + my $path = "$dir/$template_name"; + if ( -e $path ) { + # resolve symlink(s) and use the real file's name for version detection + my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/); - if (!$version) { - die sprintf(gettext("Couldn't detect version for template '%s'\n"), $values->{name}); - } + if (!$version) { + die sprintf(gettext("Couldn't detect version for template '%s'\n"), $path); + } - my $parsed = process_file($path); + my $parsed = process_file($path); - $ret .= "# template start; name=$values->{name}; version=$version;\n"; - $ret .= $parsed; - $ret .= "# template end;\n"; - return $ret; + $ret .= "# template start; name=$values->{name}; version=$version;\n"; + $ret .= $parsed; + $ret .= "# template end;\n"; + return $ret; + } + } + die sprintf(gettext("Failed to find template file matching '%s'\n"), $template_name); } # process input file and load templates for all markers found @@ -199,7 +204,7 @@ GetOptions( "input|p=s" => \$opts{input}, "output|o=s" => \$opts{output}, "newest|n" => \$opts{newest}, - "template-dir=s" => \$opts{template_dir}, + "template-dir=s@" => \$opts{template_dir}, ) or usage(1); $opts{output} = $opts{input} unless $opts{output}; diff --git a/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/PKGBUILD b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/PKGBUILD new file mode 100644 index 0000000..f8e09f8 --- /dev/null +++ b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/PKGBUILD @@ -0,0 +1,5 @@ +pkgname=foo +pkgver=1 + +# template input; name=build; version=1; +# template input; name=package; version=1; diff --git a/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/build/build-1.template b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/build/build-1.template new file mode 100644 index 0000000..81f2745 --- /dev/null +++ b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/build/build-1.template @@ -0,0 +1 @@ +build() {} diff --git a/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/package/package-1.template b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/package/package-1.template new file mode 100644 index 0000000..056096f --- /dev/null +++ b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/templates/package/package-1.template @@ -0,0 +1 @@ +package() {} diff --git a/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/testcase-config b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/testcase-config new file mode 100644 index 0000000..3c58a61 --- /dev/null +++ b/test/scripts/makepkg-template-tests/compose-multiple-template-dirs/testcase-config @@ -0,0 +1,18 @@ +arguments+=(--template-dir $testdir/$testcase/templates/build) +arguments+=(--template-dir $testdir/$testcase/templates/package) +expected_exitcode=0 + +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +pkgname=foo +pkgver=1 + +# template start; name=build; version=1; +build() {} +# template end; +# template start; name=package; version=1; +package() {} +# template end; +EOF diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD new file mode 100644 index 0000000..2813b75 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD @@ -0,0 +1,4 @@ +pkgname=foo +pkgver=1 + +# template input; name=perl-module; version=1.0; diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD.expanded b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD.expanded new file mode 100644 index 0000000..c1dbeb4 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/PKGBUILD.expanded @@ -0,0 +1,6 @@ +pkgname=foo +pkgver=1 + +# template start; name=perl-module; version=1.0; +this should be included +# template end; diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/first/perl-module-1.0.template b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/first/perl-module-1.0.template new file mode 100644 index 0000000..2649f78 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/first/perl-module-1.0.template @@ -0,0 +1 @@ +this should be overwritten diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/last/perl-module-1.0.template b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/last/perl-module-1.0.template new file mode 100644 index 0000000..409e8d4 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/templates/last/perl-module-1.0.template @@ -0,0 +1 @@ +this should be included diff --git a/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/testcase-config b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/testcase-config new file mode 100644 index 0000000..fe38d65 --- /dev/null +++ b/test/scripts/makepkg-template-tests/last-template-dir-has-precedece/testcase-config @@ -0,0 +1,15 @@ +arguments+=(--template-dir $testdir/$testcase/templates/first) +arguments+=(--template-dir $testdir/$testcase/templates/last) +expected_exitcode=0 + +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +pkgname=foo +pkgver=1 + +# template start; name=perl-module; version=1.0; +this should be included +# template end; +EOF diff --git a/test/scripts/makepkg-template-tests/missing-template-file/testcase-config b/test/scripts/makepkg-template-tests/missing-template-file/testcase-config index bdfde40..2fc400e 100644 --- a/test/scripts/makepkg-template-tests/missing-template-file/testcase-config +++ b/test/scripts/makepkg-template-tests/missing-template-file/testcase-config @@ -7,7 +7,7 @@ _setup_testcase() { # set IFS="" if you want trailing new lines, otherwise remove it IFS="" read -d '' expected_output <<'EOF' -failed to open './makepkg-template-tests/missing-template-file/templates/perl-module-1.0.template': No such file or directory +Failed to find template file matching 'perl-module-1.0.template' EOF IFS="" read -d '' expected_result <<'EOF' diff --git a/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config b/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config index c0eabe0..8f4c8b8 100644 --- a/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config +++ b/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config @@ -1,8 +1,8 @@ arguments+=() -expected_exitcode=255 +expected_exitcode=2 IFS="" read -d '' expected_output <<'EOF' -Couldn't detect version for template 'perl-module' +Failed to find template file matching 'perl-module.template' EOF IFS="" read -d '' expected_result <<'EOF' diff --git a/test/scripts/makepkg-template-tests/template-without-version/testcase-config b/test/scripts/makepkg-template-tests/template-without-version/testcase-config index ec04f2f..b078f51 100644 --- a/test/scripts/makepkg-template-tests/template-without-version/testcase-config +++ b/test/scripts/makepkg-template-tests/template-without-version/testcase-config @@ -2,7 +2,7 @@ arguments+=() expected_exitcode=255 IFS="" read -d '' expected_output <<'EOF' -Couldn't detect version for template 'template-without_version' +Couldn't detect version for template './makepkg-template-tests/template-without-version/templates/template-without_version.template' EOF IFS="" read -d '' expected_result <<'EOF' -- 2.3.5
On 23.04.2015 16:41, Dominik Fischer wrote:
Especially when maintaining local templates in addition to the ones stored in /usr/share/makepkg-template, it can be useful to include templates stored in multiple different locations into one PKGBUILD. This patch makes this possible by allowing --template-dir to be specified multiple times.
This also introduces a dedicated error message when a template cannot be found, in contrast to the already existing "Couldn't detect version for template '%s'".
If a template of the same name is present in more than one of the given directories, the last one always takes precedence.
Neither the default behaviour without the option given, nor the handling of a single template dir is changed.
Signed-off-by: Dominik Fischer <d.f.fischer@web.de>
Signed-off-by: Florian Pritz <bluewind@xinu.at> Also pulled into my working branch for easy merging (already includes the signoff).
participants (2)
-
Dominik Fischer
-
Florian Pritz