Skip to content

Commit 7a827cc

Browse files
committed
fix: ensure meson build generates non-empty ivorysql_ora--1.0.sql
In meson mode, the script was opening the output file with truncate mode (>), which created an empty file before meson could capture the STDOUT output. This resulted in an empty extension file. Now in meson mode: - Do not open the output file (avoiding the truncate) - Output all content to STDOUT, which meson captures via --capture Make mode remains unchanged - it opens and writes to the file directly. This aligns with the pattern used by other scripts like generate-plerrcodes.pl and gb18030_2022's generation.
1 parent 09d80be commit 7a827cc

1 file changed

Lines changed: 19 additions & 36 deletions

File tree

contrib/ivorysql_ora/gensql.pl

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -80,46 +80,31 @@ sub sql_merge
8080
shift @ARGV;
8181
foreach my $v (@ARGV)
8282
{
83-
# Delete ivorysql_ora--x.x(--x.x).sql files generated before.
84-
unlink(File::Spec->rel2abs("ivorysql_ora--$v.sql"))
85-
if (-e File::Spec->rel2abs("ivorysql_ora--$v.sql"));
83+
# For Make mode, delete the old file first.
84+
if ($first_arg ne 'meson') {
85+
unlink(File::Spec->rel2abs("ivorysql_ora--$v.sql"))
86+
if (-e File::Spec->rel2abs("ivorysql_ora--$v.sql"));
8687

87-
# Open(create if necessary) ivorysql_ora--x.x(--x.x).sql.
88-
if ($first_arg eq 'meson'){
89-
open(OUTFILE, ">contrib/ivorysql_ora/ivorysql_ora--$v.sql")
90-
|| croak "Could not open ivorysql_ora--$v.sql : $!";
91-
}
92-
else {
88+
# Open output file for Make mode (meson mode uses STDOUT captured by meson)
9389
open(OUTFILE, ">ivorysql_ora--$v.sql")
94-
|| croak "Could not open ivorysql_ora--$v.sql : $!";
90+
|| croak "Could not open ivorysql_ora--$v.sql : $!";
9591
}
9692

97-
# Write "extension file loading information" into it.
93+
# Write "extension file loading information".
9894
# Create extension when this version is "x.x".
9995
if ($v =~ /^\d+\.\d+$/)
10096
{
101-
if ($first_arg eq 'meson'){
102-
print STDOUT '\echo Use "CREATE EXTENSION ivorysql_ora"';
103-
print STDOUT " to load this file. \\quit\n";
104-
}
105-
else
106-
{
107-
print OUTFILE '\echo Use "CREATE EXTENSION ivorysql_ora"';
108-
print OUTFILE " to load this file. \\quit\n";
109-
}
97+
my $fh = ($first_arg eq 'meson') ? *STDOUT : *OUTFILE;
98+
print $fh '\echo Use "CREATE EXTENSION ivorysql_ora"';
99+
print $fh " to load this file. \\quit\n";
110100
}
111101
# Update extension when this version is "x.x--x.x".
112102
elsif ($v =~ /^\d+\.\d+\-\-\d+\.\d+$/)
113103
{
114104
my $up2ver = (split("--", $v))[1];
115-
if ($first_arg eq 'meson'){
116-
print STDOUT '\echo Use "ALTER EXTENSION ivorysql_ora UPDATE';
117-
print STDOUT " TO \'$up2ver\'\" to load this file. \\quit\n";
118-
}
119-
else{
120-
print OUTFILE '\echo Use "ALTER EXTENSION ivorysql_ora UPDATE';
121-
print OUTFILE " TO \'$up2ver\'\" to load this file. \\quit\n";
122-
}
105+
my $fh = ($first_arg eq 'meson') ? *STDOUT : *OUTFILE;
106+
print $fh '\echo Use "ALTER EXTENSION ivorysql_ora UPDATE';
107+
print $fh " TO \'$up2ver\'\" to load this file. \\quit\n";
123108
}
124109
else
125110
{
@@ -135,25 +120,23 @@ sub sql_merge
135120
if (-e "$set--$v.sql")
136121
{
137122
# Add a newline.
138-
print OUTFILE "\n";
123+
my $fh = ($first_arg eq 'meson') ? *STDOUT : *OUTFILE;
124+
print $fh "\n";
125+
139126
# Open a sql file.
140127
open(INFILE, "<", File::Spec->rel2abs("$set--$v.sql"));
141128
while (my $line = <INFILE>)
142129
{
143130
# Delete the last tailing "\n" of this line.
144131
chomp($line);
145132
# Write.
146-
if ($first_arg eq 'meson'){
147-
print STDOUT "$line\n";
148-
}
149-
else{
150-
print OUTFILE "$line\n";
151-
}
133+
print $fh "$line\n";
152134
}
153135
close INFILE;
154136
}
155137
}
156138

157-
close OUTFILE;
139+
# Close OUTFILE for Make mode (meson mode doesn't open it)
140+
close OUTFILE if ($first_arg ne 'meson');
158141
}
159142
}

0 commit comments

Comments
 (0)