Skip to content

Commit 8d0c175

Browse files
author
qount25
committed
Refactor: use completely customized debian rules file -- without calling dh in it (WIP)
1 parent e14be75 commit 8d0c175

File tree

11 files changed

+79
-73
lines changed

11 files changed

+79
-73
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_INSTALL_ROOT:-$PGPM_BUILDROOT}/$(pg_config --sharedir)/extension"
3+
ext_dir="$PGPM_INSTALL_ROOT/$(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/pg_config.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/env bash
2+
3+
# Ensure PG_CONFIG is set
4+
if [[ -z "$PG_CONFIG" ]]; then
5+
echo "Error: PG_CONFIG is not set."
6+
exit 1
7+
fi
8+
9+
# Wrapper function for pg_config
10+
pg_config_wrapper() {
11+
"$PG_CONFIG" "$@" | while read -r line; do
12+
if [[ -n "$PGPM_REDIRECT_TO_BUILDROOT" && -f "$line" || -d "$line" ]]; then
13+
echo "$PGPM_INSTALL_ROOT$line"
14+
else
15+
echo "$line"
16+
fi
17+
done
18+
}
19+
20+
# Call the wrapper function with the arguments passed to the script
21+
pg_config_wrapper "$@"

lib/pgpm/deb/scripts/prepare_artifacts.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@ new_extension_so=
66

77
PG_CONFIG="${PG_CONFIG:-"pg_config"}"
88

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}"
9+
install_root=$PGPM_INSTALL_ROOT
1510

1611
for file in $(find $PGPM_BUILDROOT -name '*.so'); do
1712
filename=$(basename "$file")

lib/pgpm/deb/templates/rules.erb

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
11
#!/usr/bin/make -f
22

3-
DEB_BUILDDIR ?= $(CURDIR)
4-
EXTENSION_NAME ?= "<%= self.package.extension_name %>"
3+
export DEB_BUILDDIR = $(CURDIR)
4+
export PGPM_BUILDROOT = $(CURDIR)
5+
export PG_CONFIG = $(shell /usr/bin/which pg_config)
6+
export PGPM_EXTENSION_NAME = "<%= self.package.extension_name %>"
7+
export PGPM_EXTENSION_VERSION = "<%= self.package.version %>"
8+
export PGPM_INSTALL_ROOT = "$(CURDIR)/debian/<%= deb_pkg_name(pkg_type) %>"
59

610
<% if pkg_type == :versioned %>
711
%:
8-
dh $@
9-
10-
override_dh_install:
11-
dh_install
12-
chmod +x "$(DEB_BUILDDIR)/prepare_artifacts.sh"
13-
find $(DEB_BUILDDIR) -type f | sort - | sed 's|^$(DEB_BUILDDIR)||' > .pgpm_before | sort
14-
export PG_CONFIG="which pg_config"; \
15-
export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \
16-
export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \
17-
export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \
18-
export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \
12+
echo " --> % rules target"
13+
14+
build:
15+
echo " --> build target"
16+
<%= self.package.build_steps.join("\n\t").gsub('$', '$$') %>
17+
18+
install: build
19+
mkdir -p $$PGPM_INSTALL_ROOT
20+
echo " --> install target"
21+
<%= self.package.install_steps.join("\n\t").gsub('$', '$$') %>
22+
chmod +x "$$DEB_BUILDDIR/prepare_artifacts.sh"
23+
find $$PGPM_INSTALL_ROOT -type f | sort - | sed 's|^$$PGPM_INSTALL_ROOT||' > .pgpm_before | sort
1924
./prepare_artifacts.sh
2025

21-
<% if self.package.configure_steps.size > 0 %>
22-
override_dh_auto_configure:
23-
<%= self.package.configure_steps.join("\n\t") %>
24-
<% end %>
26+
build-arch:
27+
echo " --> build-arch"
2528

26-
<% if self.package.build_steps.size > 0 %>
27-
override_dh_build:
28-
<%= self.package.build_steps.join("\n\t") %>
29-
<% end %>
29+
build-indep:
30+
echo " --> build-indep"
3031

31-
<% if self.package.install_steps.size > 0 %>
32-
override_dh_install:
33-
<%= self.package.install_steps.join("\n\t") %>
34-
<% end %>
32+
binary: install
33+
echo " --> binary"
34+
35+
binary-arch:
36+
echo " --> binary-arch"
37+
38+
binary-indep:
39+
echo " --> binary-indep"
40+
41+
clean:
42+
echo " --> clean"
3543

3644
<% else %>
3745
%:
3846
dh $@
3947

4048
install:
4149
echo " --> INSTALL"
42-
chmod +x "$(DEB_BUILDDIR)/install_default_control.sh"
43-
export PG_CONFIG="which pg_config"; \
44-
export PGPM_BUILDROOT="$(DEB_BUILDDIR)"; \
45-
export PGPM_EXTENSION_NAME=$(EXTENSION_NAME); \
46-
export PGPM_EXTENSION_VERSION="<%= self.package.version %>"; \
47-
export PGPM_INSTALL_ROOT="$(DEB_BUILDDIR)/debian/<%= deb_pkg_name(pkg_type) %>"; \
50+
chmod +x "$$DEB_BUILDDIR/install_default_control.sh"
4851
./install_default_control.sh
4952
<% end %>

lib/pgpm/package/dependencies.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def build_dependencies
1818
"postgresql-common"
1919
]
2020
if self.native?
21-
binding.break
2221
deps << "build-essential"
2322
end
2423
when "rocky+epel-9", "redhat", "fedora"

lib/pgpm/package/make.rb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,13 @@ class Package
55
module Make
66

77
def build_steps
8-
case Pgpm::OS.in_scope.class.name
9-
when "debian", "ubuntu"
10-
return []
11-
when "rocky+epel-9", "redhat", "fedora"
12-
return [Pgpm::Commands::Make.new("PG_CONFIG=$PG_CONFIG")] if makefile_present?
13-
end
14-
super
8+
[Pgpm::Commands::Make.new("PG_CONFIG=$PG_CONFIG")] if makefile_present?
159
end
1610

1711
def install_steps
18-
case Pgpm::OS.in_scope.class.name
19-
when "debian", "ubuntu"
20-
return []
21-
when "rocky+epel-9", "redhat", "fedora"
22-
return [Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_BUILDROOT", "PG_CONFIG=$PG_CONFIG")] if makefile_present?
12+
if makefile_present?
13+
[Pgpm::Commands::Make.new("install", "DESTDIR=$PGPM_INSTALL_ROOT", "PG_CONFIG=$PG_CONFIG")]
2314
end
24-
super
2515
end
2616

2717
def makefile_present?

lib/pgpm/rpm/scripts/pg_config.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#! /usr/bin/env bash
22

3-
#!/bin/bash
4-
53
# Ensure PG_CONFIG is set
64
if [[ -z "$PG_CONFIG" ]]; then
75
echo "Error: PG_CONFIG is not set."
@@ -12,12 +10,12 @@ fi
1210
pg_config_wrapper() {
1311
"$PG_CONFIG" "$@" | while read -r line; do
1412
if [[ -n "$PGPM_REDIRECT_TO_BUILDROOT" && -f "$line" || -d "$line" ]]; then
15-
echo "$PGPM_BUILDROOT$line"
13+
echo "$PGPM_INSTALL_ROOT$line"
1614
else
1715
echo "$line"
1816
fi
1917
done
2018
}
2119

2220
# Call the wrapper function with the arguments passed to the script
23-
pg_config_wrapper "$@"
21+
pg_config_wrapper "$@"

lib/pgpm/rpm/scripts/prepare_artifacts.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ set -xe
44

55
new_extension_so=
66

7-
for file in $(find $PGPM_BUILDROOT -name '*.so'); do
7+
for file in $(find $PGPM_INSTALL_ROOT -name '*.so'); do
88
filename=$(basename "$file")
99
if [[ "$filename" == "${PGPM_EXTENSION_NAME}.so" ]]; then
1010
extension_so=$filename
1111
dir=$(dirname "$file")
12-
extension_dirname=${dir#"$PGPM_BUILDROOT"}
12+
extension_dirname=${dir#"$PGPM_INSTALL_ROOT"}
1313
new_extension_so=$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION.so
1414
fi
1515
done
1616

17-
extdir=$PGPM_BUILDROOT$($PG_CONFIG --sharedir)/extension
17+
extdir=$PGPM_INSTALL_ROOT$($PG_CONFIG --sharedir)/extension
1818

1919
# control files
2020
default_control=$extdir/$PGPM_EXTENSION_NAME.control
@@ -24,7 +24,7 @@ controls=("$default_control" "$versioned_control")
2424

2525
if [[ -n "$new_extension_so" ]]; then
2626

27-
mv "$PGPM_BUILDROOT$extension_dirname/$extension_so" "$PGPM_BUILDROOT$extension_dirname/$new_extension_so"
27+
mv "$PGPM_INSTALL_ROOT$extension_dirname/$extension_so" "$PGPM_INSTALL_ROOT$extension_dirname/$new_extension_so"
2828

2929
# Change the extension name in controls
3030
for control in "${controls[@]}"; do
@@ -37,7 +37,7 @@ if [[ -n "$new_extension_so" ]]; then
3737
done
3838

3939
# sql files
40-
for sql_file in $(find $PGPM_BUILDROOT -name '*.sql' -type f); do
40+
for sql_file in $(find $PGPM_INSTALL_ROOT -name '*.sql' -type f); do
4141
# extension.so
4242
sed -i "s|/${extension_so}'|/${new_extension_so}'|g" "$sql_file"
4343
# extension
@@ -46,7 +46,7 @@ if [[ -n "$new_extension_so" ]]; then
4646

4747
# bitcode
4848

49-
pkglibdir=$PGPM_BUILDROOT$($PG_CONFIG --pkglibdir)
49+
pkglibdir=$PGPM_INSTALL_ROOT$($PG_CONFIG --pkglibdir)
5050

5151
bitcode_extension=$pkglibdir/bitcode/${extension_so%".so"}
5252
bitcode_index=$pkglibdir/bitcode/${extension_so%".so"}.index.bc
@@ -60,7 +60,7 @@ if [[ -n "$new_extension_so" ]]; then
6060
fi
6161

6262
# includes
63-
includedir=$PGPM_BUILDROOT$($PG_CONFIG --includedir-server)
63+
includedir=$PGPM_INSTALL_ROOT$($PG_CONFIG --includedir-server)
6464

6565
if [[ -d "${includedir}/extension/$PGPM_EXTENSION_NAME" ]]; then
6666
versioned_dir=${includedir}/extension/$PGPM_EXTENSION_NAME--$PGPM_EXTENSION_VERSION
@@ -85,4 +85,4 @@ if [[ -f "$default_control" ]]; then
8585
# Don't need default_version
8686
sed -i '/default_version/d' "$versioned_control"
8787
fi
88-
fi
88+
fi

lib/pgpm/rpm/spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ def to_s
9797
9898
%build
9999
export PG_CONFIG=$(rpm -ql #{@postgres_distribution.pg_config_package} | grep 'pg_config$')
100-
export PGPM_BUILDROOT=%{buildroot}
100+
export PGPM_INSTALL_ROOT=%{buildroot}
101101
#{@package.build_steps.map(&:to_s).join("\n")}
102102
103103
%install
104104
export PG_CONFIG=$(rpm -ql #{@postgres_distribution.pg_config_package} | grep 'pg_config$')
105-
export PGPM_BUILDROOT=%{buildroot}
105+
export PGPM_INSTALL_ROOT=%{buildroot}
106106
cp %{SOURCE#{sources.find_index { |src| src.name == "pg_config.sh" }}} ./pg_config.sh
107107
chmod +x ./pg_config.sh
108108
find %{buildroot} -type f | sort - | sed 's|^%{buildroot}||' > .pgpm_before | sort

packages/omnigres/package.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,17 @@ def build_steps
8888

8989
def install_steps
9090
steps = [
91-
"mkdir -p $PGPM_BUILDROOT/$($PG_CONFIG --sharedir)/extension",
92-
"mkdir -p $PGPM_BUILDROOT/$($PG_CONFIG --pkglibdir)",
91+
"mkdir -p $PGPM_INSTALL_ROOT/$($PG_CONFIG --sharedir)/extension",
92+
"mkdir -p $PGPM_INSTALL_ROOT/$($PG_CONFIG --pkglibdir)",
9393
# Package .so artifacts
94-
"find build/packaged -name '#{name}*.so' -type f -exec cp {} $PGPM_BUILDROOT/$($PG_CONFIG --pkglibdir) \\;",
94+
"find build/packaged -name '#{name}*.so' -type f -exec cp {} $PGPM_INSTALL_ROOT/$($PG_CONFIG --pkglibdir) \\;",
9595
# Package version-specific control file
96-
"cp build/packaged/extension/#{name}--#{version}.control $PGPM_BUILDROOT/$($PG_CONFIG --sharedir)/extension",
96+
"cp build/packaged/extension/#{name}--#{version}.control $PGPM_INSTALL_ROOT/$($PG_CONFIG --sharedir)/extension",
9797
# Package version-specific init file
98-
"cp build/packaged/extension/#{name}--#{version}.sql $PGPM_BUILDROOT/$($PG_CONFIG --sharedir)/extension"
98+
"cp build/packaged/extension/#{name}--#{version}.sql $PGPM_INSTALL_ROOT/$($PG_CONFIG --sharedir)/extension"
9999
]
100100
if previous_version && !previous_version.broken? && !@no_migration
101-
steps.push("cp build/packaged/extension/#{name}--#{previous_version.version}--#{version}.sql $PGPM_BUILDROOT/$($PG_CONFIG --sharedir)/extension")
101+
steps.push("cp build/packaged/extension/#{name}--#{previous_version.version}--#{version}.sql $PGPM_INSTALL_ROOT/$($PG_CONFIG --sharedir)/extension")
102102
end
103103
steps
104104
end

packages/timescale/timescaledb.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def install_steps
5252
when "debian", "ubuntu"
5353
[]
5454
when "rocky+epel-9", "redhat", "fedora"
55-
["DESTDIR=$PGPM_BUILDROOT cmake --build build --target install"]
55+
["DESTDIR=$PGPM_INSTALL_ROOT cmake --build build --target install"]
5656
end
5757
end
5858

0 commit comments

Comments
 (0)