Skip to content

Commit 96362f4

Browse files
committed
Problem: building unreleased extensions
Sometimes this is necessary for testing. But we depend on published versions. Solution: allow specify a path to the source code `#with_path` in code and `--path` using command line
1 parent f639129 commit 96362f4

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed

exe/pgpm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ module Pgpm
3737
option :arch, type: :string, default: Pgpm::Arch.host.name, desc: "Target architecture"
3838
option :pgdist, type: :string, default: "pgdg", desc: "Target Postgres distribution"
3939
option :pgver, type: :string, default: Pgpm::Postgres::Distribution.versions.last.to_s, desc: "Target Postgres version"
40+
option :path, type: :path, desc: "Override path to the source"
4041
argument :packages, type: :array, required: true, desc: "Package names"
4142

4243
# rubocop:disable Metrics/ParameterLists:
43-
def call(packages:, args: nil, os: nil, arch: nil, pgdist: nil, pgver: nil, pkgdir: nil)
44+
def call(packages:, args: nil, os: nil, arch: nil, pgdist: nil, pgver: nil, pkgdir: nil, path: nil)
4445
_ = args
4546
_ = os
4647
_ = pgdist
@@ -61,7 +62,7 @@ module Pgpm
6162
puts "Can't build a contrib package"
6263
exit(1)
6364
end
64-
pkg = p[version]
65+
pkg = path.nil? ? p[version] : p.new(version).with_path(path)
6566
if pkg.nil?
6667
puts "Package #{name} with version #{version} not found"
6768
exit(1)

lib/pgpm/package.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Pgpm
66
class Package
77
include Pgpm::Aspects::InheritanceTracker
88
include AbstractPackage
9-
include Sources
9+
include Source
1010
include Naming
1111
include Metadata
1212
include Dependencies
@@ -23,6 +23,7 @@ class Package
2323
include Initialization
2424
include Packaging
2525
include Contrib
26+
include WithPath
2627

2728
def inspect
2829
"#<#{self.class}:#{self.class.package_name} #{version}>"

lib/pgpm/package/sources.rb renamed to lib/pgpm/package/source.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
module Pgpm
44
class Package
5-
module Sources
5+
module Source
6+
def source
7+
raise StandardError, "no source specified"
8+
end
9+
610
def sources
711
[]
812
end

lib/pgpm/package/with_path.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
require "minitar"
4+
require "find"
5+
require "zlib"
6+
7+
module Pgpm
8+
class Package
9+
module WithPath
10+
def with_path(path)
11+
@with_path = File.absolute_path(path)
12+
self
13+
end
14+
15+
def source_url_directory_name
16+
if @with_path
17+
File.basename(@with_path)
18+
else
19+
super
20+
end
21+
end
22+
23+
def source
24+
if @with_path
25+
Pathname(@with_path)
26+
else
27+
super
28+
end
29+
end
30+
31+
def sources
32+
if @with_path
33+
[source_tar_gz]
34+
else
35+
super
36+
end
37+
end
38+
39+
private
40+
41+
def source_tar_gz
42+
Pgpm::OnDemandFile.new("sources.tar.gz", lambda {
43+
s = String.new
44+
begin
45+
dir = source
46+
sgz = Zlib::GzipWriter.new(StringIO.new(s))
47+
tar = Minitar::Output.open(sgz)
48+
Find.find(dir) do |entry|
49+
stat = File.stat(entry)
50+
data = File.directory?(entry) ? nil : File.binread(entry)
51+
info = { name: Pathname(entry).relative_path_from(File.dirname(source)).to_s,
52+
mode: stat.mode, uid: stat.uid, gid: stat.gid, mtime: stat.mtime }
53+
Minitar.pack_as_file(info, data, tar)
54+
end
55+
ensure
56+
# Closes both tar and sgz.
57+
tar.close
58+
end
59+
StringIO.open(s)
60+
})
61+
end
62+
end
63+
end
64+
end

packages/omnigres/package.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def artifacts(src = nil)
182182
rescue Git::GitExecuteError
183183
share_fix = "-e PGSHAREDIR=#{pgpath}/build/share"
184184
end
185-
unless Pgpm::Podman.run "run -ti #{share_fix} -v #{Pgpm::Cache.directory}:#{Pgpm::Cache.directory} #{PGPM_BUILD_CONTAINER_IMAGE} cmake -S #{src} -B #{src}/build -DOPENSSL_CONFIGURED=1 -DPGVER=#{Pgpm::Postgres::Distribution.in_scope.version} -DPGDIR=#{pgpath}"
185+
unless Pgpm::Podman.run "run -ti #{share_fix} -v #{source}:#{source} -v #{Pgpm::Cache.directory}:#{Pgpm::Cache.directory} #{PGPM_BUILD_CONTAINER_IMAGE} cmake -S #{src} -B #{src}/build -DOPENSSL_CONFIGURED=1 -DPGVER=#{Pgpm::Postgres::Distribution.in_scope.version} -DPGDIR=#{pgpath}"
186186
raise "Can't configure the project"
187187
end
188188

@@ -258,6 +258,7 @@ def previous_version
258258

259259
sorted_versions = self.class.package_versions.sort
260260
index = sorted_versions.index(version)
261+
return nil if index.nil?
261262
return unless index.positive?
262263

263264
@previous_version = self.class[sorted_versions[index - 1]]

0 commit comments

Comments
 (0)