Blob Blame History Raw
# GCC will only load plugins that were built against exactly that build of GCC
# We thus need to embed the exact GCC version as a requirement within the
# metadata.
#
# Define "gcc_vr", a variable to hold the VERSION-RELEASE string for the gcc
# we are being built against.
#
# Unfortunately, we can't simply run:
#   rpm -q --qf="%{version}-%{release}"
# to determine this, as there's no guarantee of a sane rpm database within
# the chroots created by our build system
#
# So we instead query the version from gcc's output.
#
# gcc.spec has:
#   Version: %{gcc_version}
#   Release: %{gcc_release}%{?dist}
#   ...snip...
#   echo 'Red Hat %{version}-%{gcc_release}' > gcc/DEV-PHASE

# So, given this output:
#
#   $ gcc --version
#   gcc (GCC) 4.6.1 20110908 (Red Hat 4.6.1-9)
#   Copyright (C) 2011 Free Software Foundation, Inc.
#   This is free software; see the source for copying conditions.  There is NO
#   warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# we can scrape out the "4.6.1-9" from the version line.
#
# We then have to add the dist tag; which we must hope is the same as what we
# have
#
# The following implements the above:
%global gcc_vr %(gcc --version | python -c "import re; import sys; print(re.match(r'.*\\(Red Hat (.+)\\).*', sys.stdin.read()).group(1))")%{dist}

# Define a boolean to make it easy to turn the above off, in case it fails:
%global with_hard_gcc_version_requirement 1


%global python3_debug_config  python3.5dm-config


Name:           gcc-python-plugin
Version:        0.15
Release:        1%{?dist}
Summary:        GCC plugin that embeds Python

Group:          Development/Languages
License:        GPLv3+
URL:            https://fedorahosted.org/gcc-python-plugin/
Source0:        https://fedorahosted.org/releases/g/c/gcc-python-plugin/gcc-python-plugin-%{version}.tar.gz
Patch2:         arm-fixes.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildRequires:  gcc-plugin-devel

# gcc 4.6.1's plugin/include/double-int.h includes "gmp.h", but on Fedora,
# gmp-devel isn't yet listed in the requirements of gcc-plugin-devel
# For now, explicitly require it:
BuildRequires:  gmp-devel
# Filed as https://bugzilla.redhat.com/show_bug.cgi?id=725569


# Various python runtimes to build the plugin against:
BuildRequires:  python-devel
BuildRequires:  python-debug
BuildRequires:  python3-devel
BuildRequires:  python3-debug

# "six" is used at buildtime:
BuildRequires:  python-six
BuildRequires:  python3-six

# sphinx is used for building documentation:
BuildRequires:  python-sphinx

# pygments is used when running the selftests:
BuildRequires: python-pygments
BuildRequires: python3-pygments

# lxml is used when running the selftests:
BuildRequires: python-lxml
BuildRequires: python3-lxml

%global gcc_plugins_dir %(gcc --print-file-name=plugin)

%description
Plugins for embedding various versions of Python within GCC

%package -n gcc-python-plugin-c-api
Summary: Shared library to make it easier to write GCC plugins
Group:   Development/Languages

%description -n gcc-python-plugin-c-api
Shared library to make it easier to write GCC plugins

%if %{with_hard_gcc_version_requirement}
Requires: gcc = %{gcc_vr}
%else
Requires: gcc
%endif

%package -n gcc-python2-plugin
Summary: GCC plugin embedding Python 2
Group:   Development/Languages
Requires: python-lxml
Requires: python-six
Requires: python-pygments
%if %{with_hard_gcc_version_requirement}
Requires: gcc = %{gcc_vr}
%else
Requires: gcc
%endif
Requires: gcc-python-plugin-c-api%{?_isa} = %{version}-%{release}

%description  -n gcc-python2-plugin
GCC plugin embedding Python 2

%package -n gcc-python3-plugin
Summary: GCC plugin embedding Python 3
Group:   Development/Languages
Requires: python3-lxml
Requires: python3-six
Requires: python3-pygments
%if %{with_hard_gcc_version_requirement}
Requires: gcc = %{gcc_vr}
%else
Requires: gcc
%endif
Requires: gcc-python-plugin-c-api%{?_isa} = %{version}-%{release}

%description  -n gcc-python3-plugin
GCC plugin embedding Python 3

%package -n gcc-python2-debug-plugin
Summary: GCC plugin embedding Python 2 debug build
Group:   Development/Languages
Requires: python-lxml
Requires: python-six
Requires: python-pygments
%if %{with_hard_gcc_version_requirement}
Requires: gcc = %{gcc_vr}
%else
Requires: gcc
%endif
Requires: gcc-python-plugin-c-api%{?_isa} = %{version}-%{release}

%description  -n gcc-python2-debug-plugin
GCC plugin embedding debug build of Python 2

%package -n gcc-python3-debug-plugin
Summary: GCC plugin embedding Python 3 debug build
Group:   Development/Languages
Requires: python3-lxml
Requires: python3-six
Requires: python3-pygments
%if %{with_hard_gcc_version_requirement}
Requires: gcc = %{gcc_vr}
%else
Requires: gcc
%endif
Requires: gcc-python-plugin-c-api%{?_isa} = %{version}-%{release}

%description  -n gcc-python3-debug-plugin
GCC plugin embedding debug build of Python 3

%package docs
Summary: API documentation for the GCC Python plugin
Group:   Development/Languages

%description docs
This package contains API documentation for the GCC Python plugin



%prep
%setup -q
%patch2 -p1 -b .arm-fixes.patch

# We will be building the plugin 4 times, each time against a different
# Python runtime
#
# The plugin doesn't yet cleanly support srcdir != builddir, so for now
# make 4 separate copies of the source, once for each build

PrepPlugin() {
    PluginName=$1

    BuildDir=../gcc-python-plugin-%{version}-building-for-$PluginName

    rm -rf $BuildDir
    cp -a . $BuildDir
}

PrepPlugin \
  python2

PrepPlugin \
  python2_debug

PrepPlugin \
  python3

PrepPlugin \
  python3_debug

%build

echo "gcc_vr: %{gcc_vr}"

BuildPlugin() {
    PythonExe=$1
    PythonConfig=$2
    PluginDso=$3
    PluginName=$4

    BuildDir=../gcc-python-plugin-%{version}-building-for-$PluginName

    pushd $BuildDir
    make \
       %{?_smp_mflags} \
       PLUGIN_NAME=$PluginName \
       PLUGIN_DSO=$PluginDso \
       PYTHON=$PythonExe \
       PYTHON_CONFIG=$PythonConfig \
       PLUGIN_PYTHONPATH=%{gcc_plugins_dir}/$PluginName \
       plugin print-gcc-version
    popd
}

BuildPlugin \
  python \
  python-config \
  python2.so \
  python2

BuildPlugin \
  python-debug \
  python-debug-config \
  python2_debug.so \
  python2_debug

BuildPlugin \
  python3 \
  python3-config \
  python3.so \
  python3

BuildPlugin \
  python3-debug \
  %{python3_debug_config} \
  python3_debug.so \
  python3_debug

# Documentation:
cd docs
make html
# Avoid having a hidden file in the payload:
rm _build/html/.buildinfo

make man

%install
rm -rf $RPM_BUILD_ROOT

mkdir -p $RPM_BUILD_ROOT/%{gcc_plugins_dir}
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
mkdir -p $RPM_BUILD_ROOT/%{_mandir}/man1

InstallPlugin() {
    PythonExe=$1
    PythonConfig=$2
    PluginDso=$3
    PluginName=$4

    BuildDir=../gcc-python-plugin-%{version}-building-for-$PluginName

    pushd $BuildDir
    make install \
        DESTDIR=$RPM_BUILD_ROOT \
        PLUGIN_NAME=$PluginName \
        PLUGIN_DSO=$PluginDso
    popd

    # (doing the above actually installs each build's copy of libgccapi.so,
    # all to the same location, but they should all be identical, so that's
    # OK)
}

InstallPlugin \
  python \
  python-config \
  python2.so \
  python2

InstallPlugin \
  python-debug \
  python-debug-config \
  python2_debug.so \
  python2_debug

InstallPlugin \
  python3 \
  python3-config \
  python3.so \
  python3

InstallPlugin \
  python3-debug \
  %{python3_debug_config} \
  python3_debug.so \
  python3_debug


%clean
rm -rf $RPM_BUILD_ROOT

%check

CheckPlugin() {
    PythonExe=$1
    PythonConfig=$2
    PluginDso=$3
    PluginName=$4
    SelftestArgs=$5

    BuildDir=../gcc-python-plugin-%{version}-building-for-$PluginName

    pushd $BuildDir

    # Run the selftests:
    LD_LIBRARY_PATH=gcc-c-api \
    PLUGIN_NAME=$PluginName \
        $PythonExe run-test-suite.py $SelftestArgs

    LD_LIBRARY_PATH=gcc-c-api \
    PLUGIN_NAME=$PluginName \
        $PythonExe testcpychecker.py -v

    popd
}

# Selftest for python2 (optimized) build
# All tests ought to pass:
CheckPlugin \
  python \
  python-config \
  python2.so \
  python2 \
  %{nil}

# Selftest for python2-debug build:
# Disable the cpychecker tests for now: somewhat ironically, the extra
# instrumentation in the debug build breaks the selftests for the refcount
# tracker.  (specifically, handling of _Py_RefTotal):
#
#   Failed tests:
#     tests/cpychecker/refcounts/correct_py_none
#     tests/cpychecker/refcounts/correct_decref
#     tests/cpychecker/refcounts/use_after_dealloc
#     tests/cpychecker/refcounts/returning_dead_object
#     tests/cpychecker/refcounts/too_many_increfs
#     tests/cpychecker/refcounts/loop_n_times
#
CheckPlugin \
  python-debug \
  python-debug-config \
  python2_debug.so \
  python2_debug \
  "-x tests/cpychecker"

# Selftest for python3 (optimized) build:
# Disable the cpychecker tests for now:
#   Failed tests:
#     tests/cpychecker/PyArg_ParseTuple/incorrect_codes_S_and_U
#     tests/cpychecker/PyArg_ParseTuple/correct_codes_S_and_U
#     tests/cpychecker/refcounts/correct_decref
#     tests/cpychecker/refcounts/fold_conditional
#     tests/cpychecker/refcounts/use_after_dealloc
#     tests/cpychecker/refcounts/missing_decref
#     tests/cpychecker/refcounts/returning_dead_object
#     tests/cpychecker/refcounts/too_many_increfs
#     tests/cpychecker/refcounts/loop_n_times
#
CheckPlugin \
  python3 \
  python3-config \
  python3.so \
  python3 \
  "-x tests/cpychecker"

# Selftest for python3-debug build:
#   (shares the issues of the above)
CheckPlugin \
  python3-debug \
  %{python3_debug_config} \
  python3_debug.so \
  python3_debug \
  "-x tests/cpychecker"

%files -n gcc-python-plugin-c-api
%{gcc_plugins_dir}/libgcc-c-api.so

%files -n gcc-python2-plugin
%defattr(-,root,root,-)
%doc COPYING README.rst
%{_bindir}/gcc-with-python2
%{gcc_plugins_dir}/python2.so
%{gcc_plugins_dir}/python2
%doc %{_mandir}/man1/gcc-with-python2.1.gz

%files -n gcc-python3-plugin
%defattr(-,root,root,-)
%doc COPYING README.rst
%{_bindir}/gcc-with-python3
%{gcc_plugins_dir}/python3.so
%{gcc_plugins_dir}/python3
%doc %{_mandir}/man1/gcc-with-python3.1.gz

%files -n gcc-python2-debug-plugin
%defattr(-,root,root,-)
%doc COPYING README.rst
%{_bindir}/gcc-with-python2_debug
%{gcc_plugins_dir}/python2_debug.so
%{gcc_plugins_dir}/python2_debug
%doc %{_mandir}/man1/gcc-with-python2_debug.1.gz

%files -n gcc-python3-debug-plugin
%defattr(-,root,root,-)
%doc COPYING README.rst
%{_bindir}/gcc-with-python3_debug
%{gcc_plugins_dir}/python3_debug.so
%{gcc_plugins_dir}/python3_debug
%doc %{_mandir}/man1/gcc-with-python3_debug.1.gz

%files docs
%defattr(-,root,root,-)
%doc COPYING
%doc docs/_build/html
# Example scripts:
%doc examples

%changelog
* Mon Feb 15 2016 David Malcolm <dmalcolm@redhat.com> - 0.15-1
- 0.15
- drop fix-python-3.4-failures.patch (upstreamed)
- regenerate arm-fixes.patch

* Wed Feb 03 2016 Fedora Release Engineering <releng@fedoraproject.org> - 0.14-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Thu Dec 10 2015 Jakub Jelinek <jakub@redhat.com> - 0.14-8
- rebuild against latest gcc

* Tue Dec  8 2015 Jakub Jelinek <jakub@redhat.com> - 0.14-7
- rebuild against latest gcc

* Wed Nov 11 2015 David Malcolm <dmalcolm@redhat.com> - 0.14-6
- update python3_debug_config for Python 3.5

* Tue Nov 10 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org>
- Rebuilt for https://fedoraproject.org/wiki/Changes/python3.5

* Fri Jun 19 2015 Jakub Jelinek <jakub@redhat.com> - 0.14-4
- rebuild against latest gcc

* Wed Jun 17 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org>
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Sat Jun 13 2015 Jakub Jelinek <jakub@redhat.com> - 0.14-2
- rebuild against latest gcc

* Wed May  6 2015 David Malcolm <dmalcolm@redhat.com> - 0.14-1
- 0.14

* Sun Nov  2 2014 Jakub Jelinek <jakub@redhat.com> - 0.13-2
- rebuild against latest gcc

* Fri Oct  3 2014 Dan HorĂ¡k <dan[at]danny.cz> - 0.13-1.1
- rebuilt for koji db problem

* Wed Oct  1 2014 David Malcolm <dmalcolm@redhat.com> - 0.13-1
- 0.13; drop patches 1-7, add requirements on python-lxml and
python3-lxml
- update to python 3.4
- add fixes for python 3.4 (patch 1) and arm (patch 2)

* Sat Aug 16 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org>
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Sat Jun 07 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.12-19
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Sun Feb 02 2014 Kyle McMartin <kyle@redhat.com> - 0.12-18
- rebuild against latest gcc

* Thu Dec 19 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-17
- rebuild against latest gcc

* Fri Nov 22 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-16
- rebuild against latest gcc

* Thu Oct 17 2013 Jakub Jelinek <jakub@redhat.com> - 0.12-15
- rebuild against latest gcc

* Mon Sep 23 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-14
- rebuild against latest gcc

* Wed Sep 18 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-13
- rebuild against latest gcc

* Thu Aug 22 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-12
- rebuild against latest gcc

* Wed Aug 21 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-11
- skip some more tests (patch 7)

* Tue Aug 20 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-10
- cherrypick patches from upstream (patch 5, patch 6)

* Sat Aug 03 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.12-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Thu Jul 18 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-8
- rebuild against latest gcc

* Sat Jun 15 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-7
- rebuild against latest gcc

* Tue Jun  4 2013 Jakub Jelinek <jakub@redhat.com> - 0.12-6
- rebuild against latest gcc

* Mon May 27 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-5
- rebuild against latest gcc

* Sat May 18 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-4
- rebuild against latest gcc

* Mon May 13 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-3
- rebuild against latest gcc

* Thu May  9 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-2
- rebuild against latest gcc

* Tue Apr 23 2013 David Malcolm <dmalcolm@redhat.com> - 0.12-1
- 0.12, adding gcc-python-plugin-c-api subpackage, and 3 workarounds from
upstream git (patch 2, patch 3, patch 4)
- reorganize specfile to use the "make install" from upstream, and building
each plugin from a separate srcdir
- rename the debug plugins to use underscores rather than dashes in the
names, since the latter appears to confuse GCC's option-parser

* Wed Feb 13 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.11-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* Thu Nov 29 2012 David Malcolm <dmalcolm@redhat.com> - 0.11-1
- 0.11

* Tue Nov 27 2012 Tom Callaway <spot@fedoraproject.org> - 0.9-7
- another round of rebuilds for broken deps

* Wed Oct 31 2012 Tom Callaway <spot@fedoraproject.org> - 0.9-6
- rebuild again to fix broken deps

* Sun Sep 23 2012 Jakub Jelinek <jakub@redhat.com> - 0.9-5
- rebuilt against gcc 4.7.2-2

* Wed Aug 29 2012 David Malcolm <dmalcolm@redhat.com> - 0.9-4
- fix build ordering in Makefile

* Tue Aug 28 2012 David Malcolm <dmalcolm@redhat.com> - 0.9-3
- rebuild against Python 3.3

* Wed May  9 2012 David Malcolm <dmalcolm@redhat.com> - 0.9-2
- fix FTBFS against gcc-4.7.0-4 (patch 1)

* Mon Feb  6 2012 David Malcolm <dmalcolm@redhat.com> - 0.9-1
- 0.9

* Fri Jan 13 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.7-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* Tue Nov 29 2011 David Malcolm <dmalcolm@redhat.com> - 0.7-1
- 0.7; drop patch 1

* Wed Oct 26 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.6-4
- Rebuilt for glibc bug#747377

* Mon Oct  3 2011 David Malcolm <dmalcolm@redhat.com> - 0.6-3
- add hard requirement on the exact gcc version the plugin was built with

* Mon Sep 19 2011 David Malcolm <dmalcolm@redhat.com> - 0.6-2
- fix include paths against gcc-4.6.1-7.fc16 onwards (rhbz#728011)

* Tue Aug  2 2011 David Malcolm <dmalcolm@redhat.com> - 0.6-1
- 0.6

* Wed Jul 27 2011 David Malcolm <dmalcolm@redhat.com> - 0.5-1
- 0.5
- examples are now in an "examples" subdirectory

* Tue Jul 26 2011 David Malcolm <dmalcolm@redhat.com> - 0.4-1
- 0.4
- add requirement on pygments
- run the upstream test suites during %%check

* Mon Jul 25 2011 David Malcolm <dmalcolm@redhat.com> - 0.3-1
- add requirements on python-six and python3-six
- add %%check section (empty for now)
- set PYTHON and PLUGIN_PYTHONPATH during each build; install support files
into build-specific directories below the gcc plugin dir
- add helper gcc-with-python scripts, with man pages
- package the license
- add example scripts
- add explicit BR on gmp-devel (rhbz#725569)

* Tue May 24 2011 David Malcolm <dmalcolm@redhat.com> - 0.1-1
- initial packaging