File protobuf.spec of Package protobuf.36265

#
# spec file for package protobuf
#
# Copyright (c) 2024 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#


%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%define sover 20
%define tarname protobuf
%define src_install_dir %{_prefix}/src/%{name}
# requires gmock, which is not yet in the distribution
%bcond_with check
%bcond_without java
%bcond_without python2
%bcond_without python3
%global protoc_arch %{_arch}
%ifarch x86_64 %{?x86_64}
%global protoc_arch x86_64
%endif
%ifarch ppc
%global protoc_arch ppc_32
%endif
%ifarch ppc64
%global protoc_arch ppc_64
%endif
%ifarch ppc64le
%global protoc_arch ppcle_64
%endif
%ifarch %{ix86}
%global protoc_arch x86_32
%endif
%ifarch ia64
%global protoc_arch itanium_64
%endif
%ifarch s390
%global protoc_arch s390_32
%endif
%ifarch s390x
%global protoc_arch s390_64
%endif
%ifarch %{arm}
%global protoc_arch arm_32
%endif
%ifarch aarch64 %{arm64}
%global protoc_arch aarch_64
%endif
# 32 bit sparc, optimized for v9
%ifarch sparcv9
%global protoc_arch sparc_32
%endif
# 64 bit sparc
%ifarch sparc64
%global protoc_arch sparc_64
%endif
%global __requires_exclude_from ^%{_datadir}/maven-metadata/%{name}-protoc.xml$
Name:           protobuf
Version:        3.9.2
Release:        0
Summary:        Protocol Buffers - Google's data interchange format
License:        BSD-3-Clause
Group:          Development/Libraries/C and C++
URL:            https://github.com/google/protobuf/
Source0:        https://github.com/google/protobuf/archive/v%{version}.tar.gz#/%{tarname}-%{version}.tar.gz
Source1:        baselibs.conf
# Java relevant backporting from 3.16.x tree
Patch0:         protobuf-51026d922970e06475f005b39287963594134b96.patch
Patch1:         protobuf-6ee16a9c60e734104aeb738503fe3f411c97bd88.patch
Patch2:         protobuf-73e0d748b9acdc40b693f2879ce82ecb1a849b81.patch
Patch3:         protobuf-7bff8393cab939bfbb9b5c69b3fe76b4d83c41ee.patch
Patch4:         protobuf-4f02f056b5cea99052bfdfb6698afe47a3cf2964.patch
Patch5:         protobuf-763c3588740b97e8e80b1b1a1a2dc4f417647133.patch
Patch6:         protobuf-6c92f9dff1807c142edf6780d775b58a3b078591.patch
Patch7:         protobuf-4e93585e8bb234efeacb7737b8d080968c5ab91e.patch
Patch8:         protobuf-58d4420e2dd8a3cd354fff9db0052881c25369ce.patch
# Patches for SUSE bugs
# PATCH-FIX-UPSTREAM https://github.com/protocolbuffers/protobuf/commit/a00125024e9231d76746bd394fef8876f5cc15e2
Patch100:       protobuf-CVE-2021-22570.patch
# PATCH-FIX-UPSTREAM https://github.com/protocolbuffers/protobuf/commit/c555c3dd14feb25d6283cbbd4903fe8108667c72
Patch101:       protobuf-improve-performance-of-parsing-unknown-fields-in-Java.patch
# PATCH-FIX-UPSTREAM https://github.com/protocolbuffers/protobuf/commit/55815e423bb82cc828836bbd60c79c1f9a195763
Patch102:       protobuf-CVE-2022-1941.patch
# PATCH-FIX-UPSTREAM https://github.com/protocolbuffers/protobuf/commit/42e47e5a3fa7219b136f6a5de7c74a89a79245c6
Patch103:       protobuf-CVE-2022-3171.patch
BuildRequires:  %{python_module devel}
BuildRequires:  %{python_module python-dateutil}
BuildRequires:  %{python_module python-gflags}
BuildRequires:  %{python_module pytz}
BuildRequires:  %{python_module setuptools}
BuildRequires:  %{python_module six}
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  libtool
BuildRequires:  pkgconfig
BuildRequires:  python-rpm-macros
BuildRequires:  zlib-devel
%if %{with check}
BuildRequires:  libgmock-devel >= 1.7.0
%endif
%if %{with java}
BuildRequires:  java-devel >= 1.6.0
BuildRequires:  maven-local
BuildRequires:  mvn(com.google.code.findbugs:jsr305)
BuildRequires:  mvn(com.google.code.gson:gson)
BuildRequires:  mvn(com.google.errorprone:error_prone_annotations)
BuildRequires:  mvn(com.google.guava:guava)
BuildRequires:  mvn(com.google.j2objc:j2objc-annotations)
BuildRequires:  mvn(org.apache.felix:maven-bundle-plugin)
BuildRequires:  mvn(org.apache.maven.plugins:maven-antrun-plugin)
BuildRequires:  mvn(org.codehaus.mojo:build-helper-maven-plugin)
%endif

%description
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotobuf%{sover}
Summary:        Protocol Buffers - Google's data interchange format
Group:          System/Libraries

%description -n libprotobuf%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotoc%{sover}
Summary:        Protocol Buffers - Google's data interchange format
Group:          System/Libraries

%description -n libprotoc%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package -n libprotobuf-lite%{sover}
Summary:        Protocol Buffers - Google's data interchange format
Group:          System/Libraries

%description -n libprotobuf-lite%{sover}
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package devel
Summary:        Header files, libraries and development documentation for %{name}
Group:          Development/Libraries/C and C++
Requires:       gcc-c++
Requires:       libprotobuf%{sover} = %{version}
Requires:       libprotobuf-lite%{sover}
Requires:       zlib-devel
Conflicts:      protobuf2-devel
Provides:       libprotobuf-devel = %{version}

%description devel
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

%package source
Summary:        Source code of protobuf
Group:          Development/Sources
BuildArch:      noarch

%description source
Protocol Buffers are a way of encoding structured data in an efficient yet
extensible format. Google uses Protocol Buffers for almost all of its internal
RPC protocols and file formats.

This package contains source code for Protocol Buffers.

%package java
Summary:        Java Bindings for Google Protocol Buffers
Group:          Development/Libraries/Java
Requires:       java >= 1.6.0
BuildArch:      noarch

%description java
This package contains the Java bindings for Google Protocol Buffers.

%package java-bom
Summary:        Java Bindings for Google Protocol Buffers
Group:          Development/Libraries/Java
BuildArch:      noarch

%description java-bom
This package contains the Java bindings for Google Protocol Buffers.

%package java-parent
Summary:        Java Bindings for Google Protocol Buffers
Group:          Development/Libraries/Java
BuildArch:      noarch

%description java-parent
This package contains the Java bindings for Google Protocol Buffers.

%package -n python2-%{name}
Summary:        Python2 Bindings for Google Protocol Buffers
Group:          Development/Libraries/Python
Requires:       python-six
Provides:       python-%{name} = %{version}
Obsoletes:      python-%{name} < %{version}

%description -n python2-%{name}
This package contains the Python bindings for Google Protocol Buffers.

%package -n python3-%{name}
Summary:        Python3 Bindings for Google Protocol Buffers
Group:          Development/Libraries/Python
Requires:       python3-six

%description -n python3-%{name}
This package contains the Python bindings for Google Protocol Buffers.

%prep
%autosetup -p1 -n %{tarname}-%{version}

mkdir gmock

%if %{with python2} || %{with python3}
# only needed for test suite which we don't call anyways.
# googleapis is broken on sle12
sed -i '/apputils/d' python/setup.py
sed -i '/google_test_dir/d' python/setup.py
%endif
# kill shebang that we do not really want
sed -i -e '/env python/d' python/google/protobuf/internal/*.py

%if %{with java}
pushd java
%pom_xpath_set "pom:plugin[pom:artifactId[text()='maven-compiler-plugin']]/pom:configuration/pom:source" "1.8"
%pom_xpath_set "pom:plugin[pom:artifactId[text()='maven-compiler-plugin']]/pom:configuration/pom:target" "1.8"

%{mvn_package} :{*}-parent parent
%{mvn_package} :{*}-bom bom

%{mvn_file} :{*} @1
%{mvn_file} :%{name}-java %{name}
popd
%endif

%build
%define _lto_cflags %{nil}
autoreconf -fvi
%configure \
	--disable-static

make %{?_smp_mflags}

%if %{with java}
pushd java
%{mvn_build} -jf -- -Dprotoc=$(pwd)/../src/protoc -Dmaven.compiler.source=8 -Dmaven.compiler.target=8
popd
%endif

pushd python
%python_build
popd

%if %{with check}
%check
make %{?_smp_mflags} check
%endif

%install
%make_install
install -Dm 0644 editors/proto.vim %{buildroot}%{_datadir}/vim/site/syntax/proto.vim
# no need for that
find %{buildroot} -type f -name "*.la" -delete -print

%if %{with java}
pushd java
%mvn_install
# create maven metadata for the protoc executable
install -dm 0755 %{buildroot}%{_datadir}/maven-metadata
cat <<__PROTOBUF__ >>%{buildroot}%{_datadir}/maven-metadata/%{name}-protoc.xml
<metadata xmlns="http://fedorahosted.org/xmvn/METADATA/2.3.0">
  <artifacts>
    <artifact>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protoc</artifactId>
      <extension>exe</extension>
      <classifier>linux-%{protoc_arch}</classifier>
      <version>%{version}</version>
      <path>%{_bindir}/protoc</path>
    </artifact>
  </artifacts>
</metadata>
__PROTOBUF__
popd
%endif

pushd python
%python_install
popd
%python_expand %fdupes %{buildroot}%{$python_sitelib}

mkdir -p %{buildroot}%{src_install_dir}
tar -xzf %{SOURCE0} --strip-components=1 -C %{buildroot}%{src_install_dir}
%fdupes %{buildroot}%{src_install_dir}
# Fix env-script-interpreter rpmlint error
find %{buildroot}%{src_install_dir} -type f -name "*.js" -exec sed -i 's|#!.*%{_bindir}/env node|#!%{_bindir}/node|' "{}" +
find %{buildroot}%{src_install_dir} -type f -name "*.py" -exec sed -i 's|#!.*%{_bindir}/env python2.7|#!%{_bindir}/python2.7|' "{}" +
find %{buildroot}%{src_install_dir} -type f -name "*.py" -exec sed -i 's|#!.*%{_bindir}/env python|#!%{_bindir}/python|' "{}" +
find %{buildroot}%{src_install_dir} -type f -name "*.rb" -exec sed -i 's|#!.*%{_bindir}/env ruby|#!%{_bindir}/ruby|' "{}" +
find %{buildroot}%{src_install_dir} -type f -name "*.sh" -exec sed -i 's|#!.*%{_bindir}/env bash|#!/bin/bash|' "{}" +
# And stop requiring ridiculously old Python version
find %{buildroot}%{src_install_dir} -type f -name "*.py" -exec sed -i 's|#!%{_bindir}/python2.4|#!%{_bindir}/python2.7|' "{}" +
# Fix spurious-executable-perm rpmlint error
chmod -x %{buildroot}%{src_install_dir}/src/google/protobuf/arenastring.h
chmod -x %{buildroot}%{src_install_dir}/src/google/protobuf/compiler/js/js_generator.h
chmod -x %{buildroot}%{src_install_dir}/src/google/protobuf/reflection.h
# Fix version-control-internal-file rpmlint warning
find %{buildroot}%{src_install_dir} -type f -name ".gitignore" -exec rm -f "{}" +

%fdupes %{buildroot}%{_prefix}

%post -n libprotobuf%{sover} -p /sbin/ldconfig
%postun -n libprotobuf%{sover} -p /sbin/ldconfig
%post -n libprotoc%{sover} -p /sbin/ldconfig
%postun -n libprotoc%{sover} -p /sbin/ldconfig
%post -n libprotobuf-lite%{sover} -p /sbin/ldconfig
%postun -n libprotobuf-lite%{sover} -p /sbin/ldconfig

%files -n libprotobuf%{sover}
%license LICENSE
%{_libdir}/libprotobuf.so.%{sover}*

%files -n libprotoc%{sover}
%{_libdir}/libprotoc.so.%{sover}*

%files -n libprotobuf-lite%{sover}
%{_libdir}/libprotobuf-lite.so.%{sover}*

%files devel
%doc CHANGES.txt CONTRIBUTORS.txt README.md
%{_bindir}/protoc
%{_includedir}/google
%{_libdir}/*.so
%{_libdir}/pkgconfig/*
%{_datadir}/vim
%if %{with java}
%{_datadir}/maven-metadata/%{name}-protoc.xml
%endif

%files source
%{src_install_dir}

%if %{with java}
%files java -f java/.mfiles

%files java-bom -f java/.mfiles-bom

%files java-parent -f java/.mfiles-parent
%endif

%if %{with python2}
%files -n python2-%{name}
%license LICENSE
%{python2_sitelib}/*
%endif

%if %{with python3}
%files -n python3-%{name}
%license LICENSE
%{python3_sitelib}/*
%endif

%changelog
openSUSE Build Service is sponsored by