qrpm 0.1.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/NOTES +7 -0
- data/TODO +30 -0
- data/doc/pg.yml +37 -0
- data/doc/qrpm2.rb +69 -0
- data/doc/qrpm2.yml +55 -0
- data/example/configure +0 -0
- data/example/make +0 -0
- data/example/my_package_name-1.2.3-4.x86_64.rpm +0 -0
- data/example/my_package_name.spec +49 -0
- data/example.yml +69 -15
- data/exe/qrpm +133 -44
- data/lib/qrpm/compiler.rb +238 -0
- data/lib/qrpm/fragment.rb +177 -0
- data/lib/qrpm/lexer.rb +41 -0
- data/lib/qrpm/node.rb +372 -31
- data/lib/qrpm/qrpm.rb +182 -53
- data/lib/qrpm/rpm.rb +105 -61
- data/lib/qrpm/template.erb +28 -29
- data/lib/qrpm/template.yml +15 -12
- data/lib/qrpm/utils.rb +10 -0
- data/lib/qrpm/version.rb +1 -1
- data/lib/qrpm.rb +107 -1
- data/qrpm.gemspec +3 -3
- metadata +50 -10
- data/lib/qrpm/parser.rb +0 -202
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a29e53e76de18751fc16a216ae6add03606f98c4d5b26e8dbdce28f5246d5ce
|
4
|
+
data.tar.gz: 30f123b324fb34ac66cd64ee4e2b1c9a292d231485658be1ebb057770392522c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2a572a1f28b482c99b1021ab4a58da87fe0a37faa613e737bc75648796748409d3fd41b7a1cf6901854707c306ce98e70638d2110993fee55811911d1dc1e7b
|
7
|
+
data.tar.gz: 4a6ea425d7bae8cbddabb19f2f34b304354676a625a3390cdcc4f2cfba19f72f978b6c27ed087dfd2522ed6f73eea5f99ccbfa531f725340767e898e6d1ffb4b
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-
|
1
|
+
ruby-3.1.2
|
data/NOTES
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
|
2
|
+
Random notes that should make it into the documention
|
3
|
+
|
4
|
+
o Directory nodes are top-level array definitions, optionally suffix with a /
|
5
|
+
o Only DirectoryNode keys can include a '/'
|
6
|
+
o Only DirectoryNode keys can include variables. What about this:
|
7
|
+
o DirectoryNodes can't be referenced
|
data/TODO
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
o Rule: Symbol keys are variables, String keys are directories
|
2
|
+
|
3
|
+
o Use Nodes everywhere -> makes a lot of stuff much easier
|
4
|
+
|
5
|
+
o Check "dir: file" vs. "dir:\n - file"
|
6
|
+
|
7
|
+
o Allow shell escapes to return arrays and hashes
|
8
|
+
|
9
|
+
o Allow directories within directories:
|
10
|
+
dir/
|
11
|
+
- file
|
12
|
+
- subdir/
|
13
|
+
- element # Oops: Illegal YAML syntax
|
14
|
+
|
15
|
+
o What happens if directory declarations maps to the same:
|
16
|
+
dir1: dir
|
17
|
+
dir2: dir
|
18
|
+
$dir1:
|
19
|
+
- file
|
20
|
+
$dir2:
|
21
|
+
- file
|
22
|
+
|
23
|
+
o Use same naming everywhere: field vs. value, name vs. path etc.
|
24
|
+
- "fields" are variables that also are RPM fields
|
25
|
+
- "variables" are QRPM variables
|
26
|
+
|
27
|
+
o Better references to source in error messages: Read input file(s) in parallel
|
28
|
+
with parsing of the YAML document (doesn't work with YAML merge/include). Maybe
|
29
|
+
decorate strings with lineno/charno and if the YAML module fails we catch the
|
30
|
+
error and remove the decoration from the error message
|
data/doc/pg.yml
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
# Default Redhat Postgres definititions
|
3
|
+
pg:
|
4
|
+
name: "postgres" # Name of the package. It is also the default name for package-specific diretories
|
5
|
+
vendor: "redhat"
|
6
|
+
version: null # To be specified explicitly or detected dynamically using detect.pg.version
|
7
|
+
major_version: $(sed 's/\..*//' <<<${{pg.version}})
|
8
|
+
pckdir: pgsql
|
9
|
+
etcdir: $pg.vardir/data
|
10
|
+
vardir: $vardir/$pg.pckdir
|
11
|
+
libdir: $libdir/$pg.pckdir # Assuming libdir points to /usr/lib64
|
12
|
+
extdir: $pg.libdir/extension
|
13
|
+
sharedir: $sharedir/$pg.pckdir
|
14
|
+
|
15
|
+
conf_file: $pg.etcdir/postgresql.conf
|
16
|
+
hba_file: $pg.etcdir/pg_hba.conf
|
17
|
+
ident_file: $pg.etcdir/pg_ident.conf
|
18
|
+
|
19
|
+
# Detections
|
20
|
+
detect:
|
21
|
+
pg:
|
22
|
+
version: $(pg_config --version | sed 's/^[^0-9]* \([0-9]\+\).*$/\1/')
|
23
|
+
|
24
|
+
# pgdg overrides
|
25
|
+
pg:
|
26
|
+
name: postgresql$pg.version
|
27
|
+
vendor: "pgdg"
|
28
|
+
version: null
|
29
|
+
vardir: $vardir/$pg.pckdir/$pg.major_version
|
30
|
+
usrdir: /usr/pgsql-$pg.major_version
|
31
|
+
libdir: $pg.usrdir/lib
|
32
|
+
extdir: $pg.libdir/extension
|
33
|
+
sharedir: $pg.usrdir/share
|
34
|
+
|
35
|
+
pg.version: $detect.pg.version
|
36
|
+
|
37
|
+
|
data/doc/qrpm2.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
p YAML.load(IO.read("t.yml"))
|
6
|
+
|
7
|
+
exit
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
require 'indented_io'
|
14
|
+
|
15
|
+
s = "member"
|
16
|
+
|
17
|
+
s =~ /^(\w+)|\[(\d+)\](?:\.|$)/
|
18
|
+
p $1
|
19
|
+
p $2
|
20
|
+
|
21
|
+
|
22
|
+
__END__
|
23
|
+
|
24
|
+
a = "1. $a 2. \\$a 3. \\\\$a 4. \\\\\\$a 5. \\\\\\\\$a rest"
|
25
|
+
b = "1. ${a} 2. \\${a} 3. \\\\${a} 4. \\\\\\${a} 5. \\\\\\\\${a} rest"
|
26
|
+
c = "1. $(a)"
|
27
|
+
d = "1. $a $(b $b ${b} ${{b}}) $c \\"
|
28
|
+
|
29
|
+
IDENT_RE = /(?:[\w_][\w\d_.]*)/
|
30
|
+
|
31
|
+
# Return an array of prefix/interpolated-variable tuples. The prefix is the
|
32
|
+
# string leading up to the variable. $NAME, ${NAME}, and $(COMMAND)
|
33
|
+
# interpolations are recognized
|
34
|
+
def parse_string(path, string)
|
35
|
+
r = string.scan(/(.*?)(\\*)(\$#{IDENT_RE}|\$\{#{IDENT_RE}\}|\$\(.+\)|$)/).map {
|
36
|
+
|prefix, backslashes, interpolation|
|
37
|
+
p [prefix, backslashes, interpolation]
|
38
|
+
|
39
|
+
|
40
|
+
str = prefix + '\\' * (backslashes.size / 2)
|
41
|
+
if backslashes.size % 2 == 0
|
42
|
+
var = interpolation
|
43
|
+
else
|
44
|
+
str += '\\' * (backslashes.size % 2) + interpolation
|
45
|
+
end
|
46
|
+
[str, var]
|
47
|
+
}[0..-2]
|
48
|
+
puts
|
49
|
+
r
|
50
|
+
end
|
51
|
+
|
52
|
+
#parse_string("a", a).each { |e| p e }
|
53
|
+
#exit
|
54
|
+
|
55
|
+
for s in [a, b, c, d]
|
56
|
+
puts "\"#{s}\""
|
57
|
+
indent {
|
58
|
+
parse_string("fake", s).each { |a|
|
59
|
+
p a
|
60
|
+
}
|
61
|
+
}
|
62
|
+
puts
|
63
|
+
end
|
64
|
+
|
65
|
+
#p a.scan(/\S+\s\S+/)
|
66
|
+
|
67
|
+
|
68
|
+
exit
|
69
|
+
|
data/doc/qrpm2.yml
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Qrpm with "functions"
|
2
|
+
---
|
3
|
+
|
4
|
+
# User-code
|
5
|
+
#
|
6
|
+
pg:
|
7
|
+
vendor: pgdg
|
8
|
+
|
9
|
+
$user_dir:
|
10
|
+
- $pg.postgresql_conf
|
11
|
+
|
12
|
+
# Standard global variables
|
13
|
+
# platform (redhat/debian/etc)
|
14
|
+
# vendor (only defined for third-party packages)
|
15
|
+
# domain (the network)
|
16
|
+
# host (the host)
|
17
|
+
#
|
18
|
+
# The standard variables are ordered
|
19
|
+
|
20
|
+
pg:
|
21
|
+
etcdir: $(detect)
|
22
|
+
datadir: $(detect)
|
23
|
+
postgresql_conf: ${pg.etcdir}/postgresql.conf
|
24
|
+
pg_hba_conf: ${pg.etcdir}/pg_hba.conf
|
25
|
+
pg_ident_conf: ${pg.etcdir}/pg_ident.conf
|
26
|
+
|
27
|
+
pg(platform=redhat):
|
28
|
+
etcdir: ${pg.datadir}
|
29
|
+
datadir: $pcklidir/data
|
30
|
+
|
31
|
+
pg(platform=debian):
|
32
|
+
etcdir: $pcketcdir
|
33
|
+
datadir: /var/lib/pgsql/data
|
34
|
+
|
35
|
+
# 'plaform=*' to make this more specific than the default. Not needed if
|
36
|
+
# standard variables are ordered
|
37
|
+
pg(platform=*,vendor=pgdg):
|
38
|
+
datadir: $pcklibdir/${pg.version}/data
|
39
|
+
|
40
|
+
pg(platform=debian,vendor=pgdg):
|
41
|
+
etcdir: $pcketcdir/${pg.version}
|
42
|
+
|
43
|
+
pg(platform=redhat,vendor=pgdg):
|
44
|
+
etcdir: ${pg.datadir}
|
45
|
+
|
46
|
+
# nested expressions
|
47
|
+
#
|
48
|
+
pg(vendor=pgdg):
|
49
|
+
datadir: $pcklibdir/${pg.version}/data
|
50
|
+
platform=redhat:
|
51
|
+
etcdir: ${pg.datadir}
|
52
|
+
platform=debian:
|
53
|
+
etcdir: $pckectdir/${pg.version}
|
54
|
+
|
55
|
+
|
data/example/configure
ADDED
File without changes
|
data/example/make
ADDED
File without changes
|
Binary file
|
@@ -0,0 +1,49 @@
|
|
1
|
+
|
2
|
+
Name: my_package_name
|
3
|
+
Summary: This is a summary of the package
|
4
|
+
Version: 1.2.3
|
5
|
+
Release: 4
|
6
|
+
License: GPL
|
7
|
+
Packager: clr
|
8
|
+
Requires: ruby
|
9
|
+
Requires: httpd
|
10
|
+
Requires: postgresql13
|
11
|
+
Source: %{name}.tar.gz
|
12
|
+
BuildRoot: /tmp/d20220502-22446-8neiew/tmp/%{name}-%{version}
|
13
|
+
|
14
|
+
%description
|
15
|
+
Optional longer description of the package
|
16
|
+
|
17
|
+
%prep
|
18
|
+
%setup -n my_package_name
|
19
|
+
|
20
|
+
%build
|
21
|
+
my_configure; my_make
|
22
|
+
|
23
|
+
%install
|
24
|
+
mkdir -p %{buildroot}/usr/bin %{buildroot}/usr/sbin %{buildroot}/usr/share/my_package_name %{buildroot}/var/lib
|
25
|
+
cp bin/a_file %{buildroot}/usr/bin/a_file
|
26
|
+
cp bin/another_file %{buildroot}/usr/bin/another_file
|
27
|
+
cp bin/a_file %{buildroot}/usr/bin/an_alias
|
28
|
+
cp share/some_data %{buildroot}/usr/share/my_package_name/some_data
|
29
|
+
cp share/some_other_data %{buildroot}/var/lib/some_other_data
|
30
|
+
touch %{buildroot}/usr/sbin/a_file
|
31
|
+
|
32
|
+
%files
|
33
|
+
/usr/bin/a_file
|
34
|
+
/usr/bin/another_file
|
35
|
+
/usr/bin/an_alias
|
36
|
+
/usr/share/my_package_name/some_data
|
37
|
+
/var/lib/some_other_data
|
38
|
+
%ghost /usr/sbin/a_file
|
39
|
+
|
40
|
+
%clean
|
41
|
+
%if "%{clean}" != ""
|
42
|
+
rm -rf %{_topdir}/BUILD/%{name}
|
43
|
+
[ $(basename %{buildroot}) == "%{name}-%{version}-%{release}.%{_target_cpu}" ] && rm -rf %{buildroot}
|
44
|
+
%endif
|
45
|
+
|
46
|
+
%post
|
47
|
+
|
48
|
+
ln -sf /bin/a_file /usr/sbin/a_file
|
49
|
+
|
data/example.yml
CHANGED
@@ -1,30 +1,84 @@
|
|
1
1
|
# QRPM configuration file. See https://github.com/clrgit/qrpm
|
2
2
|
|
3
|
+
# program ::= directory...
|
4
|
+
# directory ::= field... directory...
|
5
|
+
# field ::= key '*' value
|
6
|
+
# directory ::= array(string)
|
7
|
+
#
|
8
|
+
# TODO
|
9
|
+
# o Use '@' instead of '$'. Yields @name and @{name} that doesn't interfere
|
10
|
+
# with bash expansion
|
11
|
+
#
|
12
|
+
#
|
13
|
+
# ${{name}} in $(...)
|
14
|
+
# QRPM dependency check variable definitions and needs to be able to detect
|
15
|
+
# variable usages in $(...) constructs
|
16
|
+
|
17
|
+
# @include git-project
|
18
|
+
# -> version: $(cd ${{srcdir}}; git tag | tail -1 | sed 's/^v//')
|
19
|
+
#
|
20
|
+
# @include postgres-project prefix: pg_
|
21
|
+
# -> pg_name
|
22
|
+
# pg_version
|
23
|
+
# pg_libdir
|
24
|
+
# pg_sharedir
|
25
|
+
#
|
26
|
+
# @include postgres-project git@github.com:... commit-id
|
27
|
+
#
|
28
|
+
# @include redhat/httpd
|
29
|
+
# @include redhat/pg
|
30
|
+
# @include pgdg
|
31
|
+
#
|
32
|
+
# pg.version: 14
|
33
|
+
# pg: pgdg[14]
|
34
|
+
|
3
35
|
name: $pg_name-url_encode
|
4
|
-
summary: Adds the url_encode extension to postgres
|
36
|
+
summary: Adds the 'url_encode' extension to postgres ${pg.version}
|
5
37
|
description: RPM wrapper for the postgres url_encode extension (https://github.com/okbob/url_encode)
|
6
|
-
version: $(cd
|
38
|
+
version: $(cd ${{srcdir}}; git tag | tail -1 | sed 's/^v//')
|
39
|
+
# ^Oops, hardcoded FIXME: Have a dependency graph and use some standard algorithm
|
40
|
+
|
41
|
+
include:
|
42
|
+
- ./qrpm.includes
|
7
43
|
|
8
44
|
requires:
|
9
45
|
- $pg_name-server
|
10
46
|
- $pg_name-libs
|
11
47
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
48
|
+
a: $b
|
49
|
+
b: $c
|
50
|
+
c: $a
|
51
|
+
# Idea
|
52
|
+
#submod: url_encode
|
53
|
+
#subdir: url_encode
|
54
|
+
#patches:
|
55
|
+
# - patch/patch1.patch
|
56
|
+
srcdir: url_encode
|
16
57
|
|
17
|
-
|
18
|
-
|
19
|
-
|
58
|
+
root: ""
|
59
|
+
|
60
|
+
pg:
|
61
|
+
name: $(rpm -q --qf '%{NAME}\n' -f $(readlink -f $(which pg_config)))
|
62
|
+
version: $(pg_config --version | sed 's/^[^0-9]* \([0-9]\+\).*$/\1/')
|
63
|
+
major: $version
|
64
|
+
libdir: $(pg_config --libdir)
|
65
|
+
sharedir: $(pg_config --sharedir)
|
66
|
+
|
67
|
+
#init: # FIXME Doesn't work atm
|
68
|
+
# - git submodule init
|
69
|
+
# - git submodule update
|
20
70
|
|
21
71
|
make:
|
22
|
-
- cd
|
72
|
+
- cd $srcdir; make
|
73
|
+
|
74
|
+
${pg.sharedir}/extension:
|
75
|
+
- $srcdir/url_encode.control
|
76
|
+
- $srcdir/sql/url_encode--1.2.sql
|
23
77
|
|
24
|
-
$
|
25
|
-
-
|
78
|
+
${pg.libdir}:
|
79
|
+
- $srcdir/src/url_encode.so
|
80
|
+
- $srcdir/postgresql$version
|
26
81
|
|
27
|
-
$
|
28
|
-
-
|
29
|
-
- url_encode/sql/url_encode--1.2.sql
|
82
|
+
$root/somedir:
|
83
|
+
- $srcdir/somefile
|
30
84
|
|
data/exe/qrpm
CHANGED
@@ -7,30 +7,69 @@ require_relative '../lib/qrpm.rb'
|
|
7
7
|
|
8
8
|
require 'yaml'
|
9
9
|
require 'shellopts'
|
10
|
-
require 'indented_io'
|
11
10
|
|
12
11
|
# TODO
|
13
12
|
# o Fix BuildRoot (contains absolute path)
|
14
|
-
#
|
15
|
-
#
|
13
|
+
#
|
14
|
+
# + Separate standard variables from user-variables in dump
|
15
|
+
# + Enable escape of $
|
16
|
+
# + Support for $(...) constructs
|
16
17
|
|
17
18
|
begin
|
18
19
|
SPEC = %(
|
19
|
-
@
|
20
|
+
@ Make simple RPMs simple
|
20
21
|
|
21
|
-
|
22
|
+
-- VARIABLE=VALUE... [QRPM-FILE]
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
terminates the file and that $NAME or ${NAME} are variables that will be
|
26
|
-
expanded. The variables can either be specified in the configuration file
|
27
|
-
or given on the command line in <variable>=<value> format
|
24
|
+
'qrpm' creates a RPM package from a qrpm.yml specification file. It aims at
|
25
|
+
packaging shell scripts or simple executables/libraries with minimum effort
|
28
26
|
|
29
|
-
|
27
|
+
The qrpm.yml specification file is a YAML file. The simplest qrpm file
|
28
|
+
contains just one line:
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
$bindir: my_executable_script
|
31
|
+
|
32
|
+
Running qrpm using this file will yield a RPM package that installs the
|
33
|
+
script into the standard /usr/bin directory. The name of the package
|
34
|
+
is set to the name of the current directory and version to the latest tag
|
35
|
+
in git (which needs to be present). Other defaults are detailed below
|
36
|
+
|
37
|
+
VARIABLES
|
38
|
+
|
39
|
+
The configuration file can define and use variables. They are defined by
|
40
|
+
key/value definitions and the value can refer to values of other
|
41
|
+
variables using $NAME or ${NAME}. Variables can also be given on the
|
42
|
+
command line in <variable>=<value> format
|
43
|
+
|
44
|
+
$(...) constructs are commands that are executed by bash(1). The parser
|
45
|
+
considers everything from the opening '$(' to the last ')' on the line as
|
46
|
+
part of the command so only one command is allowed. This restriction keeps
|
47
|
+
the parser simple, it may change in the future
|
48
|
+
|
49
|
+
INCLUDE FILES
|
50
|
+
|
51
|
+
The qrpm file can include other files that are searched for in a list of
|
52
|
+
directories. Relative paths are relative to the directory of the qrpm file
|
53
|
+
(but see the -C option). The search directories can be set on the command
|
54
|
+
line using the -I option
|
55
|
+
|
56
|
+
BUILT-IN VARIABLES
|
57
|
+
|
58
|
+
INSTALLATION DIRECTORIES
|
59
|
+
|
60
|
+
OPTIONS
|
61
|
+
|
62
|
+
-f,force
|
63
|
+
Create package even if repository is dirty. Normally qrpm checks if the
|
64
|
+
current directory is clean
|
65
|
+
|
66
|
+
-C,directory=EDIR
|
67
|
+
Change to directory before doing anything else but include the current
|
68
|
+
directory in the search path. This makes it possible to override parts of
|
69
|
+
a spec file
|
70
|
+
|
71
|
+
+I,include=EDIR
|
72
|
+
Include directory, later definitions are searched first
|
34
73
|
|
35
74
|
-s,spec=OFILE?
|
36
75
|
Only create the spec file and not the RPM package. Use this option to
|
@@ -39,65 +78,115 @@ begin
|
|
39
78
|
-S,source
|
40
79
|
Create a source RPM file instead of a regular RPM file
|
41
80
|
|
42
|
-
-
|
43
|
-
|
44
|
-
|
45
|
-
|
81
|
+
-t,template=OFILE?
|
82
|
+
Generate a QRPM template. It is in YAML format with the extension that a
|
83
|
+
single '__END__' terminates the file immediately. The name of the file
|
84
|
+
defaults to 'qrpm.yml'. It is an error if the file exists
|
46
85
|
|
47
|
-
-
|
48
|
-
|
49
|
-
|
86
|
+
-T,force-template=OFILE?
|
87
|
+
Like --template but overwrites file if it exists
|
88
|
+
|
89
|
+
-b,builddir=NPATH?
|
90
|
+
Use the given path as the RPM build dir, default is 'builddir'. Doesn't
|
91
|
+
remove the directory afterwards. It it is an error if the directory exists
|
92
|
+
|
93
|
+
-B,force-builddir=PATH?
|
94
|
+
Like --builddir but overwrites the directory if it exists beforehand
|
50
95
|
|
51
96
|
-d,dump
|
52
97
|
Dump internal data and exit. For debug
|
53
98
|
)
|
54
99
|
|
55
|
-
opts, args = ShellOpts.process(SPEC, ARGV, verbose: true)
|
100
|
+
opts, args = ShellOpts.process(SPEC, ARGV, verbose: true, quiet: true)
|
56
101
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
if opts.template?
|
61
|
-
outfile = opts.template || Qrpm::QRPM_CONFIG_FILE
|
102
|
+
if opts.template? || opts.force_template?
|
103
|
+
outfile = opts.template || opts.force_template || Qrpm::QRPM_CONFIG_FILE
|
104
|
+
opts.force_template? || !File.exists?(outfile) or ShellOpts.error "Won't overwrite existing file: #{outfile}"
|
62
105
|
FileUtils::cp Qrpm::QRPM_CONFIG_FILE_TEMPLATE, outfile
|
106
|
+
puts "Generated #{outfile}" if !opts.quiet?
|
63
107
|
exit
|
64
108
|
end
|
65
109
|
|
66
|
-
#
|
67
|
-
#
|
68
|
-
|
110
|
+
# Process arguments. The overrides hash is constructed from var=val arguments
|
111
|
+
# on the command line
|
112
|
+
overrides = {}
|
113
|
+
file = nil
|
69
114
|
while arg = args.extract(0..1)
|
70
115
|
if arg =~ /^(.*?)=(.*)$/
|
71
|
-
|
72
|
-
|
116
|
+
overrides[$1] = $2
|
117
|
+
elsif file.nil?
|
73
118
|
file = arg
|
74
|
-
|
119
|
+
else
|
120
|
+
args.expect(-1, "More than one file argument")
|
75
121
|
end
|
76
122
|
end
|
77
|
-
args.
|
123
|
+
args.expect(0)
|
124
|
+
|
125
|
+
# Compute/normalize currdir and qrpmdir and add them to the dictionary
|
126
|
+
currdir = overrides["currdir"] = File.expand_path(overrides["currdir"] || Dir.getwd)
|
127
|
+
qrpmdir = overrides["qrpmdir"] = File.expand_path(overrides["qrpmdir"] || opts.directory || ".")
|
128
|
+
|
129
|
+
# Compute builddir
|
130
|
+
if opts.builddir? && opts.force_builddir?
|
131
|
+
ShellOpts.error "Can't use both --builddir and --force-builddir"
|
132
|
+
elsif opts.builddir? || opts.force_builddir?
|
133
|
+
builddir = opts.builddir || opts.force_builddir || "builddir"
|
134
|
+
opts.force_builddir? || !File.exist?(builddir) or
|
135
|
+
ShellOpts.error "Build directory 'builddir' exists - use -B to override"
|
136
|
+
builddir = File.expand_path(builddir)
|
137
|
+
else
|
138
|
+
builddir = nil
|
139
|
+
end
|
140
|
+
|
141
|
+
# Check if repository is clean
|
142
|
+
opts.force? || opts.dump? || `git status --porcelain | grep -v '??' 2>/dev/null` == "" or
|
143
|
+
ShellOpts.error "Repository is dirty"
|
78
144
|
|
79
145
|
# Check configuration file
|
80
146
|
file ||= Qrpm::QRPM_CONFIG_FILE
|
81
|
-
::File.exist?(file) or
|
147
|
+
::File.exist?(file) or ShellOpts.error "Can't find '#{file}'"
|
148
|
+
|
149
|
+
# Create lexer
|
150
|
+
lexer = Qrpm::Lexer.new([currdir, qrpmdir].uniq, opts.include.reverse)
|
82
151
|
|
83
152
|
# Load the qrpm configuration file
|
84
|
-
|
153
|
+
conf = lexer.lex(File.expand_path file)
|
154
|
+
|
155
|
+
# Change to qrpm directory
|
156
|
+
Dir.chdir(qrpmdir)
|
85
157
|
|
86
|
-
# Parse QRPM file
|
87
|
-
|
158
|
+
# Parse QRPM configuration file. Include paths are still resolved with the
|
159
|
+
# context of the original directory while filesystem paths are relative to
|
160
|
+
# the source directory
|
161
|
+
compiler = Qrpm::Compiler.new(overrides)
|
162
|
+
qrpm = compiler.compile(conf)
|
163
|
+
rpm = qrpm.rpm
|
88
164
|
|
89
165
|
if opts.dump?
|
90
|
-
|
166
|
+
puts "Compiler"
|
167
|
+
indent { compiler.dump }
|
168
|
+
|
169
|
+
puts "Qrpm"
|
170
|
+
indent { qrpm.dump_parts }
|
171
|
+
|
172
|
+
puts "Rpm"
|
173
|
+
indent { rpm.dump }
|
174
|
+
|
91
175
|
exit
|
92
176
|
end
|
93
177
|
|
94
|
-
#
|
95
|
-
opts.force? || `git status --porcelain 2>/dev/null` == "" or raise "Repository is dirty"
|
96
|
-
|
178
|
+
# Create spec/srpm/rpm file
|
97
179
|
target = (opts.spec? ? :spec : (opts.source? ? :srpm : :rpm))
|
98
|
-
rpm.build(
|
180
|
+
files = rpm.build(
|
181
|
+
target: target,
|
182
|
+
file: opts.spec,
|
183
|
+
verbose: opts.verbose?,
|
184
|
+
destdir: currdir,
|
185
|
+
builddir: builddir)
|
186
|
+
|
187
|
+
puts "Built #{files.map { |f| File.basename(f) }.join(" ")}" if !opts.quiet?
|
99
188
|
|
100
189
|
rescue RuntimeError => ex
|
101
|
-
ShellOpts.
|
190
|
+
ShellOpts.failure ex.message
|
102
191
|
end
|
103
192
|
|