Module: Libyui::Tasks::Helpers
- Defined in:
- lib/libyui/tasks.rb
Overview
Some helpers to be used on tasks definition
Instance Method Summary collapse
-
#bump_cmake_so_version(filename = nil) ⇒ Object
Bumps the so version in the CMake version file.
-
#bump_spec_so_version(filename = nil) ⇒ Object
Bumps the so version in the given spec file.
-
#cmake_filename(filename) ⇒ String
Filename of the CMake version file.
-
#cmake_so_version(filename = nil) ⇒ String
Returns the CMake so version from the version file.
-
#cmake_value(text, key) ⇒ String
Extracts the value of the given key from the content of a CMake version file.
-
#cmake_values(filename, *keys) ⇒ Object
Extract values from a CMake version file.
-
#cmake_version(filename = nil) ⇒ String
Returns the CMake version from the version file.
-
#spec_filename(filename) ⇒ String
Filename of the spec file.
-
#spec_so_version(filename = nil) ⇒ String?
Returns the so version from the given spec file.
Instance Method Details
#bump_cmake_so_version(filename = nil) ⇒ Object
Bumps the so version in the CMake version file
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/libyui/tasks.rb', line 76 def bump_cmake_so_version(filename = nil) filename = cmake_filename(filename) so_version = cmake_so_version(filename).split(".").first.to_i.next content = File.read(filename) content.sub!(/(^SET.*SONAME_MAJOR.*)"([^"\n])*"/, "\\1\"#{so_version}\"") content.sub!(/(^SET.*SONAME_MINOR.*)"([^"\n])*"/, "\\1\"0\"") content.sub!(/(^SET.*SONAME_PATCH.*)"([^"\n])*"/, "\\1\"0\"") File.write(filename, content) end |
#bump_spec_so_version(filename = nil) ⇒ Object
Bumps the so version in the given spec file
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/libyui/tasks.rb', line 134 def bump_spec_so_version(filename = nil) filename = spec_filename(filename) so_version = spec_so_version(filename).to_i.next content = File.read(filename) content.gsub!(/^(%define\s+so_version\s+)\d+$/, "\\1#{so_version}") File.write(filename, content) end |
#cmake_filename(filename) ⇒ String
Filename of the CMake version file
117 118 119 |
# File 'lib/libyui/tasks.rb', line 117 def cmake_filename(filename) filename || VERSION_CMAKE end |
#cmake_so_version(filename = nil) ⇒ String
Returns the CMake so version from the version file.
65 66 67 68 69 70 71 |
# File 'lib/libyui/tasks.rb', line 65 def cmake_so_version(filename = nil) filename = cmake_filename(filename) values = cmake_values(filename, "SONAME_MAJOR", "SONAME_MINOR", "SONAME_PATCH") values.compact.join(".") end |
#cmake_value(text, key) ⇒ String
Extracts the value of the given key from the content of a CMake version file
107 108 109 110 111 |
# File 'lib/libyui/tasks.rb', line 107 def cmake_value(text, key) e_key = Regexp.escape(key) m = /SET\s*\(\s*#{e_key}\s+"([^"]*)"\s*\)/.match(text) m ? m[1] : nil end |
#cmake_values(filename, *keys) ⇒ Object
Extract values from a CMake version file
95 96 97 98 99 |
# File 'lib/libyui/tasks.rb', line 95 def cmake_values(filename, *keys) content = File.read(filename) keys.map { |k| cmake_value(content, k) } end |
#cmake_version(filename = nil) ⇒ String
Returns the CMake version from the version file. VERSION_TWEAK is optional.
52 53 54 55 56 57 58 59 |
# File 'lib/libyui/tasks.rb', line 52 def cmake_version(filename = nil) filename = cmake_filename(filename) values = cmake_values(filename, "VERSION_MAJOR", "VERSION_MINOR", "VERSION_PATCH", "VERSION_TWEAK") values.compact.join(".") end |
#spec_filename(filename) ⇒ String
Filename of the spec file
149 150 151 |
# File 'lib/libyui/tasks.rb', line 149 def spec_filename(filename) filename || Dir.glob("package/*.spec").min end |
#spec_so_version(filename = nil) ⇒ String?
Returns the so version from the given spec file
125 126 127 128 129 |
# File 'lib/libyui/tasks.rb', line 125 def spec_so_version(filename = nil) filename = spec_filename(filename) File.read(filename).scan(/^%define\s+so_version\s+(\d+)/).flatten.first end |