Attached is a patch the finishes up the work to move the snowball SQL script generation into a separate script.
From 02ca51dfb918666dfde8e48499a4c73afae4e89e Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 Jun 2022 11:05:31 +0200
Subject: [PATCH] fixup! meson: prereq: move snowball_create.sql creation into
 perl file.

- Remove LANGUAGES list from Makefile, keep in Perl script.
- Add list of stopword files to install.
- Make depfile generation optional.
- Call new Perl script from Install.pm.
---
 src/backend/snowball/Makefile           | 81 ++++++++-----------------
 src/backend/snowball/meson.build        |  3 +-
 src/backend/snowball/snowball_create.pl | 73 +++++++++++++++++-----
 src/tools/msvc/Install.pm               | 36 +----------
 4 files changed, 86 insertions(+), 107 deletions(-)

diff --git a/src/backend/snowball/Makefile b/src/backend/snowball/Makefile
index 259104f8eb..c12a77055d 100644
--- a/src/backend/snowball/Makefile
+++ b/src/backend/snowball/Makefile
@@ -72,40 +72,22 @@ OBJS += \
        stem_UTF_8_turkish.o \
        stem_UTF_8_yiddish.o
 
-# first column is language name and also name of dictionary for not-all-ASCII
-# words, second is name of dictionary for all-ASCII words
-# Note order dependency: use of some other language as ASCII dictionary
-# must come after creation of that language
-LANGUAGES=  \
-       arabic          arabic          \
-       armenian        armenian        \
-       basque          basque          \
-       catalan         catalan         \
-       danish          danish          \
-       dutch           dutch           \
-       english         english         \
-       finnish         finnish         \
-       french          french          \
-       german          german          \
-       greek           greek           \
-       hindi           english         \
-       hungarian       hungarian       \
-       indonesian      indonesian      \
-       irish           irish           \
-       italian         italian         \
-       lithuanian      lithuanian      \
-       nepali          nepali          \
-       norwegian       norwegian       \
-       portuguese      portuguese      \
-       romanian        romanian        \
-       russian         english         \
-       serbian         serbian         \
-       spanish         spanish         \
-       swedish         swedish         \
-       tamil           tamil           \
-       turkish         turkish         \
-       yiddish         yiddish
-
+stop_files = \
+       danish.stop \
+       dutch.stop \
+       english.stop \
+       finnish.stop \
+       french.stop \
+       german.stop \
+       hungarian.stop \
+       italian.stop \
+       nepali.stop \
+       norwegian.stop \
+       portuguese.stop \
+       russian.stop \
+       spanish.stop \
+       swedish.stop \
+       turkish.stop
 
 SQLSCRIPT= snowball_create.sql
 DICTDIR=tsearch_data
@@ -119,35 +101,22 @@ all: all-shared-lib $(SQLSCRIPT)
 
 include $(top_srcdir)/src/Makefile.shlib
 
-$(SQLSCRIPT): snowball_create.pl Makefile snowball_func.sql.in snowball.sql.in
+$(SQLSCRIPT): snowball_create.pl snowball_func.sql.in snowball.sql.in
        $(PERL) $< --input ${srcdir} --output .
 
 install: all installdirs install-lib
        $(INSTALL_DATA) $(SQLSCRIPT) '$(DESTDIR)$(datadir)'
-       @set -e; \
-       set $(LANGUAGES) ; \
-       while [ "$$#" -gt 0 ] ; \
-       do \
-               lang=$$1; shift; shift; \
-               if [ -s $(srcdir)/stopwords/$${lang}.stop ] ; then \
-                       $(INSTALL_DATA) $(srcdir)/stopwords/$${lang}.stop 
'$(DESTDIR)$(datadir)/$(DICTDIR)' ; \
-               fi \
-       done
+       $(INSTALL_DATA) $(addprefix $(srcdir)/stopwords/,$(stop_files)) 
'$(DESTDIR)$(datadir)/$(DICTDIR)'
 
 installdirs: installdirs-lib
        $(MKDIR_P) '$(DESTDIR)$(datadir)' '$(DESTDIR)$(datadir)/$(DICTDIR)'
 
 uninstall: uninstall-lib
        rm -f '$(DESTDIR)$(datadir)/$(SQLSCRIPT)'
-       @set -e; \
-       set $(LANGUAGES) ; \
-       while [ "$$#" -gt 0 ] ; \
-       do \
-               lang=$$1; shift; shift;  \
-               if [ -s $(srcdir)/stopwords/$${lang}.stop ] ; then \
-                   rm -f '$(DESTDIR)$(datadir)/$(DICTDIR)/'$${lang}.stop ; \
-               fi \
-       done
-
-clean distclean maintainer-clean: clean-lib
-       rm -f $(OBJS) $(SQLSCRIPT) snowball_create.dep
+       rm -f $(addprefix '$(DESTDIR)$(datadir)/$(DICTDIR)/',$(stop_files))
+
+clean distclean: clean-lib
+       rm -f $(OBJS)
+
+maintainer-clean: distclean
+       rm -f $(SQLSCRIPT)
diff --git a/src/backend/snowball/meson.build b/src/backend/snowball/meson.build
index 30aed714dc..c6326380e1 100644
--- a/src/backend/snowball/meson.build
+++ b/src/backend/snowball/meson.build
@@ -70,12 +70,11 @@ snowball_create = custom_target('snowball_create',
   input: ['snowball_create.pl'],
   output: ['snowball_create.sql'],
   depfile: 'snowball_create.dep',
-  command: [perl, '@INPUT0@', '--input', '@CURRENT_SOURCE_DIR@', '--output', 
'@OUTDIR@'],
+  command: [perl, '@INPUT0@', '--depfile', '--input', '@CURRENT_SOURCE_DIR@', 
'--output', '@OUTDIR@'],
   install: true,
   install_dir: dir_data,
 )
 
-# FIXME: check whether the logic to select languages currently in Makefile is 
needed
 install_subdir('stopwords',
   install_dir: dir_data / 'tsearch_data',
   strip_directory: true,
diff --git a/src/backend/snowball/snowball_create.pl 
b/src/backend/snowball/snowball_create.pl
index 285cf4f5d9..97e6c4d86d 100644
--- a/src/backend/snowball/snowball_create.pl
+++ b/src/backend/snowball/snowball_create.pl
@@ -7,8 +7,52 @@
 my $output_path = '';
 my $makefile_path = '';
 my $input_path = '';
+my $depfile;
+
+our @languages = qw(
+       arabic
+       armenian
+       basque
+       catalan
+       danish
+       dutch
+       english
+       finnish
+       french
+       german
+       greek
+       hindi
+       hungarian
+       indonesian
+       irish
+       italian
+       lithuanian
+       nepali
+       norwegian
+       portuguese
+       romanian
+       russian
+       serbian
+       spanish
+       swedish
+       tamil
+       turkish
+       yiddish
+);
+
+# Names of alternative dictionaries for all-ASCII words.  If not
+# listed, the language itself is used.  Note order dependency: Use of
+# some other language as ASCII dictionary must come after creation of
+# that language, so the "backup" language must be listed earlier in
+# @languages.
+
+our %ascii_languages = (
+       'hindi' => 'english',
+       'russian' => 'english',
+);
 
 GetOptions(
+       'depfile'    => \$depfile,
        'output:s'   => \$output_path,
        'input:s'    => \$input_path) || usage();
 
@@ -29,7 +73,8 @@
 sub usage
 {
        die <<EOM;
-Usage: snowball_create.pl --input/-i <path> --input <path>
+Usage: snowball_create.pl --input/-i <path> --output/-o <path>
+    --depfile       Write dependency file
     --output        Output directory (default '.')
     --input         Input directory
 
@@ -45,19 +90,16 @@ sub GenerateTsearchFiles
        my $F;
        my $D;
        my $tmpl = read_file("$input_path/snowball.sql.in");
-       my $mf   = read_file("$input_path/Makefile");
 
-       open($D, '>', "$output_path/snowball_create.dep")
-         || die "Could not write snowball_create.dep";
+       if ($depfile)
+       {
+               open($D, '>', "$output_path/snowball_create.dep")
+                 || die "Could not write snowball_create.dep";
+       }
 
-       print $D "$output_file: $input_path/Makefile\n";
-       print $D "$output_file: $input_path/snowball.sql.in\n";
-       print $D "$output_file: $input_path/snowball_func.sql.in\n";
+       print $D "$output_file: $input_path/snowball.sql.in\n" if $depfile;
+       print $D "$output_file: $input_path/snowball_func.sql.in\n" if $depfile;
 
-       $mf =~ s{\\\r?\n}{}g;
-       $mf =~ /^LANGUAGES\s*=\s*(.*)$/m
-         || die "Could not find LANGUAGES line in snowball Makefile\n";
-       my @pieces = split /\s+/, $1;
        open($F, '>', $output_file)
          || die "Could not write snowball_create.sql";
 
@@ -65,10 +107,9 @@ sub GenerateTsearchFiles
 
        print $F read_file("$input_path/snowball_func.sql.in");
 
-       while ($#pieces > 0)
+       foreach my $lang (@languages)
        {
-               my $lang    = shift @pieces || last;
-               my $asclang = shift @pieces || last;
+               my $asclang = $ascii_languages{$lang} || $lang;
                my $txt     = $tmpl;
                my $stop    = '';
                my $stopword_path = "$input_path/stopwords/$lang.stop";
@@ -77,7 +118,7 @@ sub GenerateTsearchFiles
                {
                        $stop = ", StopWords=$lang";
 
-                       print $D "$output_file: $stopword_path\n";
+                       print $D "$output_file: $stopword_path\n" if $depfile;
                }
 
                $txt =~ s#_LANGNAME_#${lang}#gs;
@@ -89,7 +130,7 @@ sub GenerateTsearchFiles
                print $F $txt;
        }
        close($F);
-       close($D);
+       close($D) if $depfile;
        return;
 }
 
diff --git a/src/tools/msvc/Install.pm b/src/tools/msvc/Install.pm
index 8de79c618c..db61b992ff 100644
--- a/src/tools/msvc/Install.pm
+++ b/src/tools/msvc/Install.pm
@@ -389,39 +389,9 @@ sub GenerateTsearchFiles
        my $target = shift;
 
        print "Generating tsearch script...";
-       my $F;
-       my $tmpl = read_file('src/backend/snowball/snowball.sql.in');
-       my $mf   = read_file('src/backend/snowball/Makefile');
-       $mf =~ s{\\\r?\n}{}g;
-       $mf =~ /^LANGUAGES\s*=\s*(.*)$/m
-         || die "Could not find LANGUAGES line in snowball Makefile\n";
-       my @pieces = split /\s+/, $1;
-       open($F, '>', "$target/share/snowball_create.sql")
-         || die "Could not write snowball_create.sql";
-       print $F read_file('src/backend/snowball/snowball_func.sql.in');
-
-       while ($#pieces > 0)
-       {
-               my $lang    = shift @pieces || last;
-               my $asclang = shift @pieces || last;
-               my $txt     = $tmpl;
-               my $stop    = '';
-
-               if (-s "src/backend/snowball/stopwords/$lang.stop")
-               {
-                       $stop = ", StopWords=$lang";
-               }
-
-               $txt =~ s#_LANGNAME_#${lang}#gs;
-               $txt =~ s#_DICTNAME_#${lang}_stem#gs;
-               $txt =~ s#_CFGNAME_#${lang}#gs;
-               $txt =~ s#_ASCDICTNAME_#${asclang}_stem#gs;
-               $txt =~ s#_NONASCDICTNAME_#${lang}_stem#gs;
-               $txt =~ s#_STOPWORDS_#$stop#gs;
-               print $F $txt;
-               print ".";
-       }
-       close($F);
+       system('perl', 'src/backend/snowball/snowball_create.pl',
+               '--input', 'src/backend/snowball/',
+               '--output', "$target/share/");
        print "\n";
        return;
 }
-- 
2.36.1

Reply via email to