qrpm 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a7181b2cc45c65645e039fc5fba4d758698e2558acafe9f9173a955f7af7895
4
- data.tar.gz: 714b179b5f0f235ddd7b6098ea674579fc8dec671db6d76570e9c9128d7edae7
3
+ metadata.gz: 884bb9257c9679db9a55e792de02fe716fc777e8903b1ed003fed768bba51129
4
+ data.tar.gz: eebed25d75b50ae9f738afebadec366ae22307245be691449cce0ca48f3bab6f
5
5
  SHA512:
6
- metadata.gz: eaf5dc6516f01dcc9a912f1982f7008f2d1ff667aff8cabf9197945726d43690bc4d28836a186d2a3f5b245f17ecf2d8c7744facbdd7fe6f81d8d32aaf6ce3c3
7
- data.tar.gz: eb40981a98a3408f545ef8b42ce6a9f1f70657393886542857911f74865759e2227de458648a04c94a0b9edcc3d18a8a5b54ca3035f6c15fc8ddca5a057f7501
6
+ metadata.gz: a12688142eb50b64dbf59324d299f192421675279af2574be1fee9d6df5aba3b0272f9a4196d05dee64165be6ffc19f2769c7954a363e6c705b6b17849be5d93
7
+ data.tar.gz: bad940c0c5af97d5fa5ec5c809266765b0d3ecd5925a50c726544ea2cc15d7ba434926ba6c6e1b00918c002cfbcf2dd26f1409e93fa01b7bbfb7ffbfe0cac321
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 in the dict hash and sets the configuration file
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 =~ /^(.*?)=(.*)$/
@@ -73,12 +77,9 @@ begin
73
77
  args.empty? or args.expect(0) # Generates an illegal-number-of-arguments error
74
78
 
75
79
  # Check configuration file
76
- file ||= QRPM_CONFIG_FILE
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 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"] ||= ENV['USER']
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 case to substite left-to-rigth to avoid a variable expansion
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 value of the $USER
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 has_configure?() ::File.exist? "configure" end
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 build(target: :rpm, file: nil)
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/* ." or raise "Failed copying SRPM file"
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]* ." or raise "Failed copying RPM file"
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
@@ -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 -%>
@@ -1,3 +1,4 @@
1
+ # QRPM configuration file. See https://github.com/clrgit/qrpm
1
2
 
2
3
  # Package information
3
4
  #
data/lib/qrpm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qrpm
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
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.1
4
+ version: 0.1.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-03 00:00:00.000000000 Z
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