4e3126d
# Build HTML docs from markdown using pandoc?
cfa8883
%bcond html_docs 1
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.
3de3640
%global commit 0a2b8eac80f164f10b2cbc126890db0d295790cd
3de3640
%global access 20240216
de7ba8f
%global shortcommit %(c='%{commit}'; echo "${c:0:12}")
3de3640
%global position 2146
d1b021e
Version:        %{position}^%{access}git%{shortcommit}
d1b021e
Release:        %autorelease
4e3126d
Summary:        Meta-build system that generates build files for Ninja
4e3126d
25c56d5
# The entire source is BSD-3-Clause, except:
25c56d5
#   - src/base/third_party/icu/ is (Unicode AND ICU); see
25c56d5
#     src/base/third_party/icu/LICENSE and also the header comment in
25c56d5
#     src/base/third_party/icu/icu_utf.h.
4e3126d
#
25c56d5
# Note that src/util/test/gn_test.cc, which is licensed Apache-2.0, does not
25c56d5
# contribute to the binary RPMs, only to the gn_unittests executable, which is
25c56d5
# not installed; you may verify this with:
4e3126d
#   gdb -ex 'set pagination off' -ex 'info sources' gn | grep -F gn_test.cc
0d83bbc
License:        BSD-3-Clause AND Unicode AND ICU
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
4b9e5ec
# Stop overriding optimization flags; not sent upstream because this is
4b9e5ec
# intentional on their part
fade8c2
Patch:          gn-0153d369-no-O3.patch
4e3126d
944c0d5
# https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval
944c0d5
ExcludeArch:    %{ix86}
944c0d5
90f2d3a
BuildRequires:  python3-devel
4e3126d
BuildRequires:  ninja-build
4e3126d
BuildRequires:  gcc-c++
4e3126d
070c4e5
# For RPM macros:
070c4e5
BuildRequires:  emacs-common
070c4e5
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
Requires:       emacs-filesystem >= %{_emacs_version}
f6a2627
Provides:       emacs-gn = %{version}-%{release}
4e3126d
6bf1caa
# src/base/third_party/icu/icu_utf.h:
6bf1caa
#
6bf1caa
#   This file has the relevant components from ICU copied to handle basic
6bf1caa
#   UTF8/16/32 conversions. Components are copied from umachine.h, utf.h,
6bf1caa
#   utf8.h, and utf16.h into icu_utf.h.
6bf1caa
#
6bf1caa
# The forked, bundled ICU components are copied from Chromium. Because of the
6bf1caa
# downstream changes (primarily, changing namespaces and symbol prefixes),
6bf1caa
# there is no clear path to unbundling.
6bf1caa
#
6bf1caa
# See src/base/third_party/icu/README.chromium, from which the version number
6bf1caa
# is taken.
6bf1caa
Provides:       bundled(icu) = 60
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
48d8421
# Treating warnings as errors is too strict for downstream builds.
48d8421
#
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.
4773f3c
%{python3} build/gen.py \
48d8421
    --allow-warnings \
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
4773f3c
%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:]]+'\
d1b021e
'%{position}[[:blank:]]*' \
4e3126d
    'out/last_commit_position.h' >/dev/null
4e3126d
grep -E '^#define[[:blank:]]+LAST_COMMIT_POSITION[[:blank:]]+'\
d1b021e
'"%{position} \(%{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
6bf1caa
%license LICENSE src/base/third_party/icu/README.chromium
4e3126d
%doc AUTHORS
4e3126d
%doc OWNERS
4e3126d
%doc README*.md
4e3126d
%if %{with html_docs}
4e3126d
%doc README*.html
4e3126d
%endif
d186d1e
%doc docs/
d186d1e
%doc examples/
d186d1e
%doc infra/
d186d1e
%doc tools/
4e3126d
4e3126d
4e3126d
%changelog
4abaaa9
%autochangelog