Skip to content

Commit 8de62ed

Browse files
author
qount25
committed
Refactor: prepare_artifacts in deb/
1 parent cb58e0a commit 8de62ed

File tree

4 files changed

+56
-117
lines changed

4 files changed

+56
-117
lines changed

lib/pgpm/deb/scripts/install_default_control.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
ext_dir="$PGPM_BUILDDEB/$(pg_config --sharedir)/extension"
3+
ext_dir="${PGPM_INSTALL_ROOT:-$PGPM_BUILDROOT}/$(pg_config --sharedir)/extension"
44
control_fn="$ext_dir/$PGPM_EXTENSION_NAME.control"
55

66
echo "Creating extension dir: $ext_dir"

lib/pgpm/deb/scripts/prepare_artifacts.sh

Lines changed: 53 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
new_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

1416
for 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
2325
done
2426

25-
extdir=$PGPM_BUILDDEB$($PG_CONFIG --sharedir)/extension
27+
extdir=$install_root$($PG_CONFIG --sharedir)/extension
2628

2729
# control files
2830
default_control=$extdir/$PGPM_EXTENSION_NAME.control
2931
versioned_control=$extdir/$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION.control
3032
controls=("$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
132118
fi
119+
120+
handle_default_control

lib/pgpm/deb/templates/rules.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ override_dh_install:
1515
export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \
1616
export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \
1717
export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \
18-
export PGPM_BUILDDEB="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \
18+
export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \
1919
./prepare_artifacts.sh
2020

2121
<%= self.package.build_info[:rules] %>
@@ -35,6 +35,6 @@ install:
3535
export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \
3636
export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \
3737
export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \
38-
export PGPM_BUILDDEB="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \
38+
export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \
3939
./install_default_control.sh
4040
<% end %>

pgpm.gemspec

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

0 commit comments

Comments
 (0)