Commit ddfe26f6 authored by Robert Haas's avatar Robert Haas

Avoid maintaining three separate copies of the error codes list.

src/pl/plpgsql/src/plerrcodes.h, src/include/utils/errcodes.h, and a
big chunk of errcodes.sgml are now automatically generated from a single
file, src/backend/utils/errcodes.txt.

Jan Urbański, reviewed by Tom Lane.
parent 7212c77d
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# GENERATED_SGML # GENERATED_SGML
/features-supported.sgml /features-supported.sgml
/features-unsupported.sgml /features-unsupported.sgml
/errcodes-table.sgml
/version.sgml /version.sgml
/bookindex.sgml /bookindex.sgml
/HTML.index /HTML.index
......
...@@ -52,7 +52,7 @@ override XSLTPROCFLAGS += --stringparam pg.version '$(VERSION)' ...@@ -52,7 +52,7 @@ override XSLTPROCFLAGS += --stringparam pg.version '$(VERSION)'
GENERATED_SGML = bookindex.sgml version.sgml \ GENERATED_SGML = bookindex.sgml version.sgml \
features-supported.sgml features-unsupported.sgml features-supported.sgml features-unsupported.sgml errcodes-table.sgml
ALLSGML := $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml) $(GENERATED_SGML) ALLSGML := $(wildcard $(srcdir)/*.sgml $(srcdir)/ref/*.sgml) $(GENERATED_SGML)
...@@ -136,6 +136,8 @@ features-supported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages. ...@@ -136,6 +136,8 @@ features-supported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.
features-unsupported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.txt $(top_srcdir)/src/backend/catalog/sql_features.txt features-unsupported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.txt $(top_srcdir)/src/backend/catalog/sql_features.txt
$(PERL) $(srcdir)/mk_feature_tables.pl NO $^ > $@ $(PERL) $(srcdir)/mk_feature_tables.pl NO $^ > $@
errcodes-table.sgml: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes-table.pl
$(PERL) $(srcdir)/generate-errcodes-table.pl $< > $@
## ##
## Print ## Print
......
This diff is collapsed.
...@@ -164,6 +164,8 @@ ...@@ -164,6 +164,8 @@
<!entity features-supported SYSTEM "features-supported.sgml"> <!entity features-supported SYSTEM "features-supported.sgml">
<!entity features-unsupported SYSTEM "features-unsupported.sgml"> <!entity features-unsupported SYSTEM "features-unsupported.sgml">
<!entity errcodes-table SYSTEM "errcodes-table.sgml">
<!-- back matter --> <!-- back matter -->
<!entity biblio SYSTEM "biblio.sgml"> <!entity biblio SYSTEM "biblio.sgml">
<!entity bookindex SYSTEM "bookindex.sgml"> <!entity bookindex SYSTEM "bookindex.sgml">
......
#!/usr/bin/perl
#
# Generate the errcodes-table.sgml file from errcodes.txt
# Copyright (c) 2000-2011, PostgreSQL Global Development Group
use warnings;
use strict;
print "<!-- autogenerated from src/backend/utils/errcodes.txt, do not edit -->\n";
open my $errcodes, $ARGV[0] or die;
while (<$errcodes>) {
chomp;
# Skip comments
next if /^#/;
next if /^\s*$/;
# Emit section headers
if (/^Section:/) {
# Remove the Section: string
s/^Section: //;
# Escape dashes for SGML
s/-/&mdash;/;
# Wrap PostgreSQL in <productname/>
s/PostgreSQL/<productname>PostgreSQL<\/>/g;
print "\n\n";
print "<row>\n";
print "<entry spanname=\"span13\">";
print "<emphasis role=\"bold\">$_</></entry>\n";
print "</row>\n";
next;
}
die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
(my $sqlstate,
my $type,
my $errcode_macro,
my $condition_name) = ($1, $2, $3, $4);
# Skip lines without PL/pgSQL condition names
next unless defined($condition_name);
my $meaning = $condition_name;
# Remove underscores
$meaning =~ s/_/ /g;
# And capitalize
$meaning =~ tr/[a-z]/[A-Z]/;
print "\n";
print "<row>\n";
print "<entry><literal>$sqlstate</literal></entry>\n";
print "<entry>$meaning</entry>\n";
print "<entry>$condition_name</entry>\n";
print "</row>\n";
}
close $errcodes;
...@@ -30,6 +30,17 @@ SUBDIRS = \ ...@@ -30,6 +30,17 @@ SUBDIRS = \
# don't attempt parallel make here. # don't attempt parallel make here.
.NOTPARALLEL: .NOTPARALLEL:
# generate errcodes.h before recursing in the subdirectories
$(SUBDIRS:%=all-%-recurse): $(top_builddir)/src/include/utils/errcodes.h
backend/utils/errcodes.h: backend/utils/generate-errcodes.pl $(top_srcdir)/src/backend/utils/errcodes.txt
$(MAKE) -C backend/utils errcodes.h
$(top_builddir)/src/include/utils/errcodes.h: backend/utils/errcodes.h
prereqdir=`cd $(dir $<) >/dev/null && pwd` && \
cd $(dir $@) && rm -f $(notdir $@) && \
$(LN_S) "$$prereqdir/$(notdir $<)" .
$(recurse) $(recurse)
install: install-local install: install-local
......
...@@ -298,6 +298,7 @@ maintainer-clean: distclean ...@@ -298,6 +298,7 @@ maintainer-clean: distclean
catalog/postgres.shdescription \ catalog/postgres.shdescription \
utils/fmgroids.h \ utils/fmgroids.h \
utils/fmgrtab.c \ utils/fmgrtab.c \
utils/errcodes.h \
utils/misc/guc-file.c utils/misc/guc-file.c
......
/fmgrtab.c /fmgrtab.c
/fmgroids.h /fmgroids.h
/probes.h /probes.h
/errcodes.h
...@@ -26,6 +26,9 @@ fmgroids.h: fmgrtab.c ; ...@@ -26,6 +26,9 @@ fmgroids.h: fmgrtab.c ;
fmgrtab.c: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h fmgrtab.c: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
$(PERL) -I $(catalogdir) $< $(top_srcdir)/src/include/catalog/pg_proc.h $(PERL) -I $(catalogdir) $< $(top_srcdir)/src/include/catalog/pg_proc.h
errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
$(PERL) generate-errcodes.pl $< > $@
ifneq ($(enable_dtrace), yes) ifneq ($(enable_dtrace), yes)
probes.h: Gen_dummy_probes.sed probes.h: Gen_dummy_probes.sed
endif endif
...@@ -40,10 +43,10 @@ else ...@@ -40,10 +43,10 @@ else
endif endif
# fmgroids.h and fmgrtab.c are in the distribution tarball, so they # fmgroids.h, fmgrtab.c and errcodes.h are in the distribution tarball, so they
# are not cleaned here. # are not cleaned here.
clean: clean:
rm -f probes.h rm -f probes.h
maintainer-clean: clean maintainer-clean: clean
rm -f fmgroids.h fmgrtab.c rm -f fmgroids.h fmgrtab.c errcodes.h
This diff is collapsed.
#!/usr/bin/perl
#
# Generate the errcodes.h header from errcodes.txt
# Copyright (c) 2000-2011, PostgreSQL Global Development Group
use warnings;
use strict;
print "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
print "/* there is deliberately not an #ifndef ERRCODES_H here */\n";
open my $errcodes, $ARGV[0] or die;
while (<$errcodes>) {
chomp;
# Skip comments
next if /^#/;
next if /^\s*$/;
# Emit a comment for each section header
if (/^Section:(.*)/) {
my $header = $1;
$header =~ s/^\s+//;
print "\n/* $header */\n";
next;
}
die "unable to parse errcodes.txt" unless /^([^\s]{5})\s+[EWS]\s+([^\s]+)/;
(my $sqlstate, my $errcode_macro) = ($1, $2);
# Split the sqlstate letters
$sqlstate = join ",", split "", $sqlstate;
# And quote them
$sqlstate =~ s/([^,])/'$1'/g;
print "#define $errcode_macro MAKE_SQLSTATE($sqlstate)\n";
}
close $errcodes;
...@@ -62,7 +62,7 @@ uninstall: ...@@ -62,7 +62,7 @@ uninstall:
clean: clean:
rm -f utils/fmgroids.h parser/gram.h utils/probes.h catalog/schemapg.h rm -f utils/fmgroids.h utils/errcodes.h parser/gram.h utils/probes.h catalog/schemapg.h
distclean maintainer-clean: clean distclean maintainer-clean: clean
rm -f pg_config.h dynloader.h pg_config_os.h stamp-h rm -f pg_config.h dynloader.h pg_config_os.h stamp-h
/fmgroids.h /fmgroids.h
/probes.h /probes.h
/errcodes.h
This diff is collapsed.
/pl_gram.c /pl_gram.c
/pl_gram.h /pl_gram.h
/plerrcodes.h
...@@ -33,7 +33,7 @@ uninstall: uninstall-lib ...@@ -33,7 +33,7 @@ uninstall: uninstall-lib
# Force these dependencies to be known even without dependency info built: # Force these dependencies to be known even without dependency info built:
pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o: plpgsql.h pl_gram.h pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o: plpgsql.h pl_gram.h plerrcodes.h
# See notes in src/backend/parser/Makefile about the following two rules # See notes in src/backend/parser/Makefile about the following two rules
...@@ -46,12 +46,16 @@ else ...@@ -46,12 +46,16 @@ else
@$(missing) bison $< $@ @$(missing) bison $< $@
endif endif
distprep: pl_gram.h pl_gram.c # generate plerrcodes.h from src/backend/utils/errcodes.txt
plerrcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-plerrcodes.pl
$(PERL) generate-plerrcodes.pl $< > $@
# pl_gram.c and pl_gram.h are in the distribution tarball, distprep: pl_gram.h pl_gram.c plerrcodes.h
# pl_gram.c, pl_gram.h and plerrcodes.h are in the distribution tarball,
# so they are not cleaned here. # so they are not cleaned here.
clean distclean: clean-lib clean distclean: clean-lib
rm -f $(OBJS) rm -f $(OBJS)
maintainer-clean: clean maintainer-clean: clean
rm -f pl_gram.c pl_gram.h rm -f pl_gram.c pl_gram.h plerrcodes.h
#!/usr/bin/perl
#
# Generate the plerrcodes.h header from errcodes.txt
# Copyright (c) 2000-2011, PostgreSQL Global Development Group
use warnings;
use strict;
print "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n";
print "/* there is deliberately not an #ifndef PLERRCODES_H here */\n";
open my $errcodes, $ARGV[0] or die;
while (<$errcodes>) {
chomp;
# Skip comments
next if /^#/;
next if /^\s*$/;
# Skip section headers
next if /^Section:/;
die unless /^([^\s]{5})\s+([EWS])\s+([^\s]+)(?:\s+)?([^\s]+)?/;
(my $sqlstate,
my $type,
my $errcode_macro,
my $condition_name) = ($1, $2, $3, $4);
# Skip non-errors
next unless $type eq 'E';
# Skip lines without PL/pgSQL condition names
next unless defined($condition_name);
print "{\n\t\"$condition_name\", $errcode_macro\n},\n\n";
}
close $errcodes;
This diff is collapsed.
...@@ -273,6 +273,19 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY ...@@ -273,6 +273,19 @@ s{PG_VERSION_STR "[^"]+"}{__STRINGIFY(x) #x\n#define __STRINGIFY2(z) __STRINGIFY
); );
} }
if (IsNewer('src\include\utils\errcodes.h','src\backend\utils\errcodes.txt'))
{
print "Generating errcodes.h...\n";
system("perl src\backend\utils\generate-errcodes.pl src\backend\utils\errcodes.txt > src\backend\utils\errcodes.h");
copyFile('src\backend\utils\errcodes.h','src\include\utils\errcodes.h');
}
if (IsNewer('src\pl\plpgsql\src\plerrcodes.h','src\backend\utils\errcodes.txt'))
{
print "Generating plerrcodes.h...\n";
system("perl src\pl\plpgsql\src\generate-plerrcodes.pl src\backend\utils\errcodes.txt > src\pl\plpgsql\src\plerrcodes.h");
}
if (IsNewer('src\interfaces\libpq\libpq.rc','src\interfaces\libpq\libpq.rc.in')) if (IsNewer('src\interfaces\libpq\libpq.rc','src\interfaces\libpq\libpq.rc.in'))
{ {
print "Generating libpq.rc...\n"; print "Generating libpq.rc...\n";
......
...@@ -32,6 +32,7 @@ SET SGML_CATALOG_FILES=%DOCROOT%\%OPENJADE%\dsssl\catalog;%DOCROOT%\docbook\docb ...@@ -32,6 +32,7 @@ SET SGML_CATALOG_FILES=%DOCROOT%\%OPENJADE%\dsssl\catalog;%DOCROOT%\docbook\docb
perl %DOCROOT%\%DSSSL%\bin\collateindex.pl -f -g -o bookindex.sgml -N perl %DOCROOT%\%DSSSL%\bin\collateindex.pl -f -g -o bookindex.sgml -N
perl mk_feature_tables.pl YES ..\..\..\src\backend\catalog\sql_feature_packages.txt ..\..\..\src\backend\catalog\sql_features.txt > features-supported.sgml perl mk_feature_tables.pl YES ..\..\..\src\backend\catalog\sql_feature_packages.txt ..\..\..\src\backend\catalog\sql_features.txt > features-supported.sgml
perl mk_feature_tables.pl NO ..\..\..\src\backend\catalog\sql_feature_packages.txt ..\..\..\src\backend\catalog\sql_features.txt > features-unsupported.sgml perl mk_feature_tables.pl NO ..\..\..\src\backend\catalog\sql_feature_packages.txt ..\..\..\src\backend\catalog\sql_features.txt > features-unsupported.sgml
perl make-errcodes-table.pl ..\..\..\src\backend\utils\errcodes.txt > errcodes-table.sgml
echo Running first build... echo Running first build...
%DOCROOT%\%OPENJADE%\bin\openjade -V draft-mode -wall -wno-unused-param -wno-empty -D . -c %DOCROOT%\%DSSSL%\catalog -d stylesheet.dsl -i output-html -t sgml postgres.sgml 2>&1 | findstr /V "DTDDECL catalog entries are not supported" %DOCROOT%\%OPENJADE%\bin\openjade -V draft-mode -wall -wno-unused-param -wno-empty -D . -c %DOCROOT%\%DSSSL%\catalog -d stylesheet.dsl -i output-html -t sgml postgres.sgml 2>&1 | findstr /V "DTDDECL catalog entries are not supported"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment