Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit05d8dec

Browse files
committed
Simplify the process of perltidy'ing our Perl files.
Wrap the perltidy invocation into a shell script to reduce the risk ofcopy-and-paste errors. Include removal of *.bak files in the script,so they don't accidentally get committed. Improve the directions inthe README file.
1 parent9389fbd commit05d8dec

File tree

3 files changed

+114
-59
lines changed

3 files changed

+114
-59
lines changed

‎src/tools/pgindent/README

Lines changed: 90 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,104 @@
1-
pgindent
2-
========
1+
pgindent'ing the PostgreSQL source tree
2+
=======================================
33

4-
This can format all PostgreSQL *.c and *.h files, but excludes *.y, and
5-
*.l files.
4+
We run this process at least once in each development cycle,
5+
to maintain uniform layout style in our C and Perl code.
66

7-
1) Install pg_bsd_indent (see below for details).
7+
You might find this blog post interesting:
8+
http://adpgtech.blogspot.com/2015/05/running-pgindent-on-non-core-code-or.html
9+
10+
11+
PREREQUISITES:
12+
13+
1) Install pg_bsd_indent in your PATH (see below for details).
814

915
2) Install entab (src/tools/entab/).
1016

11-
3) Change directory to the top of the build tree.
17+
3) Install perltidy. Please be sure it is v20090616 (older and newer
18+
versions make different formatting choices, and we want consistency).
1219

13-
4) Remove all derived files (pgindent has trouble with one of the flex macros):
20+
DOING THE INDENT RUN:
1421

15-
make maintainer-clean
22+
1) Change directory to the top of the source tree.
1623

17-
Or:
24+
2) Remove all derived files (pgindent has trouble with flex files, and it
25+
would be pointless to run it on them anyway):
1826

27+
make maintainer-clean
28+
Or:
1929
git clean -fdx
2030

21-
5) Download the typedef file from the buildfarm:
31+
3) Download the latest typedef file from the buildfarm:
2232

2333
wget -O src/tools/pgindent/typedefs.list http://buildfarm.postgresql.org/cgi-bin/typedefs.pl
2434

25-
(see http://www.pgbuildfarm.org/cgi-bin/typedefs.pl?show_list for a full list of typedefs,
26-
also http://adpgtech.blogspot.com/2015/05/running-pgindent-on-non-core-code-or.html)
35+
(See http://www.pgbuildfarm.org/cgi-bin/typedefs.pl?show_list for a full
36+
list of typedef files, if you want to indent some back branch.)
2737

28-
6) Run pgindent:
38+
4) Run pgindent on the C files:
2939

3040
src/tools/pgindent/pgindent
3141

32-
7) Remove any files that generate errors and restore their original
33-
versions.
42+
If any files generate errors, restore their original versions with
43+
"git checkout", and see below for cleanup ideas.
44+
45+
5) Indent the Perl code using perltidy:
46+
47+
src/tools/pgindent/pgperltidy
3448

35-
8) Indent the Perl code using perltidy v20090616 (perltidychanges formatting
36-
decisions, so older and newer versions are incompatible):
49+
If you want to use someperltidyversion that's not in your PATH,
50+
first set the PERLTIDY environment variable to point to it.
3751

38-
(
39-
find . -name \*.pl -o -name \*.pm
52+
VALIDATION:
4053

41-
find . -type f -exec file {} \; |
42-
egrep -i ':.*perl[0-9]*\>' |
43-
cut -d: -f1
44-
) |
45-
sort -u |
46-
xargs perltidy --profile=src/tools/pgindent/perltidyrc
54+
1) Check for any newly-created files using "git status"; there shouldn't
55+
be any. (perltidy tends to leave *.LOG files behind if it has trouble.)
4756

48-
9) Do a full test build:
57+
2) Do a full test build:
4958

50-
> run configure
51-
# stop is only necessary if it's going to install in a location with an
52-
# already running server
53-
pg_ctl stop
54-
run configure
55-
make -C src install
56-
make -C contrib install
57-
run initdb
58-
pg_ctl start
59-
make installcheck-world
59+
./configure ...
60+
make -s all# look for unexpected warnings, and errors of course
61+
make check-world
62+
63+
Your configure switches should include at least --enable-tap-tests
64+
or else much of the Perl code won't get exercised.
65+
66+
3) If you have the patience, it's worth eyeballing the "git diff" output
67+
for any egregiously ugly changes. See below for cleanup ideas.
68+
69+
70+
When you're done, "git commit" everything including the typedefs.list file
71+
you used.
6072

61-
10) Remove Perl backup files after testing (*.bak)
73+
74+
---------------------------------------------------------------------------
75+
76+
Cleaning up in case of failure or ugly output
77+
---------------------------------------------
78+
79+
If you don't like the results for any particular file, "git checkout"
80+
that file to undo the changes, patch the file as needed, then repeat
81+
the indent process.
82+
83+
pgindent will reflow any comment block that's not at the left margin.
84+
If this messes up manual formatting that ought to be preserved, protect
85+
the comment block with some dashes:
86+
87+
/*----------
88+
* Text here will not be touched by pgindent.
89+
*----------
90+
*/
91+
92+
Odd spacing around typedef names might indicate an incomplete typedefs list.
93+
94+
pgindent can get confused by #if sequences that look correct to the compiler
95+
but have mismatched braces/parentheses when considered as a whole. Usually
96+
that looks pretty unreadable to humans too, so best practice is to rearrange
97+
the #if tests to avoid it.
98+
99+
Sometimes, if pgindent or perltidy produces odd-looking output, it's because
100+
of minor bugs like extra commas. Don't hesitate to clean that up while
101+
you're at it.
62102

63103
---------------------------------------------------------------------------
64104

@@ -82,33 +122,25 @@ see:
82122

83123
---------------------------------------------------------------------------
84124

85-
Notes about excluded files
86-
--------------------------
125+
Which files are processed
126+
-------------------------
127+
128+
The pgindent run processes (nearly) all PostgreSQL *.c and *.h files,
129+
but we currently exclude *.y and *.l files. Exceptions are listed
130+
in exclude_file_patterns:
87131

88132
src/include/storage/s_lock.h and src/include/port/atomics/ are excluded
89133
because they contain assembly code that pgindent tends to mess up.
90134

91-
src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
92-
are excluded because those files are imported from an external project,
93-
not maintained locally, and are machine-generated anyway.
94-
95135
src/interfaces/ecpg/test/expected/ is excluded to avoid breaking the ecpg
96136
regression tests. Several *.h files are included in regression output so
97137
should not be changed.
98138

99-
---------------------------------------------------------------------------
100-
101-
Obsolete typedef list creation instructions
102-
-------------------------------------------
103-
104-
To use pgindent:
105-
106-
1) Build the source tree with _debug_ symbols and all possible configure options
107-
108-
2) Install to /usr/local/pgsql
109-
110-
3) Install all contrib modules
111-
112-
4) Save a list of typedefs by running:
139+
src/include/snowball/libstemmer/ and src/backend/snowball/libstemmer/
140+
are excluded because those files are imported from an external project,
141+
not maintained locally, and are machine-generated anyway. Likewise for
142+
plperl/ppport.h.
113143

114-
src/tools/find_typedef /usr/local/pgsql/bin /usr/local/pgsql/lib > /tmp/pgtypedefs
144+
The perltidy run processes all *.pl and *.pm files, plus a few
145+
executable Perl scripts that are not named that way. See the "find"
146+
rules in pgperltidy for details.

‎src/tools/pgindent/exclude_file_patterns

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#list of file patterns to exclude from pgindent runs
1+
#list of file patterns to exclude from pgindent runs, see notes in README
22
/s_lock\.h$
33
/atomics/
44
/ecpg/test/expected/

‎src/tools/pgindent/pgperltidy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
3+
# src/tools/pgindent/pgperltidy
4+
5+
set -e
6+
7+
# set this to override default perltidy program:
8+
PERLTIDY=${PERLTIDY:-perltidy}
9+
10+
# locate all Perl files in the tree
11+
(
12+
# take all .pl and .pm files
13+
find. -type f -a\( -name'*.pl' -o -name'*.pm'\)
14+
# take executable files that file(1) thinks are perl files
15+
find. -type f -perm -100 -exec file {}\;|
16+
egrep -i':.*perl[0-9]*\>'|
17+
cut -d: -f1
18+
)|
19+
sort -u|
20+
xargs$PERLTIDY --profile=src/tools/pgindent/perltidyrc
21+
22+
# perltidyrc specifies --backup-and-modify-in-place, so get rid of .bak files
23+
find. -type f -name'*.bak'| xargs rm

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp