4e3126d
# Build HTML docs from markdown using pandoc?
4e3126d
%bcond_without html_docs
4e3126d
4e3126d
Name:           gn
4e3126d
# Upstream uses the number of commits in the git history as the version number.
4e3126d
# See gn --version, which outputs something like “1874 (2b683eff)”. The commit
4e3126d
# position and short commit hash in this string come from “git describe HEAD
4e3126d
# --match initial-commit”; see build/gen.py. This means that a complete git
4e3126d
# checkout is required to establish the version number; the information is not
4e3126d
# in the tarball! This is terribly inconvenient. See
4e3126d
# https://bugs.chromium.org/p/gn/issues/detail?id=3.
4e3126d
#
4e3126d
# As a result, it is necessary to use our custom update-version script,
4e3126d
# supplying the new full commit hash as the sole argument or providing no
4e3126d
# arguments to select the latest commit. This will:
4e3126d
#  1. Clone the git repository from the Internet (a substantial download)
4e3126d
#  2. Run build/gen.py to generate last_commit_position.h, the header with
4e3126d
#     version information, and copy it into the same directory as the script
4e3126d
#  3. Modify the commit and access macros and the Version field in this spec
4e3126d
#     file.
4e3126d
#  4. Download the source tarball (spectool -g)
4e3126d
#  5. Update the sources (fedpkg new-sources %%{commit}.tar.gz)
4e3126d
#  6. Stage all changes in git
34cf56e
#
34cf56e
# See https://gn.googlesource.com/gn/+log for the latest changes.
ac92af9
%global commit 4d207c94eab41f09c9a8505eb47f3d2919e47943
ac92af9
%global access 20210627
4e3126d
%global shortcommit %(echo %{commit} | cut -b -8)
ac92af9
Version:        1921
a2b7d1c
Release:        %autorelease -s %{access}git%{shortcommit}
4e3126d
Summary:        Meta-build system that generates build files for Ninja
4e3126d
4e3126d
# BSD except for src/base/third_party/icu/, which is (Unicode and MIT); note
4e3126d
# that the “ICU License” is MIT,
4e3126d
# https://fedoraproject.org/wiki/Licensing:MIT#Modern_style_.28ICU_Variant.29
4e3126d
#
4e3126d
# Note that src/util/test/gn_test.cc, which is licensed ASL 2.0, does not
4e3126d
# contribute to the installed RPM, only to the gn_unittests executable; you may
4e3126d
# verify this with:
4e3126d
#   gdb -ex 'set pagination off' -ex 'info sources' gn | grep -F gn_test.cc
4e3126d
License:        BSD and Unicode and MIT
4e3126d
URL:            https://%{name}.googlesource.com/%{name}
df5ad5f
Source0:        %{url}/+archive/%{commit}.tar.gz#/%{name}-%{shortcommit}.tar.gz
4e3126d
# Generated using script update-version:
4e3126d
Source1:        last_commit_position.h
4e3126d
Source2:        update-version
4e3126d
70b288a
# Clean up compiler warnings on gcc/g++. This patch is a rebased version of
70b288a
# chromium-84.0.4147.105-gn-gcc-cleanup.patch from the chromium RPM; see:
70b288a
#
70b288a
#   https://src.fedoraproject.org/rpms/chromium/raw/
70b288a
#     ce30313f5e4af121140c037bf026453355534f24/f/
70b288a
#     chromium-84.0.4147.105-gn-gcc-cleanup.patch
70b288a
Patch0:         %{name}-39a87c0b-gcc-cleanup.patch
958042a
# Stop overriding optimization flags
958042a
Patch1:         %{name}-0153d369-no-O3.patch
4e3126d
4e3126d
# The python3_pkgversion macro is required for EPEL; see
4e3126d
# https://fedoraproject.org/wiki/PackagingDrafts:Python3EPEL. On Fedora (and
4e3126d
# EPEL8) it simply expands to “3”.
4e3126d
BuildRequires:  python%{python3_pkgversion}
4e3126d
BuildRequires:  python%{python3_pkgversion}-devel
4e3126d
BuildRequires:  ninja-build
4e3126d
BuildRequires:  gcc-c++
4e3126d
4e3126d
BuildRequires:  /usr/bin/pathfix.py
4e3126d
4e3126d
%if %{with html_docs}
4e3126d
BuildRequires:  pandoc
4e3126d
BuildRequires:  parallel
4e3126d
%endif
4e3126d
BuildRequires:  help2man
4e3126d
4e3126d
Requires:       vim-filesystem
4e3126d
Requires:       python%{python3_pkgversion}
4e3126d
Provides:       vim-%{name} = %{version}-%{release}
4e3126d
4e3126d
BuildRequires:  emacs
4e3126d
Requires:       emacs-filesystem >= %{_emacs_version}
4e3126d
Provides:       emacs-%{name} = %{version}-%{release}
4e3126d
4e3126d
4e3126d
%description
4e3126d
GN is a meta-build system that generates build files for Ninja.
4e3126d
4e3126d
4e3126d
%package doc
4e3126d
Summary:        Documentation for GN
4e3126d
BuildArch:      noarch
4e3126d
4e3126d
%description doc
4e3126d
The %{name}-doc package contains detailed documentation for GN.
4e3126d
4e3126d
4e3126d
%prep
70b288a
%autosetup -c -n %{name}-%{commit} -p1
4e3126d
4e3126d
# Use pre-generated last_commit_position.h.
4e3126d
mkdir -p ./out
4e3126d
cp -vp '%{SOURCE1}' ./out
4e3126d
4e3126d
# Copy and rename vim extensions readme for use in the main documentation
4e3126d
# directory.
4e3126d
cp -vp misc/vim/README.md README-vim.md
4e3126d
4e3126d
# Fix shebangs in examples and such.
4e3126d
%py3_shebang_fix .
4e3126d
0fa9596
# Stop overriding optimization flags
0fa9596
sed -r -i '/.append(.-O3.)/d' build/gen.py
0fa9596
4e3126d
4e3126d
%build
4e3126d
# We need to set CC and CXX explicitly before Fedora 33, including on the EPELs.
4e3126d
CC='gcc'; export CC
4e3126d
CXX='g++'; export CXX
4e3126d
AR='gcc-ar'; export AR
4e3126d
%set_build_flags
4e3126d
# Both --use-icf and --use-lto add compiler flags that only work with clang++,
4e3126d
# not with g++. We do get LTO on Fedora anyway, since we respect the
4e3126d
# distribution’s build flags.
4e3126d
%{__python3} build/gen.py \
4e3126d
    --no-last-commit-position \
4e3126d
    --no-strip \
4e3126d
    --no-static-libstdc++
4e3126d
ninja -C out -v
4e3126d
4e3126d
%if %{with html_docs}
4e3126d
# There is a script, misc/help_as_html.py, that generates some HTML help, but
4e3126d
# pandoc does a better job and we can cover more Markdown sources.
4e3126d
find . -type f -name '*.md' | parallel -v pandoc -o '{.}.html' '{}'
4e3126d
%endif
4e3126d
4e3126d
help2man \
4e3126d
    --name='%{summary}' \
4e3126d
    --version-string="%{name} $(./out/%{name} --version)" \
4e3126d
    --no-info \
4e3126d
    ./out/%{name} |
4e3126d
  # Clean up a couple of stray binary bytes in the help output
4e3126d
  tr -d '\302\240' |
4e3126d
  # Format the entries within the sections as tagged paragraphs, and italicise
4e3126d
  # [placeholders in square brackets].
4e3126d
  sed -r -e 's/(^[[:alnum:]_]+:)/.TP\n.B \1\n/' \
4e3126d
      -e 's/\[([^]]+)\]/\\fI[\1]\\fR/g' > out/%{name}.1
4e3126d
4e3126d
4e3126d
%install
4e3126d
install -d '%{buildroot}%{_bindir}'
4e3126d
install -t '%{buildroot}%{_bindir}' -p out/%{name}
4e3126d
4e3126d
install -d '%{buildroot}%{_datadir}/vim/vimfiles'
4e3126d
cp -vrp misc/vim/* '%{buildroot}%{_datadir}/vim/vimfiles'
d8a3fc5
find '%{buildroot}%{_datadir}/vim/vimfiles' \
d8a3fc5
    -type f -name 'README.*' -print -delete
4e3126d
%py_byte_compile %{__python3} '%{buildroot}%{_datadir}/vim/vimfiles/%{name}-format.py'
4e3126d
d7ddbd9
install -d '%{buildroot}%{_emacs_sitestartdir}'
d7ddbd9
install -t '%{buildroot}%{_emacs_sitestartdir}' -p -m 0644 misc/emacs/*.el
4e3126d
4e3126d
install -d '%{buildroot}%{_mandir}/man1'
4e3126d
install -t '%{buildroot}%{_mandir}/man1' -m 0644 -p out/%{name}.1
4e3126d
4e3126d
4e3126d
%check
4e3126d
out/gn_unittests
4e3126d
4e3126d
# Verify consistency of the version header with the spec file
4e3126d
grep -E '^#define[[:blank:]]+LAST_COMMIT_POSITION_NUM[[:blank:]]+'\
4e3126d
'%{version}[[:blank:]]*' \
4e3126d
    'out/last_commit_position.h' >/dev/null
4e3126d
grep -E '^#define[[:blank:]]+LAST_COMMIT_POSITION[[:blank:]]+'\
4e3126d
'"%{version} \(%{shortcommit}\)"[[:blank:]]*' \
4e3126d
    'out/last_commit_position.h' >/dev/null
4e3126d
4e3126d
4e3126d
%files
4e3126d
%license LICENSE
4e3126d
%{_bindir}/%{name}
4e3126d
4e3126d
%{_mandir}/man1/%{name}.1*
4e3126d
4e3126d
%{_datadir}/vim/vimfiles/%{name}-format.py
4e3126d
%{_datadir}/vim/vimfiles/autoload/%{name}.vim
4e3126d
%{_datadir}/vim/vimfiles/ftdetect/%{name}filetype.vim
4e3126d
%{_datadir}/vim/vimfiles/ftplugin/%{name}.vim
4e3126d
%{_datadir}/vim/vimfiles/syntax/%{name}.vim
4e3126d
4e3126d
%{_emacs_sitestartdir}/%{name}-mode.el
4e3126d
4e3126d
4e3126d
%files doc
4e3126d
%license LICENSE
4e3126d
%doc AUTHORS
4e3126d
%doc OWNERS
4e3126d
%doc README*.md
4e3126d
%if %{with html_docs}
4e3126d
%doc README*.html
4e3126d
%endif
4e3126d
%doc docs
4e3126d
%doc examples
4e3126d
%doc infra
4e3126d
%doc tools
4e3126d
4e3126d
4e3126d
%changelog
aade52c
%autochangelog