module Libyui::Tasks::Helpers

Some helpers to be used on tasks definition

Public Instance Methods

bump_cmake_so_version(filename = nil) click to toggle source

Bumps the so version in the CMake version file

@param filename [string, nil] %{VERSION_CMAKE} by default

# 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) click to toggle source

Bumps the so version in the given spec file

@param filename [String, nil] if nil, it uses the shortest spec filename

# 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) click to toggle source

Filename of the CMake version file

@param filename [string, nil] %{VERSION_CMAKE} if no filename is given @return [String]

# File lib/libyui/tasks.rb, line 114
def cmake_filename(filename)
  filename || VERSION_CMAKE
end
cmake_so_version(filename = nil) click to toggle source

Returns the CMake so version from the version file.

@param filename [String, nil] %{VERSION_CMAKE} by default @return [String] like “4.0.0”

# 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) click to toggle source

Extracts the value of the given key from the content of a CMake version file

@param s [String] e.g., '… SET( VERSION_MAJOR “3”) …' @param key [String] e.g., 'VERSION_MAJOR'

@return [String] e.g., “3”

# 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) click to toggle source

Extract values from a CMake version file

@see cmake_value

@param filename [String] @param keys [Array<String>]

# 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) click to toggle source

Returns the CMake version from the version file. VERSION_TWEAK is optional.

@param filename [String, nil] %{VERSION_CMAKE} by default @return [String] like “1.2.3” or “1.2.3.4”

# 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) click to toggle source

Filename of the spec file

@param filename [String, nil] if nil, it uses the shortest spec filename @return [String]

# File lib/libyui/tasks.rb, line 146
def spec_filename(filename)
  filename || Dir.glob("package/*.spec").sort.first
end
spec_so_version(filename = nil) click to toggle source

Returns the so version from the given spec file

@param filename [String, nil] if nil, it uses the shortest spec filename @return [String, nil] e.g., “12”

# 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