Blob Blame History Raw
%global         so_version   0

Name:           jsonnet
Version:        0.17.0
Release:        2%{?dist}
Summary:        A data templating language based on JSON

# The bundled MD5 library is RSA licenced
License:        ASL 2.0 and RSA

URL:            https://github.com/google/jsonnet
Source0:        %{url}/archive/v%{version}/%{name}-%{version}.tar.gz

# Downstream man pages in groff_man(7) format
Source1:        jsonnet.1
Source2:        jsonnetfmt.1

# Upstream wants to build single source wheels
# these benefit from static linking,
# but we want to link to libjsonnet here so we are sharing the lib
Patch0001:      0001-Dynamic-link-to-libjsonnet-rather-than-static.patch
Patch0002:      0002-jsonnet-0.17.0-do-not-override-compiler-flags.patch


# Bundled MD5 C++ class with very permissive license (RSA)
# rpmlint must be notified of the unversioned provides
Provides:       bundled(md5-thilo)

BuildRequires:  python3-devel
BuildRequires:  python3-setuptools

BuildRequires:  bash cmake3 gcc gcc-c++ gtest-devel make

# json is header only, so note the static lib for tracking
BuildRequires:  json-devel >= 3.6
BuildRequires:  json-static >= 3.6

# Set our toplevel runtime requirements
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%global _description %{expand:
A data templating language for app and tool developers based on JSON}

%description %{_description}


%package -n python3-%{name}
Summary:        %{name} Bindings for Python
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%description -n python3-%{name} %{_description}


%package libs
Summary:        Shared Libraries for %{name}

%description libs %{_description}


%package devel
Summary:        Development Headers for %{name}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%description devel %{_description}


%package doc
Summary:        Documentation for %{name}
License:        CC-BY
BuildArch:      noarch

%description doc %{_description}


%prep
%autosetup

# use system json lib instead
rm -rfv third_party/json/*

# don't bundel rapidyaml
rm -rfv third_party/rapidyaml/*

# don't bundle thirdparty doc resources
# this leaves the doc "unbuilt" but still sorta useful
rm -rf doc/third_party
rm -rf doc/.gitignore


%build

%if 0%{?rhel} == 7
# required macro drop for EL7
%undefine __cmake3_in_source_build
%endif


# FIXME:
# For reasons I'm not following, json-devel isn't added to include by cmake
#
# explicitly set -fPIC so python can pick it up later on
export CXXFLAGS="%{optflags} -fPIC -I%{_includedir}/nlohmann -std=c++11"

# setup our build environment
%cmake3 -DBUILD_SHARED_BINARIES:BOOL=ON -DBUILD_STATIC_LIBS:BOOL=OFF -DUSE_SYSTEM_JSON:BOOL=ON -DUSE_SYSTEM_GTEST:BOOL=ON

# make tools and headers
%cmake3_build

# make python binding
%{py3_build}


%install
%{cmake3_install}

# install python binding
%{py3_install}

install -d '%{buildroot}%{_mandir}/man1'
install -t '%{buildroot}%{_mandir}/man1' -p -m 0644 '%{SOURCE1}' '%{SOURCE2}'


%check
%{ctest3}


%files
%{_bindir}/jsonnet
%{_bindir}/jsonnetfmt
%{_mandir}/man1/jsonnet.1*
%{_mandir}/man1/jsonnetfmt.1*

%files libs
%license LICENSE
%doc README.md
%{_libdir}/lib%{name}*.so.%{so_version}
%{_libdir}/lib%{name}*.so.%{version}

%files devel
%{_includedir}/lib%{name}*
%{_libdir}/lib%{name}*.so

%files -n python3-%{name}
# rpmlint must be notified this is not versioned on purpose
%{python3_sitearch}/_%{name}*.so
%{python3_sitearch}/%{name}-%{version}-py%{python3_version}.egg-info

%files doc
%license LICENSE
%doc README.md
%doc CONTRIBUTING
%doc doc
%doc examples
# don't package up the self-check script
%exclude %{_docdir}/%{name}-doc/examples/*.sh


%changelog
* Fri Jun 25 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.17.0-2
- Add downstream man pages
- Fix Summary

* Thu Jun 17 2021 Pat Riehecky <riehecky@fnal.gov> - 0.17.0-1
- Initial package.