Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add so_version tasks #33

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.20
0.1.21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should consider more final versioning. As this extends API I would extend bump of minor version. But I agree that according to semver everything in version 0 basically does not follow versioning.

113 changes: 97 additions & 16 deletions lib/libyui/tasks.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<String>]
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
Expand Down
53 changes: 53 additions & 0 deletions lib/tasks/so_version.rake
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions package/rubygem-libyui-rake.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Mar 3 16:11:29 UTC 2021 - José Iván López González <[email protected]>

- Added so_version tasks (related to bsc#1181653).
- 0.1.21

-------------------------------------------------------------------
Thu Apr 23 07:31:19 UTC 2020 - Ladislav Slezák <[email protected]>

Expand Down
2 changes: 1 addition & 1 deletion package/rubygem-libyui-rake.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down