Commit cea258b6 authored by Tom Lane's avatar Tom Lane

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".
parent 57fb1d67
...@@ -22,28 +22,21 @@ DOING THE INDENT RUN: ...@@ -22,28 +22,21 @@ DOING THE INDENT RUN:
1) Change directory to the top of the source tree. 1) Change directory to the top of the source tree.
2) Remove all derived files (pgindent has trouble with flex files, and it 2) Download the latest typedef file from the buildfarm:
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:
wget -O src/tools/pgindent/typedefs.list https://buildfarm.postgresql.org/cgi-bin/typedefs.pl 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 (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.) 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 src/tools/pgindent/pgindent
If any files generate errors, restore their original versions with If any files generate errors, restore their original versions with
"git checkout", and see below for cleanup ideas. "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 src/tools/pgindent/pgperltidy
...@@ -53,11 +46,12 @@ DOING THE INDENT RUN: ...@@ -53,11 +46,12 @@ DOING THE INDENT RUN:
VALIDATION: VALIDATION:
1) Check for any newly-created files using "git status"; there shouldn't 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: 2) Do a full test build:
./configure ... make -s clean
make -s all # look for unexpected warnings, and errors of course make -s all # look for unexpected warnings, and errors of course
make check-world make check-world
...@@ -127,21 +121,26 @@ Which files are processed ...@@ -127,21 +121,26 @@ Which files are processed
------------------------- -------------------------
The pgindent run processes (nearly) all PostgreSQL *.c and *.h files, 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: in exclude_file_patterns:
src/include/storage/s_lock.h and src/include/port/atomics/ are excluded src/include/storage/s_lock.h and src/include/port/atomics/ are excluded
because they contain assembly code that pgindent tends to mess up. 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 src/interfaces/ecpg/test/expected/ is excluded to avoid breaking the ecpg
regression tests. Several *.h files are included in regression output so 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/ src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
are excluded because those files are imported from an external project, are excluded because those files are imported from an external project,
not maintained locally, and are machine-generated anyway. Likewise for not maintained locally, and are machine-generated anyway. Likewise for
plperl/ppport.h. plperl/ppport.h.
The perltidy run processes all *.pl and *.pm files, plus a few The perltidy run processes all *.pl and *.pm files, plus a few
executable Perl scripts that are not named that way. See the "find" executable Perl scripts that are not named that way. See the "find"
rules in pgperltidy for details. rules in pgperltidy for details.
#list of file patterns to exclude from pgindent runs, see notes in README #list of file patterns to exclude from pgindent runs, see notes in README
/s_lock\.h$ /storage/s_lock\.h$
/atomics/ /port/atomics/
/utils/fmgrtab\.c$
/ecpg/test/expected/ /ecpg/test/expected/
/snowball/libstemmer/ /snowball/libstemmer/
/pl/plperl/ppport\.h$ /pl/plperl/ppport\.h$
...@@ -534,6 +534,15 @@ push(@files, @ARGV); ...@@ -534,6 +534,15 @@ push(@files, @ARGV);
foreach my $source_filename (@files) 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 $source = read_source($source_filename);
my $error_message = ''; my $error_message = '';
......
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