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

Commitc895e77

Browse files
committed
Reimplement pgbison and pgflex as perl scripts instead of bat files.
In the process, remove almost all knowledge of individual .y and .l files,and instead get invocation settings from the relevant make files.The exception is plpgsql's gram.y, which has a target with a differentname. It is hoped that this will make the scripts more future-proof,so that they won't require adjustment every time we add a new .l or .yfile.The logic is also notably less tortured than that forced on usby the idiosyncrasies of the Windows command processor.The .bat files are kept as thin wrappers for the perl scripts.
1 parent14f6719 commitc895e77

File tree

4 files changed

+134
-92
lines changed

4 files changed

+134
-92
lines changed

‎src/tools/msvc/pgbison.bat

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,7 @@
11
@echooff
2-
REM src/tools/msvc/pgbison.bat
3-
4-
IFNOTEXIST src\tools\msvc\buildenv.plgoto nobuildenv
5-
perl -e"require 'src/tools/msvc/buildenv.pl'; while(($k,$v) = each%%ENV) { print qq[\@SET $k=$v\n]; }"> bldenv.bat
6-
CALL bldenv.bat
7-
del bldenv.bat
8-
:nobuildenv
9-
10-
SETBV=
11-
for /F"tokens=4 usebackq"%%fin (`bison -V`)doif"!BV!"==""SETBV=%%f
12-
if"%BV%"==""goto novarexp
13-
if%BV%EQU 1.875goto bisonok
14-
if%BV%GEQ 2.2goto bisonok
15-
goto nobison
16-
:bisonok
17-
18-
if"%1"=="src\backend\parser\gram.y"call :generate%1 src\backend\parser\gram.c src\backend\parser\gram.h
19-
if"%1"=="src\backend\bootstrap\bootparse.y"call :generate%1 src\backend\bootstrap\bootparse.c
20-
if"%1"=="src\backend\replication\repl_gram.y"call :generate%1 src\backend\replication\repl_gram.c
21-
if"%1"=="src\pl\plpgsql\src\gram.y"call :generate%1 src\pl\plpgsql\src\pl_gram.c src\pl\plpgsql\src\pl_gram.h
22-
if"%1"=="src\test\isolation\specparse.y"call :generate%1 src\test\isolation\specparse.c
23-
if"%1"=="src\interfaces\ecpg\preproc\preproc.y"call :generate%1 src\interfaces\ecpg\preproc\preproc.c src\interfaces\ecpg\preproc\preproc.h
24-
if"%1"=="contrib\cube\cubeparse.y"call :generate%1 contrib\cube\cubeparse.c
25-
if"%1"=="contrib\seg\segparse.y"call :generate%1 contrib\seg\segparse.c
26-
27-
echo Unknown bison input:%1
28-
exit1
292

30-
:generate
31-
SETfn=%1
32-
SETcf=%2
33-
bison.exe -d%fn% -o%cf%
34-
iferrorlevel1exit1
35-
SEThf=%cf:~0,-2%.h
36-
ifnot"%hf%"=="%3" (
37-
copy /y%hf%%3
38-
iferrorlevel1exit1
39-
del%hf%
40-
)
41-
exit0
42-
43-
44-
:novarexp
45-
echo pgbison must be called with cmd /V:ON /C pgbison to work!
46-
exit1
47-
48-
:nobison
49-
echo WARNING! Bison install not found, or unsupported Bison version.
50-
echo Attempting to build without.
51-
exit0
3+
REM src/tools/msvc/pgbison.bat
4+
REM all the logic for this now belongs in builddoc.pl. This file really
5+
REM only exists so you don't have to type "perl src/tools/msvc/pgbison.pl"
6+
REM Resist any temptation to add any logic here.
7+
@perl src/tools/msvc/pgbison.pl%*

‎src/tools/msvc/pgbison.pl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# -*-perl-*- hey - emacs - this is a perl file
2+
3+
# src/tools/msvc/pgbison.pl
4+
5+
use strict;
6+
use File::Basename;
7+
8+
# assume we are in the postgres source root
9+
10+
require'src/tools/msvc/buildenv.pl'if-e'src/tools/msvc/buildenv.pl';
11+
12+
my ($bisonver) =`bison -V`;# grab first line
13+
$bisonver=(split(/\s+/,$bisonver))[3];# grab version number
14+
15+
unless ($bisonvereq'1.875' ||$bisonverge'2.2')
16+
{
17+
print"WARNING! Bison install not found, or unsupported Bison version.\n";
18+
print"echo Attempting to build without.\n";
19+
exit 0;
20+
}
21+
22+
my$input =shift;
23+
if ($input !~/\.y$/)
24+
{
25+
print"Input must be a .y file\n";
26+
exit 1;
27+
}
28+
elsif (!-e$input)
29+
{
30+
print"Input file$input not found\n";
31+
exit 1;
32+
}
33+
34+
(my$output =$input) =~s/\.y$/.c/;
35+
36+
# plpgsql just has to be different
37+
$output =~s/gram\.c$/pl_gram.c/if$input =~/src.pl.plpgsql.src.gram\.y$/;
38+
39+
my$makefile = dirname($input) ."/Makefile";
40+
my ($mf,$make);
41+
open($mf,$makefile);
42+
local$/ =undef;
43+
$make=<$mf>;
44+
close($mf);
45+
my$headerflag = ($make =~/\$\(BISON\)\s+-d/ ?'-d' :'');
46+
47+
system("bison$headerflag$input -o$output");
48+
exit$? >> 8;

‎src/tools/msvc/pgflex.bat

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,7 @@
11
@echooff
2-
REM src/tools/msvc/pgflex.bat
3-
4-
REM silence flex bleatings about file path style
5-
SETCYGWIN=nodosfilewarning
6-
7-
IFNOTEXIST src\tools\msvc\buildenv.plgoto nobuildenv
8-
perl -e"require 'src/tools/msvc/buildenv.pl'; while(($k,$v) = each%%ENV) { print qq[\@SET $k=$v\n]; }"> bldenv.bat
9-
CALL bldenv.bat
10-
del bldenv.bat
11-
:nobuildenv
12-
13-
flex -V>NUL
14-
iferrorlevel1goto noflex
152

16-
if"%1"=="src\backend\parser\scan.l"call :generate%1 src\backend\parser\scan.c -CF
17-
if"%1"=="src\backend\bootstrap\bootscanner.l"call :generate%1 src\backend\bootstrap\bootscanner.c
18-
if"%1"=="src\backend\utils\misc\guc-file.l"call :generate%1 src\backend\utils\misc\guc-file.c
19-
if"%1"=="src\backend\replication\repl_scanner.l"call :generate%1 src\backend\replication\repl_scanner.c
20-
if"%1"=="src\test\isolation\specscanner.l"call :generate%1 src\test\isolation\specscanner.c
21-
if"%1"=="src\interfaces\ecpg\preproc\pgc.l"call :generate%1 src\interfaces\ecpg\preproc\pgc.c
22-
if"%1"=="src\bin\psql\psqlscan.l"call :generate%1 src\bin\psql\psqlscan.c
23-
if"%1"=="contrib\cube\cubescan.l"call :generate%1 contrib\cube\cubescan.c
24-
if"%1"=="contrib\seg\segscan.l"call :generate%1 contrib\seg\segscan.c
25-
26-
echo Unknown flex input:%1
27-
exit1
28-
29-
REM For non-reentrant scanners we need to fix up the yywrap macro definition
30-
REM to keep the MS compiler happy.
31-
REM For reentrant scanners (like the core scanner) we do not
32-
REM need to (and must not) change the yywrap definition.
33-
:generate
34-
flex%3 -o%2%1
35-
iferrorlevel1exit%errorlevel%
36-
perl -n -e"exit 1 if /^\%%option\s+reentrant/;"%1
37-
iferrorlevel1exit0
38-
perl -pi.bak -e"s/yywrap\(n\)/yywrap()/;"%2
39-
iferrorlevel1exit%errorlevel%
40-
del%2.bak
41-
exit0
42-
43-
:noflex
44-
echo WARNING! flex install not found, attempting to build without
45-
exit0
3+
REM src/tools/msvc/pgflex.bat
4+
REM all the logic for this now belongs in builddoc.pl. This file really
5+
REM only exists so you don't have to type "perl src/tools/msvc/pgflex.pl"
6+
REM Resist any temptation to add any logic here.
7+
@perl src/tools/msvc/pgflex.pl%*

‎src/tools/msvc/pgflex.pl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# -*-perl-*- hey - emacs - this is a perl file
2+
3+
# src/tools/msvc/pgflex.pl
4+
5+
# silence flex bleatings about file path style
6+
$ENV{CYGWIN} ='nodosfilewarning';
7+
8+
use strict;
9+
use File::Basename;
10+
11+
# assume we are in the postgres source root
12+
13+
require'src/tools/msvc/buildenv.pl'if-e'src/tools/msvc/buildenv.pl';
14+
15+
system('flex -V > NUL');
16+
if ($? != 0)
17+
{
18+
print"WARNING! flex install not found, attempting to build without\n";
19+
exit 0;
20+
}
21+
22+
my$input =shift;
23+
if ($input !~/\.l$/)
24+
{
25+
print"Input must be a .l file\n";
26+
exit 1;
27+
}
28+
elsif (!-e$input)
29+
{
30+
print"Input file$input not found\n";
31+
exit 1;
32+
}
33+
34+
(my$output =$input) =~s/\.l$/.c/;
35+
36+
# get flex flags from make file
37+
my$makefile = dirname($input) ."/Makefile";
38+
my ($mf,$make);
39+
open($mf,$makefile);
40+
local$/ =undef;
41+
$make=<$mf>;
42+
close($mf);
43+
my$flexflags = ($make =~/^\s*FLEXFLAGS\s*=\s*(\S.*)/m ?$1 :'');
44+
45+
system("flex$flexflags -o$output$input");
46+
if ($? == 0)
47+
{
48+
49+
# For non-reentrant scanners we need to fix up the yywrap macro definition
50+
# to keep the MS compiler happy.
51+
# For reentrant scanners (like the core scanner) we do not
52+
# need to (and must not) change the yywrap definition.
53+
my$lfile;
54+
open($lfile,$input) ||die"opening$input for reading:$!";
55+
my$lcode = <$lfile>;
56+
close($lfile);
57+
if ($lcode !~/\%option\sreentrant/)
58+
{
59+
my$cfile;
60+
open($cfile,$output) ||die"opening$output for reading:$!";
61+
my$ccode = <$cfile>;
62+
close($cfile);
63+
$ccode =~s/yywrap\(n\)/yywrap()/;
64+
open($cfile,">$output") ||die"opening$output for reading:$!";
65+
print$cfile$ccode;
66+
close($cfile);
67+
}
68+
69+
exit 0;
70+
71+
}
72+
else
73+
{
74+
exit$? >> 8;
75+
}
76+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp