qrpm 0.0.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example.yml +30 -0
- data/exe/qrpm +12 -8
- data/lib/qrpm/parser.rb +31 -2
- data/lib/qrpm/rpm.rb +18 -13
- data/lib/qrpm/template.erb +2 -0
- data/lib/qrpm/template.yml +1 -0
- data/lib/qrpm/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75abaaf1244589f445a86adcd727e7c4b904ef43ca901d85efac65fdfbd01fac
|
4
|
+
data.tar.gz: 267f7d0505c1e802ea1bcf2d3a11a4384d0829d3c06d1737926ced73f86cb12f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00756525e6e8e98281ed1cc92bbe2aa5c2f19cb29d4ba24becc4915b3ad00d2edf98cc1779292fab050bf5f540f97e8b71072452e49c8ff7790d6a5642d488ac
|
7
|
+
data.tar.gz: 99d94787339e6208597510b0ea2af252337bce943b0a654e75cde38b7b09b94b51369b148d14460a9cd65d1ca47517e601c7334af013c8e17608e6627cefbb9d
|
data/example.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# QRPM configuration file. See https://github.com/clrgit/qrpm
|
2
|
+
|
3
|
+
name: $pg_name-url_encode
|
4
|
+
summary: Adds the url_encode extension to postgres
|
5
|
+
description: RPM wrapper for the postgres url_encode extension (https://github.com/okbob/url_encode)
|
6
|
+
version: $(cd url_encode; git tag | tail -1 | sed 's/^v//')
|
7
|
+
|
8
|
+
requires:
|
9
|
+
- $pg_name-server
|
10
|
+
- $pg_name-libs
|
11
|
+
|
12
|
+
pg_name: $(rpm -q -qf '%{NAME}\n' -f $(readlink -f $(which pg_config)))
|
13
|
+
pg_version: $(pg_config --version | sed 's/^[^0-9]* \([0-9]\+\).*$/\1/')
|
14
|
+
pg_libdir: $(pg_config --libdir)
|
15
|
+
pg_extdir: $(pg_config --share)/extension
|
16
|
+
|
17
|
+
init:
|
18
|
+
- git submodule init
|
19
|
+
- git submodule update
|
20
|
+
|
21
|
+
make:
|
22
|
+
- cd url_encode; make
|
23
|
+
|
24
|
+
$pg_libdir:
|
25
|
+
- url_encode/src/url_encode.so
|
26
|
+
|
27
|
+
$pg_extdir:
|
28
|
+
- url_encode/url_encode.control
|
29
|
+
- url_encode/sql/url_encode--1.2.sql
|
30
|
+
|
data/exe/qrpm
CHANGED
@@ -12,6 +12,7 @@ require 'indented_io'
|
|
12
12
|
# TODO
|
13
13
|
# o Fix BuildRoot (contains absolute path)
|
14
14
|
# o Enable escape of $
|
15
|
+
# o Separate standard variable from user-variables in dump
|
15
16
|
|
16
17
|
begin
|
17
18
|
SPEC = %(
|
@@ -44,14 +45,16 @@ begin
|
|
44
45
|
files
|
45
46
|
|
46
47
|
-C,directory=EDIR
|
47
|
-
Change to directory before doing anything else
|
48
|
+
Change to directory before doing anything else. Output files are still
|
49
|
+
created in the current directory, though
|
48
50
|
|
49
51
|
-d,dump
|
50
|
-
Dump internal data and exit
|
52
|
+
Dump internal data and exit. For debug
|
51
53
|
)
|
52
54
|
|
53
|
-
opts, args = ShellOpts.process(SPEC, ARGV)
|
55
|
+
opts, args = ShellOpts.process(SPEC, ARGV, verbose: true)
|
54
56
|
|
57
|
+
currdir = Dir.getwd
|
55
58
|
Dir.chdir(opts.directory) if opts.directory?
|
56
59
|
|
57
60
|
if opts.template?
|
@@ -60,7 +63,8 @@ begin
|
|
60
63
|
exit
|
61
64
|
end
|
62
65
|
|
63
|
-
# Collect var=val settings
|
66
|
+
# Collect var=val settings into the dict hash and sets the configuration file
|
67
|
+
# if present
|
64
68
|
dict = {}
|
65
69
|
while arg = args.extract(0..1)
|
66
70
|
if arg =~ /^(.*?)=(.*)$/
|
@@ -76,9 +80,6 @@ begin
|
|
76
80
|
file ||= Qrpm::QRPM_CONFIG_FILE
|
77
81
|
::File.exist?(file) or raise "Can't find '#{file}'"
|
78
82
|
|
79
|
-
# Check if repository is clean
|
80
|
-
opts.force? || `git status --porcelain 2>/dev/null` == "" or raise "Repository is dirty"
|
81
|
-
|
82
83
|
# Load the qrpm configuration file
|
83
84
|
yaml = YAML.load(IO.read(file).sub(/^__END__\s*$/m, ""))
|
84
85
|
|
@@ -90,8 +91,11 @@ begin
|
|
90
91
|
exit
|
91
92
|
end
|
92
93
|
|
94
|
+
# Check if repository is clean
|
95
|
+
opts.force? || `git status --porcelain | grep -v '??' 2>/dev/null` == "" or raise "Repository is dirty"
|
96
|
+
|
93
97
|
target = (opts.spec? ? :spec : (opts.source? ? :srpm : :rpm))
|
94
|
-
rpm.build(target: target, file: opts.spec)
|
98
|
+
rpm.build(target: target, file: opts.spec, verbose: opts.verbose?, destdir: currdir)
|
95
99
|
|
96
100
|
rescue RuntimeError => ex
|
97
101
|
ShellOpts.error ex.message
|
data/lib/qrpm/parser.rb
CHANGED
@@ -32,9 +32,15 @@ module Qrpm
|
|
32
32
|
fields.key?(f) or raise "Missing mandatory variable: #{f}"
|
33
33
|
}
|
34
34
|
|
35
|
+
# Get full name of user
|
36
|
+
fullname = Etc.getpwnam(ENV['USER'])&.gecos
|
37
|
+
if fullname.nil? || fullname == ""
|
38
|
+
fullname = ENV['USER']
|
39
|
+
end
|
40
|
+
|
35
41
|
# Defaults for description and packager fields
|
36
42
|
fields["description"] ||= fields["summary"]
|
37
|
-
fields["packager"] ||=
|
43
|
+
fields["packager"] ||= fullname
|
38
44
|
fields["release"] ||= "0"
|
39
45
|
fields["license"] ||= "GPL"
|
40
46
|
|
@@ -42,6 +48,10 @@ module Qrpm
|
|
42
48
|
# of the variables
|
43
49
|
expand_fields
|
44
50
|
|
51
|
+
# Expand variables in directory entries. The algorithm is simpler than in
|
52
|
+
# #expand_fields because no further variable defitinitions can happend
|
53
|
+
expand_dirs
|
54
|
+
|
45
55
|
# Replace symbolic directory names
|
46
56
|
@dirs = dirs.map { |dir, files|
|
47
57
|
if DIRS.key?(dir)
|
@@ -106,6 +116,25 @@ module Qrpm
|
|
106
116
|
"logdir" => "/var/log"
|
107
117
|
}
|
108
118
|
|
119
|
+
# TODO TODO TODO
|
120
|
+
|
121
|
+
# Expand shell expansions ($(shell command))
|
122
|
+
#
|
123
|
+
def expand_shell_commands(object)
|
124
|
+
case object
|
125
|
+
when Array; object.map { |e| expand_shell_commands(e) }
|
126
|
+
when Hash; object.map { |k,v| [k, expand_shell_commands(v)] }.to_h
|
127
|
+
when String;
|
128
|
+
puts object.scan(/\$\(([^\)]+)\)/)
|
129
|
+
object.scan(/\$\(([^\)]+)\)/)
|
130
|
+
|
131
|
+
when Integer, Float, true, false, nil; object
|
132
|
+
else
|
133
|
+
raise "Illegal object: #{object}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
109
138
|
# Returns array of variables in the object. Variables can be either '$name' or
|
110
139
|
# '${name}'. The variables are returned in left-to-right order
|
111
140
|
#
|
@@ -122,7 +151,7 @@ module Qrpm
|
|
122
151
|
|
123
152
|
# Expand variables in the given string
|
124
153
|
#
|
125
|
-
# The method takes
|
154
|
+
# The method takes care to substite left-to-rigth to avoid a variable expansion
|
126
155
|
# to infer with the name of an immediately preceding variable. Eg. $a$b; if $b
|
127
156
|
# is resolved to 'c' then a search would otherwise be made for a variable named
|
128
157
|
# '$ac'
|
data/lib/qrpm/rpm.rb
CHANGED
@@ -11,8 +11,9 @@ module Qrpm
|
|
11
11
|
# license License (defaults to GPL)
|
12
12
|
# summary Short one-line description of package
|
13
13
|
# description Description
|
14
|
-
# packager Name of the packager (defaults to the
|
15
|
-
# environment variable
|
14
|
+
# packager Name of the packager (defaults to the name of the current
|
15
|
+
# user or the value of the $USER environment variable if not
|
16
|
+
# found)
|
16
17
|
# require Array of required packages
|
17
18
|
# make Controls the build process:
|
18
19
|
# null Search the top-level directory for configure or
|
@@ -42,17 +43,21 @@ module Qrpm
|
|
42
43
|
def files() @files ||= nodes.select(&:file?) end
|
43
44
|
def links() @lines ||= nodes.select(&:link?) end
|
44
45
|
|
45
|
-
def
|
46
|
-
def has_make?() ::File.exist? "make" end
|
46
|
+
def verbose?() @verbose end
|
47
47
|
|
48
|
-
def initialize(fields, nodes, template: TEMPLATE)
|
48
|
+
def initialize(fields, nodes, template: TEMPLATE, verbose: false)
|
49
49
|
@fields, @nodes = fields, nodes
|
50
50
|
@template = template
|
51
|
+
@verbose = verbose
|
52
|
+
@verb = verbose ? "" : "&>/dev/null"
|
51
53
|
end
|
52
54
|
|
53
|
-
def
|
55
|
+
def has_configure?() ::File.exist? "configure" end
|
56
|
+
def has_make?() ::File.exist? "make" end
|
57
|
+
|
58
|
+
def build(target: :rpm, file: nil, verbose: false, destdir: ".")
|
59
|
+
verb = verbose ? "" : "&>/dev/null"
|
54
60
|
Dir.mktmpdir { |rootdir|
|
55
|
-
rootdir = "/home/clr/prj/qrpm/tmp"
|
56
61
|
FileUtils.rm_rf(rootdir)
|
57
62
|
FileUtils.mkdir_p(rootdir)
|
58
63
|
|
@@ -73,7 +78,7 @@ module Qrpm
|
|
73
78
|
FileUtils.cp_r(".", tarroot, preserve: true)
|
74
79
|
|
75
80
|
# Roll tarball and put it in the SOURCES directory
|
76
|
-
system "tar zcf #{tar_path} -C #{rootdir}/tmp #{name}" or raise "Can't roll tarball"
|
81
|
+
system "tar zcf #{tar_path} -C #{rootdir}/tmp #{name} #{verb}" or raise "Can't roll tarball"
|
77
82
|
|
78
83
|
# Remove temporary tar dir
|
79
84
|
FileUtils.rm_rf tarroot
|
@@ -84,15 +89,15 @@ module Qrpm
|
|
84
89
|
|
85
90
|
# Emit spec or build RPM
|
86
91
|
if target == :spec
|
87
|
-
IO.write(spec_file, @spec)
|
92
|
+
IO.write("#{destdir}/#{spec_file}", @spec)
|
88
93
|
else
|
89
94
|
IO.write(spec_path, @spec)
|
90
|
-
system "rpmbuild -v -ba --define \"_topdir #{rootdir}\" #{rootdir}/SPECS/#{name}.spec" or
|
91
|
-
raise "Failed building RPM file"
|
95
|
+
system "rpmbuild -v -ba --define \"_topdir #{rootdir}\" #{rootdir}/SPECS/#{name}.spec #{verb}" or
|
96
|
+
raise "Failed building RPM file. Re-run with -v option to see errors"
|
92
97
|
if target == :srpm
|
93
|
-
system "cp #{rootdir}/SRPMS/*
|
98
|
+
system "cp #{rootdir}/SRPMS/* #{destdir}" or raise "Failed copying SRPM file"
|
94
99
|
elsif target == :rpm
|
95
|
-
system "cp #{rootdir}/RPMS/*/#{name}-[0-9]*
|
100
|
+
system "cp #{rootdir}/RPMS/*/#{name}-[0-9]* #{destdir}" or raise "Failed copying RPM file"
|
96
101
|
else
|
97
102
|
raise ArgumentError, "Not a valid value for :target - #{target.inspect}"
|
98
103
|
end
|
data/lib/qrpm/template.erb
CHANGED
@@ -41,6 +41,7 @@ make
|
|
41
41
|
<% end -%>
|
42
42
|
|
43
43
|
%install
|
44
|
+
<% if !nodes.empty? -%>
|
44
45
|
mkdir -p <%= nodes.map { |f| "%{buildroot}#{f.directory}" }.uniq.join(" ") %>
|
45
46
|
<% for file in files -%>
|
46
47
|
cp <%= file.file %> %{buildroot}<%= file.path %>
|
@@ -48,6 +49,7 @@ cp <%= file.file %> %{buildroot}<%= file.path %>
|
|
48
49
|
<% for link in links -%>
|
49
50
|
touch %{buildroot}<%= link.path %>
|
50
51
|
<% end -%>
|
52
|
+
<% end -%>
|
51
53
|
|
52
54
|
%files
|
53
55
|
<% for file in files -%>
|
data/lib/qrpm/template.yml
CHANGED
data/lib/qrpm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qrpm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shellopts
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- bin/setup
|
56
56
|
- clean
|
57
57
|
- cmd
|
58
|
+
- example.yml
|
58
59
|
- example/bin/a_file
|
59
60
|
- example/bin/another_file
|
60
61
|
- example/qrpm.yml
|