]> granicus.if.org Git - postgresql/commitdiff
Teach pgindent to skip files generated by bison or flex automatically.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 17 Jun 2017 03:14:27 +0000 (23:14 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 17 Jun 2017 03:14:40 +0000 (23:14 -0400)
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".

src/tools/pgindent/README
src/tools/pgindent/exclude_file_patterns
src/tools/pgindent/pgindent

index ee27b732ec9f622398e1a60a4dfeabd60da6d4ab..598200403ee118e4f8b810d45af3a29f3cda0bd7 100644 (file)
@@ -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.
index 97ba092658e71fb647d290c22e71903670ec96c5..cb2f902a90f2178f7d0df488bbfcd14764573dbe 100644 (file)
@@ -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$
index f48af3242627f126000baa9cb747a897bad12a54..603e4b3aff1c2838b7ce1f02d59700b9e529f660 100755 (executable)
@@ -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 = '';