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(s, 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
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/libyui/tasks.rb', line 73 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
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/libyui/tasks.rb', line 131 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
114 115 116 |
# File 'lib/libyui/tasks.rb', line 114 def cmake_filename(filename) filename || VERSION_CMAKE end |
#cmake_so_version(filename = nil) ⇒ String
Returns the CMake so version from the version file.
62 63 64 65 66 67 68 |
# File 'lib/libyui/tasks.rb', line 62 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(s, key) ⇒ String
Extracts the value of the given key from the content of a CMake version file
104 105 106 107 108 |
# File 'lib/libyui/tasks.rb', line 104 def cmake_value(s, key) e_key = Regexp.escape(key) m = /SET\s*\(\s*#{e_key}\s+"([^"]*)"\s*\)/.match(s) m ? m[1] : nil end |
#cmake_values(filename, *keys) ⇒ Object
Extract values from a CMake version file
92 93 94 95 96 |
# File 'lib/libyui/tasks.rb', line 92 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.
49 50 51 52 53 54 55 56 |
# File 'lib/libyui/tasks.rb', line 49 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
146 147 148 |
# File 'lib/libyui/tasks.rb', line 146 def spec_filename(filename) filename || Dir.glob("package/*.spec").sort.first end |
#spec_so_version(filename = nil) ⇒ String?
Returns the so version from the given spec file
122 123 124 125 126 |
# File 'lib/libyui/tasks.rb', line 122 def spec_so_version(filename = nil) filename = spec_filename(filename) File.read(filename).scan(/^%define\s+so_version\s+(\d+)/).flatten.first end |