#
# spec file for package obs-bundled-gems
#
# Copyright (c) 2018 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/
#

%global rake_version 13.0.6
%global rack_version 2.2.3
Name:           obs-bundled-gems
Version:        2.10.1
Release:        11
Summary:        The Open Build Service -- Bundled Gems
License:        GPL-2.0-only OR GPL-3.0-only
URL:            http://www.openbuildservice.org
Source0:        Gemfile
Source1:        Gemfile.lock.aarch64
Source2:        Gemfile.lock.x86
Source3:	verdor.obscpio
Source4:        Gemfile.lock.loongarch64
# http://rubygems.loongnix.cn/gems/ffi-1.15.5.gem
Source5:        ffi-1.15.5.gem
# http://rubygems.loongnix.cn/gems/nokogiri-1.13.4.gem
Source6:        nokogiri-1.13.4.gem
# http://rubygems.loongnix.cn/gems/mini_portile2-2.8.0.gem
Source7:        mini_portile2-2.8.0.gem
# http://rubygems.loongnix.cn/gems/stringio-3.0.1.gem
Source8:        stringio-3.0.1.gem
BuildRequires:  cyrus-sasl-devel mysql-devel nodejs openldap-devel python3-devel
BuildRequires:  gcc gcc-c++ glibc-devel libtool libxml2-devel libxslt-devel
BuildRequires:  ruby-devel rubygem-bundler ruby-common make

%description
This package is useful for the Open Build Service. It will figure out
denpendent gems, and add them to spec file.

%package -n     obs-api-deps
Summary:        Holding dependencies required to run the OBS frontend
Requires:       build >= 20170315
Requires:       memcached >= 1.4
Requires:       mariadb-server
Requires:       obs-bundled-gems = %{version}
Requires:       sphinx >= 2.1.8
Requires:       perl(GD)
Requires:       rubygem-bundler
Requires:       rubygem-rake

%description -n obs-api-deps
To simplify splitting the test suite packages off the main package,
this package is just a meta package used to run and build obs-api

%package -n obs-api-testsuite-deps
Summary:        Holding dependencies required to run frontend test suites
Group:          Productivity/Networking/Web/Utilities
Requires:       inst-source-utils
Requires:       nodejs
Requires:       obs-api-deps = %{version}

%description -n obs-api-testsuite-deps
To simplify splitting the test suite packages off the main package,
this package is just a meta package used to build obs-api testsuite

%prep
echo "This package contains of requirements"> README
cp %{_sourcedir}/Gemfile %{_sourcedir}/Gemfile.lock* .
arch=`uname -m`
if [ $arch == 'x86_64' ];then
  mv Gemfile.lock.x86 Gemfile.lock
elif [ $arch == 'loongarch64' ];then
  mv Gemfile.lock.loongarch64 Gemfile.lock
else
  mv Gemfile.lock.aarch64 Gemfile.lock
fi

%build
cd %{_sourcedir}
if [ ! -f verdor.obscpio ]; then find ./vendor/cache | cpio -o -H newc > %{_sourcedir}/verdor.obscpio; fi
if [ -d vendor ]; then rm -rf vendor; fi
cpio -idvm < verdor.obscpio
cd -
arch=`uname -m`
if [ $arch == 'loongarch64' ];then
  cp %{SOURCE5} %{_sourcedir}/vendor/cache/
  cp %{SOURCE6} %{_sourcedir}/vendor/cache/
  cp %{SOURCE7} %{_sourcedir}/vendor/cache/
  cp %{SOURCE8} %{_sourcedir}/vendor/cache/
fi
export QA_SKIP_BUILD_ROOT=1
# copy gem files into cache
mkdir -p vendor/cache
cp %{_sourcedir}/vendor/cache/*.gem vendor/cache
export GEM_HOME=~/.gems
bundle config build.nokogiri --use-system-libraries

%install
export QA_SKIP_BUILD_ROOT=1
bundle --local --path %{buildroot}%_libdir/obs-api/

# test that the rake and rack macros is still matching our Gemfile
test -f %{buildroot}%_libdir/obs-api/ruby/3.0.0/gems/rake-%{rake_version}/rake.gemspec
test -f %{buildroot}%_libdir/obs-api/ruby/3.0.0/gems/rack-%{rack_version}/rack.gemspec

# run gem clean up script
/usr/lib/rpm/gem_build_cleanup.sh %{buildroot}%_libdir/obs-api/ruby/*/

# work around sassc bug - and install libsass
sassc_dir=$(ls -1d %{buildroot}%_libdir/obs-api/ruby/3.0.0/gems/sassc-2*)
install -D -m 755 $sassc_dir/ext/libsass.so $sassc_dir/lib/sassc
sed -i -e 's,/ext/libsass,,' $sassc_dir/lib/sassc/native.rb

# Remove sources of extensions, we don't need them
rm -rf %{buildroot}%_libdir/obs-api/ruby/*/gems/*/ext/

# remove binaries with invalid interpreters
rm -rf %{buildroot}%_libdir/obs-api/ruby/*/gems/diff-lcs-*/bin

# remove spec / test files from gems as they shouldn't be shipped in gems anyway
# and often cause errors / warning in rpmlint
rm -rf %{buildroot}%_libdir/obs-api/ruby/*/gems/*/spec/
rm -rf %{buildroot}%_libdir/obs-api/ruby/*/gems/*/test/
# we do not verify signing of the gem
rm -rf %{buildroot}%_libdir/obs-api/ruby/*/gems/mousetrap-rails-*/gem-public_cert.pem

# remove prebuilt binaries causing broken dependencies
rm -rf %{buildroot}%_libdir/obs-api/ruby/*/gems/selenium-webdriver-*/lib/selenium/webdriver/firefox/native

# remove all gitignore files to fix rpmlint version-control-internal-file
find %{buildroot}%_libdir/obs-api -name .gitignore | xargs rm -rf

# fix interpreter in installed binaries
for bin in %{buildroot}%_libdir/obs-api/ruby/*/bin/*; do
  sed -i -e 's,/usr/bin/env ruby.ruby2.5,/usr/bin/ruby.ruby2.5,' $bin
done

# remove exec bit from all other files still containing /usr/bin/env except ruby/2.5.0/bin - mostly helper scripts
find %{buildroot} -type f -print0 | xargs -0 grep -l /usr/bin/env | grep -v ruby/2.5.0/bin| while read file; do
  chmod a-x $file
done

%files
%_libdir/obs-api

%files -n obs-api-deps
%doc README

%files -n obs-api-testsuite-deps
%doc README

%changelog
* Mon Aug 28 2023 panchenbo <panchenbo@kylinsec.com.cn> - 2.10.1-11
- add loongarch64 support

* Mon Feb 13 2023 wangkai <wangkai385@h-partners.com> 2.10.1-10
- Modify the rdoc version to 6.3.3

* Fri Feb 03 2023 zhangliangpengkun<zhangliangpengkun@xfusion.com> - 2.10.1-9
- Add components that are missing from the source package

* Wed Dec 07 2022 yaoxin <yaoxin30@h-partners.com> - 2.10.1-8
- Add make dependency

* Thu Oct 27 2022 liyanan <liyanan32@h-partners.com> 2.10.1-7
- Update gem version for obs-server 2.10.15

* Tue May 24 2022 wangkai <wangkai385@h-partners.com> 2.10.1-6
- Update Gemfile.lock factory_bot-6.2.1 and pry-0.13.1 and pry-byebug-3.9.0

* Thu May 12 2022 wangkai <wangkai385@h-partners.com> 2.10.1-5
- Update xmlhash to 1.3.8

* Mon Mar 21 2022 Ge Wang <wangge20@huawei.com> 2.10.1-4
- Fix compilation failed due to ruby and some rubygems upgraded

* Thu Sep 23 2021 lingsheng <lingsheng@huawei.com> 2.10.1-3
- Fix exec permission in ruby/2.5.0/bin, change require to mariadb-server

* Wed Jun 9 2021 zhaomengchao <zhaomengchao3@huawei.com> 2.10.1-2
- fix obs-bundled-gems compilation failed.

* Tue Nov 17 2020 yanglongkang <yanglongkang@huawei.com> 2.10.1-1
- Add verdor.obscpio to the source code package.

* Sat Mar 7 2020 Shijie Luo <luoshijie1@huawei.com> 2.10.1-0
- Package Init.
