File machinery.spec of Package machinery.2111

#
# spec file for package machinery
#
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           machinery
Version:        1.18.0
Release:        0
%define binary_name machinery
%define mod_name machinery-tool
%define mod_full_name %{mod_name}-%{version}
%define mod_branch -%{version}
%define mod_weight 1

%if %suse_version > 1320
# openSUSE Factory
%define bundlegems 0
%else
# SLES12, openSUSE 13.1/13.2/Leap
# LEAP has the suse_Version 1315
%define bundlegems 1
%endif

BuildRoot:      %{_tmppath}/%{name}-%{version}-build
# Require on SLES12 our Go version with s390x support
%if 0%{?suse_version} == 1315 && 0%{?is_opensuse} != 1
BuildRequires:  go-s390x
%else
BuildRequires:  go
%endif
BuildRequires:  fdupes
BuildRequires:  ruby-macros >= 5
%if %suse_version > 1310
%define rb_build_versions %{rb_default_ruby}
BuildRequires:  %{rubydevel}
BuildRequires:  %{rubygem bundler}
BuildRequires:  %{rubygem gem2rpm}
%if 0%{?bundlegems}
BuildRequires:  %{rubygem abstract_method < 2}
BuildRequires:  %{rubygem abstract_method >= 1.2}
BuildRequires:  %{rubygem builder < 4}
BuildRequires:  %{rubygem builder >= 3.2}
BuildRequires:  %{rubygem cheetah < 1}
BuildRequires:  %{rubygem cheetah >= 0.4}
BuildRequires:  %{rubygem diffy < 4}
BuildRequires:  %{rubygem diffy >= 3.0}
BuildRequires:  %{rubygem gli < 3}
BuildRequires:  %{rubygem gli >= 2.11}
BuildRequires:  %{rubygem haml < 5}
BuildRequires:  %{rubygem haml >= 4.0}
BuildRequires:  %{rubygem json < 2}
BuildRequires:  %{rubygem json >= 1.8}
BuildRequires:  %{rubygem json-schema < 2.3}
BuildRequires:  %{rubygem json-schema >= 2.2.4}
BuildRequires:  %{rubygem kramdown < 2}
BuildRequires:  %{rubygem kramdown >= 1.3}
BuildRequires:  %{rubygem mimemagic < 1}
BuildRequires:  %{rubygem mimemagic >= 0.3}
BuildRequires:  %{rubygem sinatra < 2}
BuildRequires:  %{rubygem sinatra >= 1.4}
BuildRequires:  %{rubygem tilt < 3}
BuildRequires:  %{rubygem tilt >= 2.0}
%else
Requires:       %{rubygem abstract_method < 2}
Requires:       %{rubygem abstract_method >= 1.2}
Requires:       %{rubygem builder < 4}
Requires:       %{rubygem builder >= 3.2}
Requires:       %{rubygem cheetah < 1}
Requires:       %{rubygem cheetah >= 0.4}
Requires:       %{rubygem diffy < 4}
Requires:       %{rubygem diffy >= 3.0}
Requires:       %{rubygem gli < 3}
Requires:       %{rubygem gli >= 2.11}
Requires:       %{rubygem haml < 5}
Requires:       %{rubygem haml >= 4.0}
Requires:       %{rubygem json < 2}
Requires:       %{rubygem json >= 1.8}
Requires:       %{rubygem json-schema < 2.3}
Requires:       %{rubygem json-schema >= 2.2.4}
Requires:       %{rubygem kramdown < 2}
Requires:       %{rubygem kramdown >= 1.3}
Requires:       %{rubygem mimemagic < 1}
Requires:       %{rubygem mimemagic >= 0.3}
Requires:       %{rubygem sinatra < 2}
Requires:       %{rubygem sinatra >= 1.4}
Requires:       %{rubygem tilt < 3}
Requires:       %{rubygem tilt >= 2.0}
%endif
%else
BuildRequires:  ruby-devel
BuildRequires:  rubygem(abstract_method) < 2
BuildRequires:  rubygem(abstract_method) >= 1.2
BuildRequires:  rubygem(builder) < 4
BuildRequires:  rubygem(builder) >= 3.2
BuildRequires:  rubygem(bundler)
BuildRequires:  rubygem(cheetah) < 1
BuildRequires:  rubygem(cheetah) >= 0.4
BuildRequires:  rubygem(diffy) < 4
BuildRequires:  rubygem(diffy) >= 3.0
BuildRequires:  rubygem(gem2rpm)
BuildRequires:  rubygem(gli) < 3
BuildRequires:  rubygem(gli) >= 2.11
BuildRequires:  rubygem(haml) < 5
BuildRequires:  rubygem(haml) >= 4.0
BuildRequires:  rubygem(json) < 2
BuildRequires:  rubygem(json) >= 1.8
BuildRequires:  rubygem(json-schema) < 2.3
BuildRequires:  rubygem(json-schema) >= 2.2.4
BuildRequires:  rubygem(kramdown) < 2
BuildRequires:  rubygem(kramdown) >= 1.3
BuildRequires:  rubygem(mimemagic) < 1
BuildRequires:  rubygem(mimemagic) >= 0.3
BuildRequires:  rubygem(sinatra) < 2
BuildRequires:  rubygem(sinatra) >= 1.4
BuildRequires:  rubygem(tilt) < 3
BuildRequires:  rubygem(tilt) >= 2.0
%endif
# Disable autogenerating "Requires:" headers for bundled gems.
%define __requires_exclude ^rubygem
Requires:       ruby >= 2.0
Requires:       sudo
Requires:       which
Url:            http://suse.com
Source0:        http://rubygems.org/gems/%{mod_full_name}.gem
Source1:        %{binary_name}-rpmlintrc
Summary:        Systems management toolkit
License:        GPL-3.0
Group:          Development/Languages/Ruby

%description
Machinery is a systems management toolkit for Linux. It supports configuration
discovery, system validation, and service migration. It's based on the idea of a
universal system description.

%package doc
Summary:        RDoc and RI documentation for Machinery
Group:          Development/Languages/Ruby
Requires:       %{name} = %{version}

%description doc
RDoc and RI documentation for Machinery. Machinery is a systems management
toolkit for Linux.

%prep

%build

%install
# Install the gem itself

%gem_install -f

%if %{?bundlegems}
# Bundle dependencies

pushd %{buildroot}%{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_full_name}

cat > Gemfile <<EOT
gem "cheetah", "~> 0.4"
%if %suse_version <= 1310
gem "json", "~> 1.8"
%endif
gem "abstract_method", "~> 1.2"
gem "builder", "~> 3.2"
gem "gli", "~> 2.11"
gem "json-schema", "~> 2.2.4"
gem "haml", "~> 4.0"
gem "kramdown", "~> 1.3"
gem "tilt", "~> 2.0"
gem "sinatra", "~> 1.4"
gem "mimemagic", "~> 0.3"
gem "diffy", "~> 3.0"
EOT

mkdir -p vendor/cache
cp %{_libdir}/ruby/gems/%{rb_ver}/cache/*.gem vendor/cache

bundle install --standalone --local

popd
%endif

# Adapt the binary

# Remove the ruby version suffix from the machinery executable
if [ ! -f "%{buildroot}%{_bindir}/%{binary_name}" ]; then
  mv "%{buildroot}%{_bindir}/%{binary_name}"* "%{buildroot}%{_bindir}/%{binary_name}"
fi

%if %{?bundlegems}
# Here we do a surgery on the binary to actually load the bundled gems. This is
# a hack, but it can't be done anywhere else because the binary is generated
# during gem install.
sed -i '/gem /i \
Gem.path.unshift("%{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_full_name}/bundle/ruby/%{rb_ver}")

' %{buildroot}%{_bindir}/%{binary_name}
%endif

# Clean up obsolete extension doc
rm -rf %{buildroot}%{_libdir}/ruby/gems/%{rb_ver}/doc/extensions

# Man page & additional files

mkdir -p %{buildroot}%{_mandir}/man1
ln -s %{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_full_name}/man/generated/%{binary_name}.1.gz %{buildroot}%{_mandir}/man1/
ln -s %{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_full_name}/COPYING
ln -s %{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_full_name}/NEWS

# Convert duplicate files to symlinks

%fdupes -s %{buildroot}

%files
%defattr(-,root,root,-)
%{_bindir}/%{binary_name}
%{_libdir}/ruby/gems/%{rb_ver}/cache/%{mod_full_name}.gem
%{_libdir}/ruby/gems/%{rb_ver}/gems/%{mod_full_name}/

%if %suse_version > 1310
%{_libdir}/ruby/gems/%{rb_ver}/extensions/
%endif
%{_libdir}/ruby/gems/%{rb_ver}/specifications/%{mod_full_name}.gemspec
%{_mandir}/man1/*.1.gz
%doc COPYING NEWS

%files doc
%defattr(-,root,root,-)
%doc %{_libdir}/ruby/gems/%{rb_ver}/doc/%{mod_full_name}/

%changelog