forked from babelfish-for-postgresql/babelfish_extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.pl
144 lines (131 loc) · 5.65 KB
/
build.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright 2023 [email protected]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use strict;
use warnings;
use Cwd qw(abs_path);
use File::Basename qw(basename dirname);
use File::Copy::Recursive qw(fcopy);
use File::Path qw(make_path remove_tree);
use File::Spec::Functions qw(catfile);
my $root_dir = dirname(abs_path(__FILE__));
my $cmake_gen_name = "Visual Studio 17 2022";
my $cmake_build_type = "RelWithDebInfo";
if (defined($ARGV[0]) && (uc($ARGV[0]) eq 'DEBUG')) {
$cmake_build_type = "Debug";
}
sub ensure_dir_empty {
my $dir = shift;
if (-d $dir) {
remove_tree($dir) or die("$!");
}
make_path($dir) or die("$!");
}
sub build_cmake_project {
my $src_dir = shift;
my $src_dir_name = basename($src_dir);
print("\nBuilding project: [$src_dir_name]\n");
my $build_dir = catfile($src_dir, "build");
ensure_dir_empty($build_dir);
chdir($build_dir);
my $conf_cmd = "cmake ..";
$conf_cmd .= " -G \"$cmake_gen_name\"";
print("$conf_cmd\n");
0 == system($conf_cmd) or die("$!");
my $build_cmd = "cmake --build .";
$build_cmd .= " --config $cmake_build_type";
print("$build_cmd\n");
0 == system($build_cmd) or die("$!");
my $install_cmd = "$build_cmd --target install";
print("$install_cmd\n");
0 == system($install_cmd) or die("$!");
}
sub build_system_stats {
my $src_dir = shift;
my $src_dir_name = basename($src_dir);
print("\nBuilding project: [$src_dir_name]\n");
$ENV{PG_INCLUDE_DIR} = catfile($ENV{PGWIN_INSTALL_DIR}, "include");
$ENV{PG_LIB_DIR} = catfile($ENV{PGWIN_INSTALL_DIR}, "lib");
my $conf = "Debug" eq $cmake_build_type ? "Debug" : "Release";
my $build_cmd = "msbuild system_stats.vcxproj";
$build_cmd .= " /p:Configuration=$conf";
$build_cmd .= " /p:Platform=x64";
$build_cmd .= " /p:PlatformToolset=v143";
print("$build_cmd\n");
0 == system($build_cmd) or die("$!");
my $dist_dir = $ENV{PGWIN_INSTALL_DIR};
my $ext_dir = catfile($dist_dir, "share", "extension");
fcopy(catfile($src_dir, "x64", $conf, "system_stats.dll"), catfile($dist_dir, "lib", "system_stats.dll")) or die("$!");
fcopy(catfile($src_dir, "x64", $conf, "system_stats.pdb"), catfile($dist_dir, "symbols", "system_stats.pdb")) or die("$!");
fcopy(catfile($src_dir, "system_stats.control"), catfile($ext_dir, "system_stats.control")) or die("$!");
fcopy(catfile($src_dir, "system_stats--1.0.sql"), catfile($ext_dir, "system_stats--1.0.sql")) or die("$!");
fcopy(catfile($src_dir, "system_stats--1.0--2.0.sql"), catfile($ext_dir, "system_stats--1.0--2.0.sql")) or die("$!");
fcopy(catfile($src_dir, "system_stats--2.0.sql"), catfile($ext_dir, "system_stats--2.0.sql")) or die("$!");
}
sub build_pgagent {
my $src_dir = shift;
my $src_dir_name = basename($src_dir);
print("\nBuilding project: [$src_dir_name]\n");
$ENV{PG_CONFIG_PATH} = catfile($ENV{PGWIN_INSTALL_DIR}, "bin", "pg_config.exe");
my $build_dir = catfile($src_dir, "build");
my $dist_dir = catfile($build_dir, "dist");
ensure_dir_empty($build_dir);
chdir($build_dir);
my $conf_cmd = "cmake ..";
$conf_cmd .= " -G \"$cmake_gen_name\"";
$conf_cmd .= " -DCMAKE_INSTALL_PREFIX=\"$dist_dir\"";
print("$conf_cmd\n");
0 == system($conf_cmd) or die("$!");
my $build_cmd = "cmake --build .";
$build_cmd .= " --config $cmake_build_type";
print("$build_cmd\n");
0 == system($build_cmd) or die("$!");
my $install_cmd = "$build_cmd --target install";
print("$install_cmd\n");
0 == system($install_cmd) or die("$!");
my $ext_dir = catfile($ENV{PGWIN_INSTALL_DIR}, "share", "extension");
fcopy(catfile($dist_dir, "pgagent--4.2.sql"), catfile($ext_dir, "pgagent--4.2.sql")) or die("$!");
fcopy(catfile($dist_dir, "pgagent.control"), catfile($ext_dir, "pgagent.control")) or die("$!");
}
my $extensions_dir = catfile(dirname($root_dir), "extensions");
my $contrib_dir = catfile($root_dir, "contrib");
my $pg_hint_plan_dir = catfile($extensions_dir, "pg_hint_plan");
my $tds_fdw_dir = catfile($extensions_dir, "tds_fdw");
my $system_stats_dir = catfile($extensions_dir, "system_stats");
my $pgagent_dir = catfile($extensions_dir, "pgagent");
print("Cleaning up repos\n");
chdir($contrib_dir);
0 == system("git clean -dxf") or die("$!");
0 == system("git status") or die("$!");
build_cmake_project(catfile($contrib_dir, "babelfishpg_money"));
build_cmake_project(catfile($contrib_dir, "babelfishpg_common"));
build_cmake_project(catfile($contrib_dir, "babelfishpg_tds"));
build_cmake_project(catfile($contrib_dir, "babelfishpg_tsql"));
chdir($pg_hint_plan_dir);
0 == system("git clean -dxf") or die("$!");
0 == system("git status") or die("$!");
build_cmake_project($pg_hint_plan_dir);
chdir($tds_fdw_dir);
0 == system("git clean -dxf") or die("$!");
0 == system("git status") or die("$!");
build_cmake_project($tds_fdw_dir);
chdir($system_stats_dir);
0 == system("git clean -dxf") or die("$!");
0 == system("git status") or die("$!");
build_system_stats($system_stats_dir);
chdir($pgagent_dir);
0 == system("git clean -dxf") or die("$!");
0 == system("git status") or die("$!");
build_pgagent($pgagent_dir);
chdir($root_dir);
print("Build complete successfully\n");