aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-06-16 23:14:27 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-06-16 23:14:40 -0400
commitcea258b63d9c7a6d0a7c5e91e539bb89df4bc078 (patch)
treed3218290d41cbc5a35d5228e7b649b0153886e8a /src
parent57fb1d677d98d9c02565e47afdbf5e887b095c9f (diff)
downloadpostgresql-cea258b63d9c7a6d0a7c5e91e539bb89df4bc078.tar.gz
postgresql-cea258b63d9c7a6d0a7c5e91e539bb89df4bc078.zip
Teach pgindent to skip files generated by bison or flex automatically.
If a .c or .h file corresponds to a .y or .l file, skip indenting it. There's no point in reindenting derived files, and these files tend to confuse pgindent. (Which probably indicates a bug in BSD indent, but I can't get excited about trying to fix it.) For the same reasons, add src/backend/utils/fmgrtab.c to the set of files excluded by src/tools/pgindent/exclude_file_patterns. The point of doing this is that it makes it safe to run pgindent over the tree without doing "make maintainer-clean" first. While these are not the only derived .c/.h files in the tree, they are the only ones pgindent fails on. Removing that prerequisite step results in one less way to mess up a pgindent run, and it's necessary if we ever hope to get to the ease of running pgindent via "make indent".
Diffstat (limited to 'src')
-rw-r--r--src/tools/pgindent/README27
-rw-r--r--src/tools/pgindent/exclude_file_patterns5
-rwxr-xr-xsrc/tools/pgindent/pgindent9
3 files changed, 25 insertions, 16 deletions
diff --git a/src/tools/pgindent/README b/src/tools/pgindent/README
index ee27b732ec9..598200403ee 100644
--- a/src/tools/pgindent/README
+++ b/src/tools/pgindent/README
@@ -22,28 +22,21 @@ DOING THE INDENT RUN:
1) Change directory to the top of the source tree.
-2) Remove all derived files (pgindent has trouble with flex files, and it
- would be pointless to run it on them anyway):
-
- make maintainer-clean
- Or:
- git clean -fdx
-
-3) Download the latest typedef file from the buildfarm:
+2) Download the latest typedef file from the buildfarm:
wget -O src/tools/pgindent/typedefs.list https://buildfarm.postgresql.org/cgi-bin/typedefs.pl
(See https://www.pgbuildfarm.org/cgi-bin/typedefs.pl?show_list for a full
list of typedef files, if you want to indent some back branch.)
-4) Run pgindent on the C files:
+3) Run pgindent on the C files:
src/tools/pgindent/pgindent
If any files generate errors, restore their original versions with
"git checkout", and see below for cleanup ideas.
-5) Indent the Perl code using perltidy:
+4) Indent the Perl code using perltidy:
src/tools/pgindent/pgperltidy
@@ -53,11 +46,12 @@ DOING THE INDENT RUN:
VALIDATION:
1) Check for any newly-created files using "git status"; there shouldn't
- be any. (perltidy tends to leave *.LOG files behind if it has trouble.)
+ be any. (pgindent leaves *.BAK files behind if it has trouble, while
+ perltidy leaves *.LOG files behind.)
2) Do a full test build:
- ./configure ...
+ make -s clean
make -s all # look for unexpected warnings, and errors of course
make check-world
@@ -127,21 +121,26 @@ Which files are processed
-------------------------
The pgindent run processes (nearly) all PostgreSQL *.c and *.h files,
-but we currently exclude *.y and *.l files. Exceptions are listed
+but we currently exclude *.y and *.l files, as well as *.c and *.h files
+derived from *.y and *.l files. Additional exceptions are listed
in exclude_file_patterns:
src/include/storage/s_lock.h and src/include/port/atomics/ are excluded
because they contain assembly code that pgindent tends to mess up.
+src/backend/utils/fmgrtab.c is excluded because it confuses pgindent
+and it's a derived file anyway.
+
src/interfaces/ecpg/test/expected/ is excluded to avoid breaking the ecpg
regression tests. Several *.h files are included in regression output so
-should not be changed.
+they must not be changed.
src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
are excluded because those files are imported from an external project,
not maintained locally, and are machine-generated anyway. Likewise for
plperl/ppport.h.
+
The perltidy run processes all *.pl and *.pm files, plus a few
executable Perl scripts that are not named that way. See the "find"
rules in pgperltidy for details.
diff --git a/src/tools/pgindent/exclude_file_patterns b/src/tools/pgindent/exclude_file_patterns
index 97ba092658e..cb2f902a90f 100644
--- a/src/tools/pgindent/exclude_file_patterns
+++ b/src/tools/pgindent/exclude_file_patterns
@@ -1,6 +1,7 @@
#list of file patterns to exclude from pgindent runs, see notes in README
-/s_lock\.h$
-/atomics/
+/storage/s_lock\.h$
+/port/atomics/
+/utils/fmgrtab\.c$
/ecpg/test/expected/
/snowball/libstemmer/
/pl/plperl/ppport\.h$
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindent
index f48af324262..603e4b3aff1 100755
--- a/src/tools/pgindent/pgindent
+++ b/src/tools/pgindent/pgindent
@@ -534,6 +534,15 @@ push(@files, @ARGV);
foreach my $source_filename (@files)
{
+ # Automatically ignore .c and .h files that correspond to a .y or .l
+ # file. indent tends to get badly confused by Bison/flex output,
+ # and there's no value in indenting derived files anyway.
+ my $otherfile = $source_filename;
+ $otherfile =~ s/\.[ch]$/.y/;
+ next if $otherfile ne $source_filename && -f $otherfile;
+ $otherfile =~ s/\.y$/.l/;
+ next if $otherfile ne $source_filename && -f $otherfile;
+
my $source = read_source($source_filename);
my $error_message = '';