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

Commit156c049

Browse files
committed
Integrate pg_bsd_indent into our build/test infrastructure.
Update the Makefile and build directions for in-tree build,and add Meson build infrastructure. Also convert the ad-hoctest target into a TAP test.Currently, the Make build system will not build pg_bsd_indentby default, while the Meson system will. Both will test itduring "make check-world" or "ninja test". Neither will installit automatically. (We might change some of these decisions later.)Also fix a few portability nits noted during early testing.Also, exclude pg_bsd_indent from pgindent's purview; at least fornow, we'll leave it formatted similarly to the FreeBSD original.Tom Lane and Andres FreundDiscussion:https://postgr.es/m/3935719.1675967430@sss.pgh.pa.usDiscussion:https://postgr.es/m/20200812223409.6di3y2qsnvynao7a@alap3.anarazel.de
1 parentb44e5fc commit156c049

File tree

13 files changed

+188
-66
lines changed

13 files changed

+188
-66
lines changed

‎GNUmakefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ check check-tests installcheck installcheck-parallel installcheck-tests: CHECKPR
6868
check check-tests installcheck installcheck-parallel installcheck-tests: submake-generated-headers
6969
$(MAKE) -C src/test/regress $@
7070

71-
$(call recurse,check-world,src/test src/pl src/interfaces contrib src/bin,check)
71+
$(call recurse,check-world,src/test src/pl src/interfaces contrib src/bin src/tools/pg_bsd_indent,check)
7272
$(call recurse,checkprep, src/test src/pl src/interfaces contrib src/bin)
7373

7474
$(call recurse,installcheck-world,src/test src/pl src/interfaces contrib src/bin,installcheck)

‎src/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ clean:
6666
$(MAKE) -Ctest$@
6767
$(MAKE) -C tutorial NO_PGXS=1$@
6868
$(MAKE) -C test/isolation$@
69+
$(MAKE) -C tools/pg_bsd_indent$@
6970

7071
distcleanmaintainer-clean:
7172
$(MAKE) -Ctest$@
7273
$(MAKE) -C tutorial NO_PGXS=1$@
7374
$(MAKE) -C test/isolation$@
75+
$(MAKE) -C tools/pg_bsd_indent$@
7476
rm -f Makefile.port Makefile.global
7577

7678

‎src/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ subdir('pl')
1313

1414
subdir('interfaces')
1515

16+
subdir('tools/pg_bsd_indent')
17+
1618

1719
### Generate a Makefile.global that's complete enough for PGXS to work.
1820
#

‎src/tools/pg_bsd_indent/.gitignore

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# Global excludes across all subdirectories
2-
*.o
3-
*.obj
4-
*.exe
5-
6-
# Local excludes in root directory
71
/pg_bsd_indent
8-
/*.out
9-
/*.list
10-
/tests.diff
2+
# Generated by test suite
3+
/log/
4+
/tmp_check/

‎src/tools/pg_bsd_indent/Makefile

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
11
#-------------------------------------------------------------------------
22
#
3-
#Makefile forpg_bsd_indent
3+
#src/tools/pg_bsd_indent/Makefile
44
#
5-
# Copyright (c) 2017, PostgreSQL Global Development Group
5+
# Copyright (c) 2017-2023, PostgreSQL Global Development Group
66
#
77
#-------------------------------------------------------------------------
88

99
PGFILEDESC = "pg_bsd_indent - indent C code nicely"
1010
PGAPPICON = win32
1111

12-
PROGRAM = pg_bsd_indent
13-
OBJS= args.o err.o indent.o io.o lexi.o parse.o pr_comment.o$(WIN32RES)
12+
subdir = src/tools/pg_bsd_indent
13+
top_builddir = ../../..
14+
include$(top_builddir)/src/Makefile.global
1415

15-
# clean junk left behind by "make test"
16-
EXTRA_CLEAN = *.out *.list tests.diff
16+
OBJS =\
17+
$(WIN32RES)\
18+
args.o\
19+
err.o\
20+
indent.o\
21+
io.o\
22+
lexi.o\
23+
parse.o\
24+
pr_comment.o
1725

18-
PG_CONFIG = pg_config
19-
PGXS :=$(shell$(PG_CONFIG) --pgxs)
20-
include$(PGXS)
26+
all: pg_bsd_indent
2127

22-
# pgxs.mk assumes too much about what "make check" means, so call it "test"
28+
pg_bsd_indent:$(OBJS) | submake-libpgport
29+
$(CC)$(CFLAGS)$^$(LDFLAGS)$(LDFLAGS_EX)$(LIBS) -o$@$(X)
30+
31+
install: all installdirs
32+
$(INSTALL_PROGRAM) pg_bsd_indent$(X)'$(DESTDIR)$(bindir)/pg_bsd_indent$(X)'
33+
34+
installdirs:
35+
$(MKDIR_P)'$(DESTDIR)$(bindir)'
36+
37+
uninstall:
38+
rm -f'$(DESTDIR)$(bindir)/pg_bsd_indent$(X)'
39+
40+
cleandistcleanmaintainer-clean:
41+
rm -f pg_bsd_indent$(X)$(OBJS)
42+
rm -rf log/ tmp_check/
43+
44+
check: pg_bsd_indent
45+
$(prove_check)
46+
47+
installcheck:
48+
$(prove_installcheck)
49+
50+
# Provide this alternate test name to allow testing pg_bsd_indent
51+
# without building all of the surrounding Postgres installation.
2352
.PHONY: test
2453

25-
test:$(PROGRAM)
26-
@rm -f tests.diff
27-
@cp$(srcdir)/tests/*.list.
28-
@for testsrcin$(srcdir)/tests/*.0;do\
29-
test=`basename"$$testsrc" .0`;\
30-
./$(PROGRAM)$$testsrc$$test.out -P$(srcdir)/tests/$$test.pro||echo FAILED>>$$test.out;\
31-
diff -u$$testsrc.stdout$$test.out>>tests.diff2>&1||true;\
32-
done
33-
@cat tests.diff
34-
@test'!' -s tests.diff
35-
@echo Tests complete.
54+
test: pg_bsd_indent
55+
$(prove_installcheck)

‎src/tools/pg_bsd_indent/README

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
src/tools/pg_bsd_indent/README
2+
3+
This is a lightly modified version of the "indent" program maintained
4+
by the FreeBSD project. The modifications are mostly to make it portable
5+
to non-BSD-ish platforms, though we do have one formatting switch we
6+
couldn't convince upstream to take.
7+
8+
To build it, configure the surrounding Postgres source tree,
9+
then run "make" in this directory.
10+
Optionally, run "make test" for some simple tests.
11+
12+
You'll need to install pg_bsd_indent somewhere in your PATH before
13+
using it. Most likely, if you're a developer, you don't want to
14+
put it in the same place as where the surrounding Postgres build
15+
gets installed. Therefore, do this part with something like
16+
17+
make install prefix=/usr/local
18+
19+
If you are using Meson to build, the standard build targets will
20+
build pg_bsd_indent and also test it, but there is not currently
21+
provision for installing it anywhere. Manually copy the built
22+
executable from build/src/tools/pg_bsd_indent/pg_bsd_indent to
23+
wherever you want to put it.
24+
25+
26+
If you happen to be hacking upon the indent source code, the closest
27+
approximation to the existing indentation style seems to be
28+
29+
./pg_bsd_indent -i4 -l79 -di12 -nfc1 -nlp -sac somefile.c
30+
31+
although this has by no means been rigorously adhered to.
32+
(What was that saw about the shoemaker's children?)
33+
We're not planning to re-indent to Postgres style, because that
34+
would make it difficult to compare to the FreeBSD sources.
35+
36+
----------
37+
138
The FreeBSD originals of the files in this directory bear the
239
"4-clause" version of the BSD license. We have removed the
340
"advertising" clauses, as per UC Berkeley's directive here:

‎src/tools/pg_bsd_indent/README.pg_bsd_indent

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎src/tools/pg_bsd_indent/args.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void
176176
set_profile(constchar*profile_name)
177177
{
178178
FILE*f;
179-
charfname[PATH_MAX];
179+
charfname[MAXPGPATH];
180180
staticcharprof[]=".indent.pro";
181181

182182
if (profile_name==NULL)

‎src/tools/pg_bsd_indent/indent.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const char *in_name = "Standard Input";/* will always point to name of input
6060
* file */
6161
constchar*out_name="Standard Output";/* will always point to name
6262
* of output file */
63-
charbakfile[MAXPATHLEN]="";
63+
charbakfile[MAXPGPATH]="";
6464

6565
int
6666
main(intargc,char**argv)
@@ -207,7 +207,7 @@ main(int argc, char **argv)
207207
* the file */
208208
errx(1,"input and output files must be different");
209209
}
210-
output=fopen(out_name,"w");
210+
output=fopen(out_name,"wb");
211211
if (output==NULL)/* check for create error */
212212
err(1,"%s",out_name);
213213
continue;
@@ -1232,7 +1232,7 @@ bakcopy(void)
12321232
if (input==NULL)
12331233
err(1,"%s",bakfile);
12341234
/* now the original input file will be the output */
1235-
output=fopen(in_name,"w");
1235+
output=fopen(in_name,"wb");
12361236
if (output==NULL) {
12371237
unlink(bakfile);
12381238
err(1,"%s",in_name);

‎src/tools/pg_bsd_indent/indent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 303746 2016-08-04 15:27:09Z pfg $");
2929
#endif
3030

31-
#definenitems(array)(sizeof (array) / sizeof (array[0]))
31+
#definenitems(x)(sizeof((x)) / sizeof((x)[0]))
3232

3333
voidadd_typename(constchar*);
3434
voidalloc_typenames(void);

‎src/tools/pg_bsd_indent/meson.build

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
2+
3+
pg_bsd_indent_sources=files(
4+
'args.c',
5+
'err.c',
6+
'indent.c',
7+
'io.c',
8+
'lexi.c',
9+
'parse.c',
10+
'pr_comment.c',
11+
)
12+
13+
if host_system=='windows'
14+
pg_bsd_indent_sources+= rc_bin_gen.process(win32ver_rc,extra_args: [
15+
'--NAME','pg_bsd_indent',
16+
'--FILEDESC','pg_bsd_indent - indent C code nicely'])
17+
endif
18+
19+
pg_bsd_indent=executable('pg_bsd_indent',
20+
pg_bsd_indent_sources,
21+
dependencies: [frontend_code],
22+
include_directories:include_directories('.'),
23+
kwargs: default_bin_args+ {
24+
'install':false,
25+
# possibly at some point do this:
26+
# 'install_dir': dir_pgxs / 'src/tools/pg_bsd_indent',
27+
},
28+
)
29+
bin_targets+= pg_bsd_indent
30+
31+
tests+= {
32+
'name':'pg_bsd_indent',
33+
'sd':meson.current_source_dir(),
34+
'bd':meson.current_build_dir(),
35+
'tap': {
36+
'tests': [
37+
't/001_pg_bsd_indent.pl',
38+
],
39+
},
40+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# pg_bsd_indent: some simple tests
2+
3+
# The test cases come from FreeBSD upstream, but this test scaffolding is ours.
4+
# Copyright (c) 2017-2023, PostgreSQL Global Development Group
5+
6+
use strict;
7+
use warnings;
8+
9+
use Cwdqw(getcwd);
10+
use File::Copy"cp";
11+
use File::Spec;
12+
13+
use PostgreSQL::Test::Utils;
14+
use Test::More;
15+
16+
# We expect to be started in the source directory (even in a VPATH build);
17+
# we want to run pg_bsd_indent in the tmp_check directory to reduce clutter.
18+
# (Also, it's caller's responsibility that pg_bsd_indent be in the PATH.)
19+
my$src_dir = getcwd;
20+
chdir${PostgreSQL::Test::Utils::tmp_check};
21+
22+
# Basic tests: pg_bsd_indent knows --version but not much else.
23+
program_version_ok('pg_bsd_indent');
24+
25+
# Run pg_bsd_indent on pre-fab test cases.
26+
# Any diffs in the generated files will be accumulated here.
27+
my$diff_file ="tests.diff";
28+
29+
# Copy support files to current dir, so *.pro files don't need to know path.
30+
while (my$file =glob("$src_dir/tests/*.list"))
31+
{
32+
cp($file,".") ||die"cp$file failed:$!";
33+
}
34+
35+
while (my$test_src =glob("$src_dir/tests/*.0"))
36+
{
37+
# extract test basename
38+
my ($volume,$directories,$test) = File::Spec->splitpath($test_src);
39+
$test =~s/\.0$//;
40+
# run pg_bsd_indent
41+
command_ok(
42+
[
43+
'pg_bsd_indent',$test_src,
44+
"$test.out","-P$src_dir/tests/$test.pro"
45+
],
46+
"pg_bsd_indent succeeds on$test");
47+
# check result matches, adding any diff to $diff_file
48+
my$result = run_log(['diff','-upd',"$test_src.stdout","$test.out" ],
49+
'>>',$diff_file);
50+
ok($result,"pg_bsd_indent output matches for$test");
51+
}
52+
53+
done_testing();

‎src/tools/pgindent/exclude_file_patterns

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ src/pl/plperl/ppport\.h$
4747
src/pl/plperl/SPI\.c$
4848
src/pl/plperl/Util\.c$
4949
#
50+
# pg_bsd_indent has its own, idiosyncratic indentation style.
51+
# We'll stick to that to permit comparison with the FreeBSD upstream.
52+
src/tools/pg_bsd_indent/.*
53+
#
5054
# Exclude any temporary installations that may be in the tree.
5155
/tmp_check/
5256
/tmp_install/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp