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
4abaaa9
#  7. Commit the changes
031473f
#
031473f
# See https://gn.googlesource.com/gn/+log for the latest changes.
5e56c1e
%global commit 693f9fb87e4febdd4299db9f73d8d2c958e63148
5e56c1e
%global access 20211018
4e3126d
%global shortcommit %(echo %{commit} | cut -b -8)
5e56c1e
Version:        1939
4abaaa9
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
f6a2627
URL:            https://gn.googlesource.com/gn
f6a2627
Source0:        %{url}/+archive/%{commit}.tar.gz#/gn-%{shortcommit}.tar.gz
4e3126d
# Generated using script update-version:
4e3126d
Source1:        last_commit_position.h
4e3126d
Source2:        update-version
4e3126d
dc005b0
# Clean up compiler warnings on gcc/g++. This patch is a rebased version of
dc005b0
# chromium-84.0.4147.105-gn-gcc-cleanup.patch from the chromium RPM; see:
dc005b0
#
dc005b0
#   https://src.fedoraproject.org/rpms/chromium/raw/
dc005b0
#     ce30313f5e4af121140c037bf026453355534f24/f/
dc005b0
#     chromium-84.0.4147.105-gn-gcc-cleanup.patch
f6a2627
Patch0:         gn-39a87c0b-gcc-cleanup.patch
25a26dd
# Stop overriding optimization flags
f6a2627
Patch1:         gn-0153d369-no-O3.patch
4e3126d
90f2d3a
BuildRequires:  python3
90f2d3a
BuildRequires:  python3-devel
4e3126d
BuildRequires:  ninja-build
4e3126d
BuildRequires:  gcc-c++
4e3126d
4e3126d
%if %{with html_docs}
4e3126d
BuildRequires:  pandoc
4e3126d
BuildRequires:  parallel
4e3126d
%endif
4e3126d
BuildRequires:  help2man
4e3126d
4e3126d
Requires:       vim-filesystem
90f2d3a
Requires:       python3
f6a2627
Provides:       vim-gn = %{version}-%{release}
4e3126d
4e3126d
BuildRequires:  emacs
4e3126d
Requires:       emacs-filesystem >= %{_emacs_version}
f6a2627
Provides:       emacs-gn = %{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
f6a2627
The gn-doc package contains detailed documentation for GN.
4e3126d
4e3126d
4e3126d
%prep
f6a2627
%autosetup -c -n gn-%{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
4e3126d
4e3126d
%build
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}' \
f6a2627
    --version-string="gn $(./out/gn --version)" \
4e3126d
    --no-info \
f6a2627
    ./out/gn |
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/' \
f6a2627
      -e 's/\[([^]]+)\]/\\fI[\1]\\fR/g' > out/gn.1
4e3126d
4e3126d
4e3126d
%install
f6a2627
install -t '%{buildroot}%{_bindir}' -D -p out/gn
4e3126d
4e3126d
install -d '%{buildroot}%{_datadir}/vim/vimfiles'
4e3126d
cp -vrp misc/vim/* '%{buildroot}%{_datadir}/vim/vimfiles'
ab3ecdc
find '%{buildroot}%{_datadir}/vim/vimfiles' \
cbd1c42
    -type f -name 'README.*' -print -delete
f6a2627
%py_byte_compile %{__python3} '%{buildroot}%{_datadir}/vim/vimfiles/gn-format.py'
4e3126d
90f2d3a
install -t '%{buildroot}%{_emacs_sitestartdir}' -D -p -m 0644 misc/emacs/*.el
4e3126d
f6a2627
install -t '%{buildroot}%{_mandir}/man1' -D -m 0644 -p out/gn.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
f6a2627
%{_bindir}/gn
4e3126d
f6a2627
%{_mandir}/man1/gn.1*
4e3126d
f6a2627
%{_datadir}/vim/vimfiles/gn-format.py
f6a2627
%{_datadir}/vim/vimfiles/autoload/gn.vim
f6a2627
%{_datadir}/vim/vimfiles/ftdetect/gnfiletype.vim
f6a2627
%{_datadir}/vim/vimfiles/ftplugin/gn.vim
f6a2627
%{_datadir}/vim/vimfiles/syntax/gn.vim
4e3126d
f6a2627
%{_emacs_sitestartdir}/gn-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
4abaaa9
%autochangelog