%global product oVirt

%global use_rhev %( test -z @RHEV@ && echo 1 || echo 0)
%define debug_package %{nil}

%global source_basename ovirt-web-ui

Name:           ovirt-web-ui
Version:        1.7.0
Release:        3
Summary:        VM Portal for %{product}
License:        Apache 2.0
URL:            https://github.com/oVirt/ovirt-web-ui
Source0:        https://github.com/oVirt/ovirt-web-ui/archive/%{source_basename}-1.7.0.tar.gz
#https://patch-diff.githubusercontent.com/raw/omgovich/colord/pull/52.patch
patch1:         Simplify-package-exports.patch
BuildArch: noarch

# nodejs-modules embeds yarn and requires nodejs
BuildRequires: ovirt-engine-nodejs-modules >= 2.0.53-1

%description
This package provides the VM Portal for %{product}.

%prep
%setup -q -n"%{source_basename}-%{version}"
rpm -qa | grep ovirt-engine-nodejs

echo "=== Workaround: 'yarn check' is recently failing on requiring webpack >= v2. Manually"
echo "=== verified that this is ok for recent code base but may be a real failure in the"
echo "=== future. Please watch carefully for other potential types of errors."
IGNORE_YARN_CHECK=1 source /usr/share/ovirt-engine-nodejs-modules/setup-env.sh
pushd  node_modules/colord
%patch1 -p1
popd

%build
export PATH="%{_datadir}/ovirt-engine-nodejs/bin:%{_datadir}/ovirt-engine-nodejs-modules/bin:${PATH}"
%configure

# Change hardcoded deafult hash algorithm from legacy md4 to sha512
sed -i 's/md4/sha512/g' node_modules/webpack/lib/*.js
sed -i 's/md4/sha512/g' node_modules/webpack/lib/optimize/*.js
sed -i 's/md4/sha512/g' node_modules/copy-webpack-plugin/dist/*.js
sed -i 's/md4/sha512/g' node_modules/terser-webpack-plugin/dist/*.js
sed -i 's/md4/sha512/g' node_modules/loader-utils/lib/index.js
sed -i 's/md4/sha512/g' node_modules/loader-utils/lib/*.js
sed -i 's/md4/sha512/g' node_modules/babel-loader/lib/cache.js
sed -i 's/md4/sha512/g' node_modules/webpack/node_modules/terser-webpack-plugin/dist/index.js

make

%install
make install DESTDIR=%{buildroot}

%files
%doc README.md
%license LICENSE
%{_datarootdir}/ovirt-web-ui
%{_datarootdir}/ovirt-engine/ovirt-web-ui.war
%{_sysconfdir}/ovirt-engine/engine.conf.d/50-ovirt-web-ui.conf
%{_sysconfdir}/ovirt-web-ui/branding/00-ovirt.brand

%changelog
* Fri Mar 03 2023 lijunwei <lijunwei@kylinos.cn> - 1.7.0-3
- Change hardcoded deafult hash algorithm from legacy md4 to sha512

* Wed May 18 2022 jiangxinyu <jiangxinyu@kylinos.cn> - 1.7.0-2
- Add Simplify-package-exports.patch

* Tue Sep 7 2021 liyanan <liyanan32@huawei.com> - 1.7.0-1
- update to 1.7.0

* Thu Mar 5 2020 di.wang <di.wang@cs2c.com.cn> - 1.6.0-1
- Package Initialization
