diff --git a/VERSION b/VERSION index baa9837..7906299 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.20 +0.1.21 diff --git a/lib/libyui/tasks.rb b/lib/libyui/tasks.rb index 7448fa7..7ad4539 100644 --- a/lib/libyui/tasks.rb +++ b/lib/libyui/tasks.rb @@ -1,5 +1,5 @@ #-- -# Copyright (C) 2015 SUSE LLC +# Copyright (C) 2015-2021 SUSE LLC # This library is free software; you can redistribute it and/or modify # it only under the terms of version 2.1 of the GNU Lesser General Public # License as published by the Free Software Foundation. @@ -41,29 +41,110 @@ def self.submit_to(target, file = TARGETS_FILE) # Some helpers to be used on tasks definition module Helpers - # Extracts the value from a CMake string + # Returns the CMake version from the version file. + # VERSION_TWEAK is optional. # - # @param s [String] '... SET( VERSION_MAJOR "3") ...' - # @param key [String] 'VERSION_MAJOR' - # @return "3" + # @param filename [String, nil] %{VERSION_CMAKE} by default + # @return [String] like "1.2.3" or "1.2.3.4" + 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 + + # Returns the CMake so version from the version file. + # + # @param filename [String, nil] %{VERSION_CMAKE} by default + # @return [String] like "4.0.0" + def cmake_so_version(filename = nil) + filename = cmake_filename(filename) + + values = cmake_values(filename, "SONAME_MAJOR", "SONAME_MINOR", "SONAME_PATCH") + + values.compact.join(".") + end + + # Bumps the so version in the CMake version file + # + # @param filename [string, nil] %{VERSION_CMAKE} by default + 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 + + # Extract values from a CMake version file + # + # @see cmake_value + # + # @param filename [String] + # @param keys [Array] + def cmake_values(filename, *keys) + content = File.read(filename) + + keys.map { |k| cmake_value(content, k) } + end + + # 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" 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 - # Returns the CMake version from the version file. - # VERSION_TWEAK is optional. + # Filename of the CMake version file # - # @param [String] Version file (VERSION_CMAKE by default) - # @return [String] like "1.2.3" or "1.2.3.4" - # @see VERSION_CMAKE - def cmake_version(file = nil) - f = File.read(file || VERSION_CMAKE) - [cmake_value(f, "VERSION_MAJOR"), - cmake_value(f, "VERSION_MINOR"), - cmake_value(f, "VERSION_PATCH"), - cmake_value(f, "VERSION_TWEAK")].compact.join(".") + # @param filename [string, nil] %{VERSION_CMAKE} if no filename is given + # @return [String] + def cmake_filename(filename) + filename || VERSION_CMAKE + end + + # 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" + def spec_so_version(filename = nil) + filename = spec_filename(filename) + + File.read(filename).scan(/^%define\s+so_version\s+(\d+)/).flatten.first + end + + # Bumps the so version in the given spec file + # + # @param filename [String, nil] if nil, it uses the shortest spec filename + 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 + + # Filename of the spec file + # + # @param filename [String, nil] if nil, it uses the shortest spec filename + # @return [String] + def spec_filename(filename) + filename || Dir.glob("package/*.spec").sort.first end end end diff --git a/lib/tasks/so_version.rake b/lib/tasks/so_version.rake new file mode 100644 index 0000000..2f34244 --- /dev/null +++ b/lib/tasks/so_version.rake @@ -0,0 +1,53 @@ +#-- +# Copyright (C) 2021 SUSE LLC +# This library is free software; you can redistribute it and/or modify +# it only under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +#++ + +namespace :so_version do + include Libyui::Tasks::Helpers + + desc "Check that the so version numbers are in sync" + task :check do + so_version = cmake_so_version.split(".").first + + filenames = Dir.glob("package/*.spec").sort + filenames.reject! { |f| spec_so_version(f).nil? } + + mismatches = filenames.select { |f| spec_so_version(f) != so_version } + + if mismatches.any? + messages = ["so version mismatch:"] + messages << "cmake so version: #{so_version}" + messages += mismatches.map { |f| "#{f}: #{spec_so_version(f)}" } + + raise messages.join("\n") + end + + puts cmake_so_version if verbose + end + + desc "Increase the so version in spec and cmake files" + task bump: :check do + bump_cmake_so_version + + Dir.glob("package/*.spec").each { |f| bump_spec_so_version(f) } + + puts cmake_so_version if verbose + end + + desc "Show the so version" + task :show do + puts cmake_so_version + end +end diff --git a/package/rubygem-libyui-rake.changes b/package/rubygem-libyui-rake.changes index cd34662..f8071ff 100644 --- a/package/rubygem-libyui-rake.changes +++ b/package/rubygem-libyui-rake.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Mar 3 16:11:29 UTC 2021 - José Iván López González + +- Added so_version tasks (related to bsc#1181653). +- 0.1.21 + ------------------------------------------------------------------- Thu Apr 23 07:31:19 UTC 2020 - Ladislav Slezák diff --git a/package/rubygem-libyui-rake.spec b/package/rubygem-libyui-rake.spec index c8a6bd5..a3a83c9 100644 --- a/package/rubygem-libyui-rake.spec +++ b/package/rubygem-libyui-rake.spec @@ -17,7 +17,7 @@ Name: rubygem-libyui-rake -Version: 0.1.20 +Version: 0.1.21 Release: 0 %define mod_name libyui-rake %define mod_full_name %{mod_name}-%{version}