Module: Libyui::Tasks::Helpers

Defined in:
lib/libyui/tasks.rb

Overview

Some helpers to be used on tasks definition

Instance Method Summary collapse

Instance Method Details

#bump_cmake_so_version(filename = nil) ⇒ Object

Bumps the so version in the CMake version file

Parameters:

  • filename (string, nil) (defaults to: nil)

    %VERSION_CMAKE by default



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

Parameters:

  • filename (String, nil) (defaults to: nil)

    if nil, it uses the shortest spec filename



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

Parameters:

  • filename (string, nil)

    %VERSION_CMAKE if no filename is given

Returns:

  • (String)


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.

Parameters:

  • filename (String, nil) (defaults to: nil)

    %VERSION_CMAKE by default

Returns:

  • (String)

    like “4.0.0”



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

Parameters:

  • s (String)

    e.g., ‘… SET( VERSION_MAJOR “3”) …’

  • key (String)

    e.g., ‘VERSION_MAJOR’

Returns:

  • (String)

    e.g., “3”



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

Parameters:

  • filename (String)
  • keys (Array<String>)

See Also:



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.

Parameters:

  • filename (String, nil) (defaults to: nil)

    %VERSION_CMAKE by default

Returns:

  • (String)

    like “1.2.3” or “1.2.3.4”



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

Parameters:

  • filename (String, nil)

    if nil, it uses the shortest spec filename

Returns:

  • (String)


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

Parameters:

  • filename (String, nil) (defaults to: nil)

    if nil, it uses the shortest spec filename

Returns:

  • (String, nil)

    e.g., “12”



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