44
55new_extension_so=
66
7- echo $PGPM_BUILDROOT
8- echo $PGPM_EXTENSION_NAME
9- echo $PGPM_EXTENSION_VERSION
10- PG_CONFIG=" pg_config"
11- echo " pg_config: $( which pg_config) "
12- echo " pg_config sharedir: $( pg_config --sharedir) "
7+ PG_CONFIG=" ${PG_CONFIG:- " pg_config" } "
8+
9+ # When building with pbuilder on Debian, files are installed under
10+ # `$PGPM_BUILDROOT/debian/ext-name-0.0.0/` -- this path should then be
11+ # assigned to the PGPM_INSTALL_ROOT env variable. However it isn't assigned
12+ # to it (as is the case with rpm and mock), then we use PGPM_BUILDROOT instead.
13+ # In this script we're
14+ install_root=" ${PGPM_INSTALL_ROOT:- $PGPM_BUILDROOT } "
1315
1416for file in $( find $PGPM_BUILDROOT -name ' *.so' ) ; do
1517 filename=$( basename " $file " )
@@ -22,40 +24,21 @@ for file in $(find $PGPM_BUILDROOT -name '*.so'); do
2224 fi
2325done
2426
25- extdir=$PGPM_BUILDDEB $( $PG_CONFIG --sharedir) /extension
27+ extdir=$install_root $( $PG_CONFIG --sharedir) /extension
2628
2729# control files
2830default_control=$extdir /$PGPM_EXTENSION_NAME .control
2931versioned_control=$extdir /$PGPM_EXTENSION_NAME --$PGPM_EXTENSION_VERSION .control
3032controls=(" $default_control " " $versioned_control " )
3133
32- echo " PWD: $( pwd) "
33-
34- echo " ----------------------"
35- echo " extension_dirname: $extension_dirname "
36- echo " new_extension_so: $new_extension_so "
37- echo " default_control: $default_control "
38- echo " versioned_control: $versioned_control "
39- echo " extension_so: $extension_so "
40- echo " extdir: $extdir "
41- echo " PGPM_BUILDDEB: $PGPM_BUILDDEB "
42- echo " ----------------------"
43-
44- echo " CONTROLS CONTENTS"
45- echo " -----------------"
46- echo " DEFAULT CONTROL:"
47- cat $default_control
48- echo " \nVERSIONED CONTROL:"
49- cat $versioned_control
50- echo " -----------------"
51-
52- if [[ -n " $new_extension_so " ]]; then
53-
54- mv " $PGPM_BUILDDEB$extension_dirname /$extension_so " " $PGPM_BUILDDEB$extension_dirname /$new_extension_so "
34+ function rename_so() {
35+ mv " $install_root$extension_dirname /$extension_so " \
36+ " $install_root$extension_dirname /$new_extension_so "
37+ }
5538
56- echo " CHANGING EXTENSION NAME IN CONTROLS "
57- echo " ----------------------------------- "
58- # Change the extension name in controls
39+ function change_name_in_controls() {
40+ echo " CHANGING EXTENSION NAME IN CONTROL FILES "
41+ echo " ---------------------------------------- "
5942 for control in " ${controls[@]} " ; do
6043 if [[ -f " $control " ]]; then
6144 echo " $control "
@@ -65,29 +48,28 @@ if [[ -n "$new_extension_so" ]]; then
6548 sed -i " s|${extension_so% " .so" } '|${new_extension_so% " .so" } '|g" " $control "
6649 fi
6750 done
68- echo " ----------------------------------- "
51+ }
6952
70- # sql files
71- echo " SQL FILES"
72- echo " ---------"
73- for sql_file in $( find $PGPM_BUILDDEB -name ' *.sql' -type f) ; do
53+ function rename_sql_files() {
54+ echo " RENAMING EXTENSION SQL FILES"
55+ echo " ---------------------------- "
56+ for sql_file in $( find $install_root -name ' *.sql' -type f) ; do
7457 echo " $sql_file "
7558 # extension.so
7659 sed -i " s|/${extension_so} '|/${new_extension_so} '|g" " $sql_file "
7760 # extension
7861 sed -i " s|/${extension_so% " .so" } '|/${new_extension_so} '|g" " $sql_file "
7962 done
80- echo " --------- "
63+ }
8164
82- # bitcode
83-
84- pkglibdir= $PGPM_BUILDDEB $( $PG_CONFIG --pkglibdir )
65+ function rename_bitcode() {
66+ echo " RENAMING BITCODE "
67+ echo " ---------------- "
8568
69+ pkglibdir=$install_root $( $PG_CONFIG --pkglibdir)
8670 bitcode_extension=$pkglibdir /bitcode/${extension_so% " .so" }
8771 bitcode_index=$pkglibdir /bitcode/${extension_so% " .so" } .index.bc
8872
89- echo " BITCODE"
90- echo " -------"
9173 if [[ -d " ${bitcode_extension} " ]]; then
9274 echo " $bitcode_extension "
9375 mv " $bitcode_extension " " $pkglibdir /bitcode/${new_extension_so% " .so" } "
@@ -97,36 +79,42 @@ if [[ -n "$new_extension_so" ]]; then
9779 echo " $bitcode_index "
9880 mv " ${bitcode_index} " " $pkglibdir /bitcode/${new_extension_so% " .so" } .index.bc"
9981 fi
100- echo " -------"
101-
102- # includes
103- includedir=$PGPM_BUILDDEB $( $PG_CONFIG --includedir-server)
82+ }
10483
105- echo " INCLUDES"
106- echo " --------"
84+ function rename_includes() {
85+ includedir=$install_root $( $PG_CONFIG --includedir-server)
86+ echo " RENAMING INCLUDES"
87+ echo " -----------------"
10788 if [[ -d " ${includedir} /extension/$PGPM_EXTENSION_NAME " ]]; then
10889 echo " $includedir "
10990 versioned_dir=${includedir} /extension/$PGPM_EXTENSION_NAME --$PGPM_EXTENSION_VERSION
11091 mkdir -p " $versioned_dir "
11192 mv " ${includedir} /extension/$PGPM_EXTENSION_NAME " " $versioned_dir "
11293 fi
113- echo " --------"
114-
115- # TODO: share, docs, etc.
116-
117- fi
118-
94+ }
11995
12096# Make sure we don't build a default control as it belongs
12197# to another package
122- if [[ -f " $default_control " ]]; then
123- if [[ -f " $versioned_control " ]]; then
124- # We don't need default control if versioned is present
125- rm -f " $default_control "
126- else
127- # Default becomes versioned
128- mv " $default_control " " $versioned_control "
129- # Don't need default_version
130- sed -i ' /default_version/d' " $versioned_control "
98+ function handle_default_control() {
99+ if [[ -f " $default_control " ]]; then
100+ if [[ -f " $versioned_control " ]]; then
101+ # We don't need default control if versioned is present
102+ rm -f " $default_control "
103+ else
104+ # Default becomes versioned
105+ mv " $default_control " " $versioned_control "
106+ # Don't need default_version
107+ sed -i ' /default_version/d' " $versioned_control "
108+ fi
131109 fi
110+ }
111+
112+ if [[ -n " $new_extension_so " ]]; then
113+ rename_so
114+ change_name_in_controls
115+ rename_sql_files
116+ rename_bitcode
117+ rename_incluides
132118fi
119+
120+ handle_default_control
0 commit comments