diff mbox series

[PULL,18/22] meson: Move the detection logic for sphinx to meson

Message ID 20201016114814.1564523-19-pbonzini@redhat.com
State New
Headers show
Series Build system + misc changes for 2020-10-16 | expand

Commit Message

Paolo Bonzini Oct. 16, 2020, 11:48 a.m. UTC
From: Yonggang Luo <luoyonggang@gmail.com>

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Message-Id: <20201015220626.418-4-luoyonggang@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 configure         | 59 ++++-------------------------------------------
 docs/meson.build  | 46 ++++++++++++++++++++++++++++++++++++
 meson.build       | 30 ++++++++----------------
 meson_options.txt |  4 ++++
 4 files changed, 64 insertions(+), 75 deletions(-)

Comments

罗勇刚(Yonggang Luo) Oct. 16, 2020, 1:27 p.m. UTC | #1
On Fri, Oct 16, 2020 at 7:48 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> From: Yonggang Luo <luoyonggang@gmail.com>
>
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> Message-Id: <20201015220626.418-4-luoyonggang@gmail.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  configure         | 59 ++++-------------------------------------------
>  docs/meson.build  | 46 ++++++++++++++++++++++++++++++++++++
>  meson.build       | 30 ++++++++----------------
>  meson_options.txt |  4 ++++
>  4 files changed, 64 insertions(+), 75 deletions(-)
>
> diff --git a/configure b/configure
> index 3edbdd2a24..68f097861d 100755
> --- a/configure
> +++ b/configure
> @@ -297,7 +297,7 @@ brlapi=""
>  curl=""
>  iconv="auto"
>  curses="auto"
> -docs=""
> +docs="auto"
>  fdt="auto"
>  netmap="no"
>  sdl="auto"
> @@ -820,15 +820,6 @@ do
>      fi
>  done
>
> -sphinx_build=
> -for binary in sphinx-build-3 sphinx-build
> -do
> -    if has "$binary"
> -    then
> -        sphinx_build=$(command -v "$binary")
> -        break
> -    fi
> -done
>
>  # Check for ancillary tools used in testing
>  genisoimage=
> @@ -1228,9 +1219,9 @@ for opt do
>    ;;
>    --disable-crypto-afalg) crypto_afalg="no"
>    ;;
> -  --disable-docs) docs="no"
> +  --disable-docs) docs="disabled"
>    ;;
> -  --enable-docs) docs="yes"
> +  --enable-docs) docs="enabled"
>    ;;
>    --disable-vhost-net) vhost_net="no"
>    ;;
> @@ -4419,45 +4410,6 @@ if check_include linux/btrfs.h ; then
>      btrfs=yes
>  fi
>
> -# If we're making warnings fatal, apply this to Sphinx runs as well
> -sphinx_werror=""
> -if test "$werror" = "yes"; then
> -    sphinx_werror="-W"
> -fi
> -
> -# Check we have a new enough version of sphinx-build
> -has_sphinx_build() {
> -    # This is a bit awkward but works: create a trivial document and
> -    # try to run it with our configuration file (which enforces a
> -    # version requirement). This will fail if either
> -    # sphinx-build doesn't exist at all or if it is too old.
> -    mkdir -p "$TMPDIR1/sphinx"
> -    touch "$TMPDIR1/sphinx/index.rst"
> -    "$sphinx_build" $sphinx_werror -c "$source_path/docs" \
> -                    -b html "$TMPDIR1/sphinx" \
> -                    "$TMPDIR1/sphinx/out"  >> config.log 2>&1
> -}
> -
> -# Check if tools are available to build documentation.
> -if test "$docs" != "no" ; then
> -  if has_sphinx_build; then
> -    sphinx_ok=yes
> -  else
> -    sphinx_ok=no
> -  fi
> -  if test "$sphinx_ok" = "yes"; then
> -    docs=yes
> -  else
> -    if test "$docs" = "yes" ; then
> -      if has $sphinx_build && test "$sphinx_ok" != "yes"; then
> -        echo "Warning: $sphinx_build exists but it is either too old or
uses too old a Python version" >&2
> -      fi
> -      feature_not_found "docs" "Install a Python 3 version of
python-sphinx"
> -    fi
> -    docs=no
> -  fi
> -fi
> -
>  # Search for bswap_32 function
>  byteswap_h=no
>  cat > $TMPC << EOF
> @@ -6093,9 +6045,6 @@ qemu_version=$(head $source_path/VERSION)
>  echo "PKGVERSION=$pkgversion" >>$config_host_mak
>  echo "SRC_PATH=$source_path" >> $config_host_mak
>  echo "TARGET_DIRS=$target_list" >> $config_host_mak
> -if [ "$docs" = "yes" ] ; then
> -  echo "BUILD_DOCS=yes" >> $config_host_mak
> -fi
>  if test "$modules" = "yes"; then
>    # $shacmd can generate a hash started with digit, which the compiler
doesn't
>    # like as an symbol. So prefix it with an underscore
> @@ -6784,7 +6733,6 @@ fi
>  echo "ROMS=$roms" >> $config_host_mak
>  echo "MAKE=$make" >> $config_host_mak
>  echo "PYTHON=$python" >> $config_host_mak
> -echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
>  echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
>  echo "MESON=$meson" >> $config_host_mak
>  echo "NINJA=$ninja" >> $config_host_mak
> @@ -7066,6 +7014,7 @@ NINJA=$ninja $meson setup \
>          -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
>          -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
>          -Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\
> +        -Ddocs=$docs -Dsphinx_build=$sphinx_build \
>          $cross_arg \
>          "$PWD" "$source_path"
>
> diff --git a/docs/meson.build b/docs/meson.build
> index 0340d489ac..789dca8cc0 100644
> --- a/docs/meson.build
> +++ b/docs/meson.build
> @@ -1,4 +1,50 @@

> +if get_option('sphinx_build') == ''
> +  sphinx_build = find_program(['sphinx-build-3', 'sphinx-build'],
> +                              required: get_option('docs'))
> +else
> +  sphinx_build = find_program(get_option('sphinx_build'),
> +                              required: get_option('docs'))
> +endif
> +
> +# Check if tools are available to build documentation.
> +build_docs = false
> +if sphinx_build.found()
> +  SPHINX_ARGS = [sphinx_build]
> +  # If we're making warnings fatal, apply this to Sphinx runs as well
> +  if get_option('werror')
> +    SPHINX_ARGS += [ '-W' ]
> +  endif
> +
> +  # This is a bit awkward but works: create a trivial document and
> +  # try to run it with our configuration file (which enforces a
> +  # version requirement). This will fail if sphinx-build is too old.
> +  run_command('mkdir', ['-p', tmpdir / 'sphinx'])
> +  run_command('touch', [tmpdir / 'sphinx/index.rst'])
> +  sphinx_build_test_out = run_command(SPHINX_ARGS + [
> +    '-c', meson.current_source_dir(),
> +    '-b', 'html', tmpdir / 'sphinx',
> +    tmpdir / 'sphinx/out'])
> +  build_docs = (sphinx_build_test_out.returncode() == 0)
> +
> +  if not build_docs
> +    warning('@0@ exists but it is either too old or uses too old a
Python version'.format(sphinx_build_option))
Here need to be get_option('sphinx_build')




> +    if get_option('docs').enabled()
> +      error('Install a Python 3 version of python-sphinx')
> +    endif
> +  endif
> +endif
> +
>  if build_docs
> +  SPHINX_ARGS += ['-Dversion=' + meson.project_version(), '-Drelease=' +
config_host['PKGVERSION']]
> +
> +  sphinx_extn_depends = [ meson.source_root() / 'docs/sphinx/depfile.py',
> +                          meson.source_root() / 'docs/sphinx/hxtool.py',
> +                          meson.source_root() /
'docs/sphinx/kerneldoc.py',
> +                          meson.source_root() /
'docs/sphinx/kernellog.py',
> +                          meson.source_root() / 'docs/sphinx/qapidoc.py',
> +                          meson.source_root() /
'docs/sphinx/qmp_lexer.py',
> +                          qapi_gen_depends ]
> +
>    configure_file(output: 'index.html',
>                   input: files('index.html.in'),
>                   configuration: {'VERSION': meson.project_version()},
> diff --git a/meson.build b/meson.build
> index 15732f4701..05fb59a00b 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -17,7 +17,13 @@ cc = meson.get_compiler('c')
>  config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
>  enable_modules = 'CONFIG_MODULES' in config_host
>  enable_static = 'CONFIG_STATIC' in config_host
> -build_docs = 'BUILD_DOCS' in config_host
> +
> +# Temporary directory used for files created while
> +# configure runs. Since it is in the build directory
> +# we can safely blow away any previous version of it
> +# (and we need not jump through hoops to try to delete
> +# it when configure exits.)
> +tmpdir = meson.current_build_dir() / 'meson-private/temp'
>
>  if get_option('qemu_suffix').startswith('/')
>    error('qemu_suffix cannot start with a /')
> @@ -1266,22 +1272,6 @@ foreach d : hx_headers
>  endforeach
>  genh += hxdep
>
> -SPHINX_ARGS = [config_host['SPHINX_BUILD'],
> -               '-Dversion=' + meson.project_version(),
> -               '-Drelease=' + config_host['PKGVERSION']]
> -
> -if get_option('werror')
> -  SPHINX_ARGS += [ '-W' ]
> -endif
> -
> -sphinx_extn_depends = [ meson.source_root() / 'docs/sphinx/depfile.py',
> -                        meson.source_root() / 'docs/sphinx/hxtool.py',
> -                        meson.source_root() / 'docs/sphinx/kerneldoc.py',
> -                        meson.source_root() / 'docs/sphinx/kernellog.py',
> -                        meson.source_root() / 'docs/sphinx/qapidoc.py',
> -                        meson.source_root() / 'docs/sphinx/qmp_lexer.py',
> -                        qapi_gen_depends ]
> -
>  ###################
>  # Collect sources #
>  ###################
> @@ -1866,8 +1856,8 @@ endif
>  subdir('scripts')
>  subdir('tools')
>  subdir('pc-bios')
> -subdir('tests')
>  subdir('docs')
> +subdir('tests')
>  if 'CONFIG_GTK' in config_host
>    subdir('po')
>  endif
> @@ -1949,7 +1939,7 @@ summary_info += {'QEMU_CFLAGS':
config_host['QEMU_CFLAGS']}
>  summary_info += {'QEMU_LDFLAGS':      config_host['QEMU_LDFLAGS']}
>  summary_info += {'make':              config_host['MAKE']}
>  summary_info += {'python':            '@0@ (version: @1@)'.format(python.full_path(),
python.language_version())}
> -summary_info += {'sphinx-build':      config_host['SPHINX_BUILD']}
> +summary_info += {'sphinx-build':      sphinx_build.found()}
>  summary_info += {'genisoimage':       config_host['GENISOIMAGE']}
>  # TODO: add back version
>  summary_info += {'slirp support':     slirp_opt == 'disabled' ? false :
slirp_opt}
> @@ -2017,7 +2007,7 @@ if config_host.has_key('CONFIG_XEN_BACKEND')
>    summary_info += {'xen ctrl version':
 config_host['CONFIG_XEN_CTRL_INTERFACE_VERSION']}
>  endif
>  summary_info += {'brlapi support':
 config_host.has_key('CONFIG_BRLAPI')}
> -summary_info += {'Documentation':     config_host.has_key('BUILD_DOCS')}
> +summary_info += {'Documentation':     build_docs}
>  summary_info += {'PIE':               get_option('b_pie')}
>  summary_info += {'vde support':       config_host.has_key('CONFIG_VDE')}
>  summary_info += {'netmap support':
 config_host.has_key('CONFIG_NETMAP')}
> diff --git a/meson_options.txt b/meson_options.txt
> index 77b3fabd00..967229b66e 100644
> --- a/meson_options.txt
> +++ b/meson_options.txt
> @@ -2,7 +2,11 @@ option('qemu_suffix', type : 'string', value: 'qemu',
>         description: 'Suffix for QEMU data/modules/config directories
(can be empty)')
>  option('docdir', type : 'string', value : 'doc',
>         description: 'Base directory for documentation installation (can
be empty)')
> +option('sphinx_build', type : 'string', value : '',
> +       description: 'Use specified sphinx-build [$sphinx_build] for
building document (default to be empty)')
>
> +option('docs', type : 'feature', value : 'auto',
> +       description: 'Documentations build support')
>  option('gettext', type : 'boolean', value : true,
>         description: 'Localization of the GTK+ user interface')
>  option('sparse', type : 'feature', value : 'auto',
> --
> 2.26.2
>
>


--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Fri, Oct 16, 2020 at 7:48 PM Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt; wrote:<br>&gt;<br>&gt; From: Yonggang Luo &lt;<a href="mailto:luoyonggang@gmail.com">luoyonggang@gmail.com</a>&gt;<br>&gt;<br>&gt; Signed-off-by: Yonggang Luo &lt;<a href="mailto:luoyonggang@gmail.com">luoyonggang@gmail.com</a>&gt;<br>&gt; Message-Id: &lt;<a href="mailto:20201015220626.418-4-luoyonggang@gmail.com">20201015220626.418-4-luoyonggang@gmail.com</a>&gt;<br>&gt; Signed-off-by: Paolo Bonzini &lt;<a href="mailto:pbonzini@redhat.com">pbonzini@redhat.com</a>&gt;<br>&gt; ---<br>&gt;  configure         | 59 ++++-------------------------------------------<br>&gt;  docs/meson.build  | 46 ++++++++++++++++++++++++++++++++++++<br>&gt;  meson.build       | 30 ++++++++----------------<br>&gt;  meson_options.txt |  4 ++++<br>&gt;  4 files changed, 64 insertions(+), 75 deletions(-)<br>&gt;<br>&gt; diff --git a/configure b/configure<br>&gt; index 3edbdd2a24..68f097861d 100755<br>&gt; --- a/configure<br>&gt; +++ b/configure<br>&gt; @@ -297,7 +297,7 @@ brlapi=&quot;&quot;<br>&gt;  curl=&quot;&quot;<br>&gt;  iconv=&quot;auto&quot;<br>&gt;  curses=&quot;auto&quot;<br>&gt; -docs=&quot;&quot;<br>&gt; +docs=&quot;auto&quot;<br>&gt;  fdt=&quot;auto&quot;<br>&gt;  netmap=&quot;no&quot;<br>&gt;  sdl=&quot;auto&quot;<br>&gt; @@ -820,15 +820,6 @@ do<br>&gt;      fi<br>&gt;  done<br>&gt;<br>&gt; -sphinx_build=<br>&gt; -for binary in sphinx-build-3 sphinx-build<br>&gt; -do<br>&gt; -    if has &quot;$binary&quot;<br>&gt; -    then<br>&gt; -        sphinx_build=$(command -v &quot;$binary&quot;)<br>&gt; -        break<br>&gt; -    fi<br>&gt; -done<br>&gt;<br>&gt;  # Check for ancillary tools used in testing<br>&gt;  genisoimage=<br>&gt; @@ -1228,9 +1219,9 @@ for opt do<br>&gt;    ;;<br>&gt;    --disable-crypto-afalg) crypto_afalg=&quot;no&quot;<br>&gt;    ;;<br>&gt; -  --disable-docs) docs=&quot;no&quot;<br>&gt; +  --disable-docs) docs=&quot;disabled&quot;<br>&gt;    ;;<br>&gt; -  --enable-docs) docs=&quot;yes&quot;<br>&gt; +  --enable-docs) docs=&quot;enabled&quot;<br>&gt;    ;;<br>&gt;    --disable-vhost-net) vhost_net=&quot;no&quot;<br>&gt;    ;;<br>&gt; @@ -4419,45 +4410,6 @@ if check_include linux/btrfs.h ; then<br>&gt;      btrfs=yes<br>&gt;  fi<br>&gt;<br>&gt; -# If we&#39;re making warnings fatal, apply this to Sphinx runs as well<br>&gt; -sphinx_werror=&quot;&quot;<br>&gt; -if test &quot;$werror&quot; = &quot;yes&quot;; then<br>&gt; -    sphinx_werror=&quot;-W&quot;<br>&gt; -fi<br>&gt; -<br>&gt; -# Check we have a new enough version of sphinx-build<br>&gt; -has_sphinx_build() {<br>&gt; -    # This is a bit awkward but works: create a trivial document and<br>&gt; -    # try to run it with our configuration file (which enforces a<br>&gt; -    # version requirement). This will fail if either<br>&gt; -    # sphinx-build doesn&#39;t exist at all or if it is too old.<br>&gt; -    mkdir -p &quot;$TMPDIR1/sphinx&quot;<br>&gt; -    touch &quot;$TMPDIR1/sphinx/index.rst&quot;<br>&gt; -    &quot;$sphinx_build&quot; $sphinx_werror -c &quot;$source_path/docs&quot; \<br>&gt; -                    -b html &quot;$TMPDIR1/sphinx&quot; \<br>&gt; -                    &quot;$TMPDIR1/sphinx/out&quot;  &gt;&gt; config.log 2&gt;&amp;1<br>&gt; -}<br>&gt; -<br>&gt; -# Check if tools are available to build documentation.<br>&gt; -if test &quot;$docs&quot; != &quot;no&quot; ; then<br>&gt; -  if has_sphinx_build; then<br>&gt; -    sphinx_ok=yes<br>&gt; -  else<br>&gt; -    sphinx_ok=no<br>&gt; -  fi<br>&gt; -  if test &quot;$sphinx_ok&quot; = &quot;yes&quot;; then<br>&gt; -    docs=yes<br>&gt; -  else<br>&gt; -    if test &quot;$docs&quot; = &quot;yes&quot; ; then<br>&gt; -      if has $sphinx_build &amp;&amp; test &quot;$sphinx_ok&quot; != &quot;yes&quot;; then<br>&gt; -        echo &quot;Warning: $sphinx_build exists but it is either too old or uses too old a Python version&quot; &gt;&amp;2<br>&gt; -      fi<br>&gt; -      feature_not_found &quot;docs&quot; &quot;Install a Python 3 version of python-sphinx&quot;<br>&gt; -    fi<br>&gt; -    docs=no<br>&gt; -  fi<br>&gt; -fi<br>&gt; -<br>&gt;  # Search for bswap_32 function<br>&gt;  byteswap_h=no<br>&gt;  cat &gt; $TMPC &lt;&lt; EOF<br>&gt; @@ -6093,9 +6045,6 @@ qemu_version=$(head $source_path/VERSION)<br>&gt;  echo &quot;PKGVERSION=$pkgversion&quot; &gt;&gt;$config_host_mak<br>&gt;  echo &quot;SRC_PATH=$source_path&quot; &gt;&gt; $config_host_mak<br>&gt;  echo &quot;TARGET_DIRS=$target_list&quot; &gt;&gt; $config_host_mak<br>&gt; -if [ &quot;$docs&quot; = &quot;yes&quot; ] ; then<br>&gt; -  echo &quot;BUILD_DOCS=yes&quot; &gt;&gt; $config_host_mak<br>&gt; -fi<br>&gt;  if test &quot;$modules&quot; = &quot;yes&quot;; then<br>&gt;    # $shacmd can generate a hash started with digit, which the compiler doesn&#39;t<br>&gt;    # like as an symbol. So prefix it with an underscore<br>&gt; @@ -6784,7 +6733,6 @@ fi<br>&gt;  echo &quot;ROMS=$roms&quot; &gt;&gt; $config_host_mak<br>&gt;  echo &quot;MAKE=$make&quot; &gt;&gt; $config_host_mak<br>&gt;  echo &quot;PYTHON=$python&quot; &gt;&gt; $config_host_mak<br>&gt; -echo &quot;SPHINX_BUILD=$sphinx_build&quot; &gt;&gt; $config_host_mak<br>&gt;  echo &quot;GENISOIMAGE=$genisoimage&quot; &gt;&gt; $config_host_mak<br>&gt;  echo &quot;MESON=$meson&quot; &gt;&gt; $config_host_mak<br>&gt;  echo &quot;NINJA=$ninja&quot; &gt;&gt; $config_host_mak<br>&gt; @@ -7066,6 +7014,7 @@ NINJA=$ninja $meson setup \<br>&gt;          -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \<br>&gt;          -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \<br>&gt;          -Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\<br>&gt; +        -Ddocs=$docs -Dsphinx_build=$sphinx_build \<br>&gt;          $cross_arg \<br>&gt;          &quot;$PWD&quot; &quot;$source_path&quot;<br>&gt;<br>&gt; diff --git a/docs/meson.build b/docs/meson.build<br>&gt; index 0340d489ac..789dca8cc0 100644<br>&gt; --- a/docs/meson.build<br>&gt; +++ b/docs/meson.build<br>&gt; @@ -1,4 +1,50 @@<div><br>&gt; +if get_option(&#39;sphinx_build&#39;) == &#39;&#39;<br>&gt; +  sphinx_build = find_program([&#39;sphinx-build-3&#39;, &#39;sphinx-build&#39;],<br>&gt; +                              required: get_option(&#39;docs&#39;))<br>&gt; +else<br>&gt; +  sphinx_build = find_program(get_option(&#39;sphinx_build&#39;),<br>&gt; +                              required: get_option(&#39;docs&#39;))<br>&gt; +endif<br>&gt; +<br>&gt; +# Check if tools are available to build documentation.<br>&gt; +build_docs = false<br>&gt; +if sphinx_build.found()<br>&gt; +  SPHINX_ARGS = [sphinx_build]<br>&gt; +  # If we&#39;re making warnings fatal, apply this to Sphinx runs as well<br>&gt; +  if get_option(&#39;werror&#39;)<br>&gt; +    SPHINX_ARGS += [ &#39;-W&#39; ]<br>&gt; +  endif<br>&gt; +<br>&gt; +  # This is a bit awkward but works: create a trivial document and<br>&gt; +  # try to run it with our configuration file (which enforces a<br>&gt; +  # version requirement). This will fail if sphinx-build is too old.<br>&gt; +  run_command(&#39;mkdir&#39;, [&#39;-p&#39;, tmpdir / &#39;sphinx&#39;])<br>&gt; +  run_command(&#39;touch&#39;, [tmpdir / &#39;sphinx/index.rst&#39;])<br>&gt; +  sphinx_build_test_out = run_command(SPHINX_ARGS + [<br>&gt; +    &#39;-c&#39;, meson.current_source_dir(),<br>&gt; +    &#39;-b&#39;, &#39;html&#39;, tmpdir / &#39;sphinx&#39;,<br>&gt; +    tmpdir / &#39;sphinx/out&#39;])<br>&gt; +  build_docs = (sphinx_build_test_out.returncode() == 0)<br>&gt; +<br>&gt; +  if not build_docs<br>&gt; +    warning(&#39;@0@ exists but it is either too old or uses too old a Python version&#39;.format(sphinx_build_option))<br>Here need to be

get_option(&#39;sphinx_build&#39;)

<br><br><br><br><br>&gt; +    if get_option(&#39;docs&#39;).enabled()<br>&gt; +      error(&#39;Install a Python 3 version of python-sphinx&#39;)<br>&gt; +    endif<br>&gt; +  endif<br>&gt; +endif<br>&gt; +<br>&gt;  if build_docs<br>&gt; +  SPHINX_ARGS += [&#39;-Dversion=&#39; + meson.project_version(), &#39;-Drelease=&#39; + config_host[&#39;PKGVERSION&#39;]]<br>&gt; +<br>&gt; +  sphinx_extn_depends = [ meson.source_root() / &#39;docs/sphinx/depfile.py&#39;,<br>&gt; +                          meson.source_root() / &#39;docs/sphinx/hxtool.py&#39;,<br>&gt; +                          meson.source_root() / &#39;docs/sphinx/kerneldoc.py&#39;,<br>&gt; +                          meson.source_root() / &#39;docs/sphinx/kernellog.py&#39;,<br>&gt; +                          meson.source_root() / &#39;docs/sphinx/qapidoc.py&#39;,<br>&gt; +                          meson.source_root() / &#39;docs/sphinx/qmp_lexer.py&#39;,<br>&gt; +                          qapi_gen_depends ]<br>&gt; +<br>&gt;    configure_file(output: &#39;index.html&#39;,<br>&gt;                   input: files(&#39;<a href="http://index.html.in">index.html.in</a>&#39;),<br>&gt;                   configuration: {&#39;VERSION&#39;: meson.project_version()},<br>&gt; diff --git a/meson.build b/meson.build<br>&gt; index 15732f4701..05fb59a00b 100644<br>&gt; --- a/meson.build<br>&gt; +++ b/meson.build<br>&gt; @@ -17,7 +17,13 @@ cc = meson.get_compiler(&#39;c&#39;)<br>&gt;  config_host = keyval.load(meson.current_build_dir() / &#39;config-host.mak&#39;)<br>&gt;  enable_modules = &#39;CONFIG_MODULES&#39; in config_host<br>&gt;  enable_static = &#39;CONFIG_STATIC&#39; in config_host<br>&gt; -build_docs = &#39;BUILD_DOCS&#39; in config_host<br>&gt; +<br>&gt; +# Temporary directory used for files created while<br>&gt; +# configure runs. Since it is in the build directory<br>&gt; +# we can safely blow away any previous version of it<br>&gt; +# (and we need not jump through hoops to try to delete<br>&gt; +# it when configure exits.)<br>&gt; +tmpdir = meson.current_build_dir() / &#39;meson-private/temp&#39;<br>&gt;<br>&gt;  if get_option(&#39;qemu_suffix&#39;).startswith(&#39;/&#39;)<br>&gt;    error(&#39;qemu_suffix cannot start with a /&#39;)<br>&gt; @@ -1266,22 +1272,6 @@ foreach d : hx_headers<br>&gt;  endforeach<br>&gt;  genh += hxdep<br>&gt;<br>&gt; -SPHINX_ARGS = [config_host[&#39;SPHINX_BUILD&#39;],<br>&gt; -               &#39;-Dversion=&#39; + meson.project_version(),<br>&gt; -               &#39;-Drelease=&#39; + config_host[&#39;PKGVERSION&#39;]]<br>&gt; -<br>&gt; -if get_option(&#39;werror&#39;)<br>&gt; -  SPHINX_ARGS += [ &#39;-W&#39; ]<br>&gt; -endif<br>&gt; -<br>&gt; -sphinx_extn_depends = [ meson.source_root() / &#39;docs/sphinx/depfile.py&#39;,<br>&gt; -                        meson.source_root() / &#39;docs/sphinx/hxtool.py&#39;,<br>&gt; -                        meson.source_root() / &#39;docs/sphinx/kerneldoc.py&#39;,<br>&gt; -                        meson.source_root() / &#39;docs/sphinx/kernellog.py&#39;,<br>&gt; -                        meson.source_root() / &#39;docs/sphinx/qapidoc.py&#39;,<br>&gt; -                        meson.source_root() / &#39;docs/sphinx/qmp_lexer.py&#39;,<br>&gt; -                        qapi_gen_depends ]<br>&gt; -<br>&gt;  ###################<br>&gt;  # Collect sources #<br>&gt;  ###################<br>&gt; @@ -1866,8 +1856,8 @@ endif<br>&gt;  subdir(&#39;scripts&#39;)<br>&gt;  subdir(&#39;tools&#39;)<br>&gt;  subdir(&#39;pc-bios&#39;)<br>&gt; -subdir(&#39;tests&#39;)<br>&gt;  subdir(&#39;docs&#39;)<br>&gt; +subdir(&#39;tests&#39;)<br>&gt;  if &#39;CONFIG_GTK&#39; in config_host<br>&gt;    subdir(&#39;po&#39;)<br>&gt;  endif<br>&gt; @@ -1949,7 +1939,7 @@ summary_info += {&#39;QEMU_CFLAGS&#39;:       config_host[&#39;QEMU_CFLAGS&#39;]}<br>&gt;  summary_info += {&#39;QEMU_LDFLAGS&#39;:      config_host[&#39;QEMU_LDFLAGS&#39;]}<br>&gt;  summary_info += {&#39;make&#39;:              config_host[&#39;MAKE&#39;]}<br>&gt;  summary_info += {&#39;python&#39;:            &#39;@0@ (version: @1@)&#39;.format(python.full_path(), python.language_version())}<br>&gt; -summary_info += {&#39;sphinx-build&#39;:      config_host[&#39;SPHINX_BUILD&#39;]}<br>&gt; +summary_info += {&#39;sphinx-build&#39;:      sphinx_build.found()}<br>&gt;  summary_info += {&#39;genisoimage&#39;:       config_host[&#39;GENISOIMAGE&#39;]}<br>&gt;  # TODO: add back version<br>&gt;  summary_info += {&#39;slirp support&#39;:     slirp_opt == &#39;disabled&#39; ? false : slirp_opt}<br>&gt; @@ -2017,7 +2007,7 @@ if config_host.has_key(&#39;CONFIG_XEN_BACKEND&#39;)<br>&gt;    summary_info += {&#39;xen ctrl version&#39;:  config_host[&#39;CONFIG_XEN_CTRL_INTERFACE_VERSION&#39;]}<br>&gt;  endif<br>&gt;  summary_info += {&#39;brlapi support&#39;:    config_host.has_key(&#39;CONFIG_BRLAPI&#39;)}<br>&gt; -summary_info += {&#39;Documentation&#39;:     config_host.has_key(&#39;BUILD_DOCS&#39;)}<br>&gt; +summary_info += {&#39;Documentation&#39;:     build_docs}<br>&gt;  summary_info += {&#39;PIE&#39;:               get_option(&#39;b_pie&#39;)}<br>&gt;  summary_info += {&#39;vde support&#39;:       config_host.has_key(&#39;CONFIG_VDE&#39;)}<br>&gt;  summary_info += {&#39;netmap support&#39;:    config_host.has_key(&#39;CONFIG_NETMAP&#39;)}<br>&gt; diff --git a/meson_options.txt b/meson_options.txt<br>&gt; index 77b3fabd00..967229b66e 100644<br>&gt; --- a/meson_options.txt<br>&gt; +++ b/meson_options.txt<br>&gt; @@ -2,7 +2,11 @@ option(&#39;qemu_suffix&#39;, type : &#39;string&#39;, value: &#39;qemu&#39;,<br>&gt;         description: &#39;Suffix for QEMU data/modules/config directories (can be empty)&#39;)<br>&gt;  option(&#39;docdir&#39;, type : &#39;string&#39;, value : &#39;doc&#39;,<br>&gt;         description: &#39;Base directory for documentation installation (can be empty)&#39;)<br>&gt; +option(&#39;sphinx_build&#39;, type : &#39;string&#39;, value : &#39;&#39;,<br>&gt; +       description: &#39;Use specified sphinx-build [$sphinx_build] for building document (default to be empty)&#39;)<br>&gt;<br>&gt; +option(&#39;docs&#39;, type : &#39;feature&#39;, value : &#39;auto&#39;,<br>&gt; +       description: &#39;Documentations build support&#39;)<br>&gt;  option(&#39;gettext&#39;, type : &#39;boolean&#39;, value : true,<br>&gt;         description: &#39;Localization of the GTK+ user interface&#39;)<br>&gt;  option(&#39;sparse&#39;, type : &#39;feature&#39;, value : &#39;auto&#39;,<br>&gt; --<br>&gt; 2.26.2<br>&gt;<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo<br></div></div>
Eric Blake Oct. 19, 2020, 7:40 p.m. UTC | #2
On 10/16/20 8:27 AM, 罗勇刚(Yonggang Luo) wrote:
> On Fri, Oct 16, 2020 at 7:48 PM Paolo Bonzini <pbonzini@redhat.com> wrote:

>>


Meta-comment.  Your quoting style leaves a lot to be desired:


>> -    if test "$docs" = "yes" ; then

>> -      if has $sphinx_build && test "$sphinx_ok" != "yes"; then

>> -        echo "Warning: $sphinx_build exists but it is either too old or

> uses too old a Python version" >&2

>> -      fi

>> -      feature_not_found "docs" "Install a Python 3 version of

> python-sphinx"

>> -    fi


Here, your mailer wrapped lines but did not quote the wrapped portion, 
while...

>> +  if not build_docs

>> +    warning('@0@ exists but it is either too old or uses too old a

> Python version'.format(sphinx_build_option))

> Here need to be get_option('sphinx_build')


...here you added new content without any newline separator, right after 
another case of a mailer wrapping a line.  It makes it very difficult to 
decipher which text you are quoting and which text you are adding.

You may want to consider using a better mail engine that does not split 
quoted lines incorrectly, as well as using a blank line both before and 
after every block of your inline replies, to call more visual attention 
to what you are adding to the conversation.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
diff mbox series

Patch

diff --git a/configure b/configure
index 3edbdd2a24..68f097861d 100755
--- a/configure
+++ b/configure
@@ -297,7 +297,7 @@  brlapi=""
 curl=""
 iconv="auto"
 curses="auto"
-docs=""
+docs="auto"
 fdt="auto"
 netmap="no"
 sdl="auto"
@@ -820,15 +820,6 @@  do
     fi
 done
 
-sphinx_build=
-for binary in sphinx-build-3 sphinx-build
-do
-    if has "$binary"
-    then
-        sphinx_build=$(command -v "$binary")
-        break
-    fi
-done
 
 # Check for ancillary tools used in testing
 genisoimage=
@@ -1228,9 +1219,9 @@  for opt do
   ;;
   --disable-crypto-afalg) crypto_afalg="no"
   ;;
-  --disable-docs) docs="no"
+  --disable-docs) docs="disabled"
   ;;
-  --enable-docs) docs="yes"
+  --enable-docs) docs="enabled"
   ;;
   --disable-vhost-net) vhost_net="no"
   ;;
@@ -4419,45 +4410,6 @@  if check_include linux/btrfs.h ; then
     btrfs=yes
 fi
 
-# If we're making warnings fatal, apply this to Sphinx runs as well
-sphinx_werror=""
-if test "$werror" = "yes"; then
-    sphinx_werror="-W"
-fi
-
-# Check we have a new enough version of sphinx-build
-has_sphinx_build() {
-    # This is a bit awkward but works: create a trivial document and
-    # try to run it with our configuration file (which enforces a
-    # version requirement). This will fail if either
-    # sphinx-build doesn't exist at all or if it is too old.
-    mkdir -p "$TMPDIR1/sphinx"
-    touch "$TMPDIR1/sphinx/index.rst"
-    "$sphinx_build" $sphinx_werror -c "$source_path/docs" \
-                    -b html "$TMPDIR1/sphinx" \
-                    "$TMPDIR1/sphinx/out"  >> config.log 2>&1
-}
-
-# Check if tools are available to build documentation.
-if test "$docs" != "no" ; then
-  if has_sphinx_build; then
-    sphinx_ok=yes
-  else
-    sphinx_ok=no
-  fi
-  if test "$sphinx_ok" = "yes"; then
-    docs=yes
-  else
-    if test "$docs" = "yes" ; then
-      if has $sphinx_build && test "$sphinx_ok" != "yes"; then
-        echo "Warning: $sphinx_build exists but it is either too old or uses too old a Python version" >&2
-      fi
-      feature_not_found "docs" "Install a Python 3 version of python-sphinx"
-    fi
-    docs=no
-  fi
-fi
-
 # Search for bswap_32 function
 byteswap_h=no
 cat > $TMPC << EOF
@@ -6093,9 +6045,6 @@  qemu_version=$(head $source_path/VERSION)
 echo "PKGVERSION=$pkgversion" >>$config_host_mak
 echo "SRC_PATH=$source_path" >> $config_host_mak
 echo "TARGET_DIRS=$target_list" >> $config_host_mak
-if [ "$docs" = "yes" ] ; then
-  echo "BUILD_DOCS=yes" >> $config_host_mak
-fi
 if test "$modules" = "yes"; then
   # $shacmd can generate a hash started with digit, which the compiler doesn't
   # like as an symbol. So prefix it with an underscore
@@ -6784,7 +6733,6 @@  fi
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
 echo "PYTHON=$python" >> $config_host_mak
-echo "SPHINX_BUILD=$sphinx_build" >> $config_host_mak
 echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
 echo "MESON=$meson" >> $config_host_mak
 echo "NINJA=$ninja" >> $config_host_mak
@@ -7066,6 +7014,7 @@  NINJA=$ninja $meson setup \
         -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
         -Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
         -Diconv=$iconv -Dcurses=$curses -Dlibudev=$libudev\
+        -Ddocs=$docs -Dsphinx_build=$sphinx_build \
         $cross_arg \
         "$PWD" "$source_path"
 
diff --git a/docs/meson.build b/docs/meson.build
index 0340d489ac..789dca8cc0 100644
--- a/docs/meson.build
+++ b/docs/meson.build
@@ -1,4 +1,50 @@ 
+if get_option('sphinx_build') == ''
+  sphinx_build = find_program(['sphinx-build-3', 'sphinx-build'],
+                              required: get_option('docs'))
+else
+  sphinx_build = find_program(get_option('sphinx_build'),
+                              required: get_option('docs'))
+endif
+
+# Check if tools are available to build documentation.
+build_docs = false
+if sphinx_build.found()
+  SPHINX_ARGS = [sphinx_build]
+  # If we're making warnings fatal, apply this to Sphinx runs as well
+  if get_option('werror')
+    SPHINX_ARGS += [ '-W' ]
+  endif
+
+  # This is a bit awkward but works: create a trivial document and
+  # try to run it with our configuration file (which enforces a
+  # version requirement). This will fail if sphinx-build is too old.
+  run_command('mkdir', ['-p', tmpdir / 'sphinx'])
+  run_command('touch', [tmpdir / 'sphinx/index.rst'])
+  sphinx_build_test_out = run_command(SPHINX_ARGS + [
+    '-c', meson.current_source_dir(),
+    '-b', 'html', tmpdir / 'sphinx',
+    tmpdir / 'sphinx/out'])
+  build_docs = (sphinx_build_test_out.returncode() == 0)
+
+  if not build_docs
+    warning('@0@ exists but it is either too old or uses too old a Python version'.format(sphinx_build_option))
+    if get_option('docs').enabled()
+      error('Install a Python 3 version of python-sphinx')
+    endif
+  endif
+endif
+
 if build_docs
+  SPHINX_ARGS += ['-Dversion=' + meson.project_version(), '-Drelease=' + config_host['PKGVERSION']]
+
+  sphinx_extn_depends = [ meson.source_root() / 'docs/sphinx/depfile.py',
+                          meson.source_root() / 'docs/sphinx/hxtool.py',
+                          meson.source_root() / 'docs/sphinx/kerneldoc.py',
+                          meson.source_root() / 'docs/sphinx/kernellog.py',
+                          meson.source_root() / 'docs/sphinx/qapidoc.py',
+                          meson.source_root() / 'docs/sphinx/qmp_lexer.py',
+                          qapi_gen_depends ]
+
   configure_file(output: 'index.html',
                  input: files('index.html.in'),
                  configuration: {'VERSION': meson.project_version()},
diff --git a/meson.build b/meson.build
index 15732f4701..05fb59a00b 100644
--- a/meson.build
+++ b/meson.build
@@ -17,7 +17,13 @@  cc = meson.get_compiler('c')
 config_host = keyval.load(meson.current_build_dir() / 'config-host.mak')
 enable_modules = 'CONFIG_MODULES' in config_host
 enable_static = 'CONFIG_STATIC' in config_host
-build_docs = 'BUILD_DOCS' in config_host
+
+# Temporary directory used for files created while
+# configure runs. Since it is in the build directory
+# we can safely blow away any previous version of it
+# (and we need not jump through hoops to try to delete
+# it when configure exits.)
+tmpdir = meson.current_build_dir() / 'meson-private/temp'
 
 if get_option('qemu_suffix').startswith('/')
   error('qemu_suffix cannot start with a /')
@@ -1266,22 +1272,6 @@  foreach d : hx_headers
 endforeach
 genh += hxdep
 
-SPHINX_ARGS = [config_host['SPHINX_BUILD'],
-               '-Dversion=' + meson.project_version(),
-               '-Drelease=' + config_host['PKGVERSION']]
-
-if get_option('werror')
-  SPHINX_ARGS += [ '-W' ]
-endif
-
-sphinx_extn_depends = [ meson.source_root() / 'docs/sphinx/depfile.py',
-                        meson.source_root() / 'docs/sphinx/hxtool.py',
-                        meson.source_root() / 'docs/sphinx/kerneldoc.py',
-                        meson.source_root() / 'docs/sphinx/kernellog.py',
-                        meson.source_root() / 'docs/sphinx/qapidoc.py',
-                        meson.source_root() / 'docs/sphinx/qmp_lexer.py',
-                        qapi_gen_depends ]
-
 ###################
 # Collect sources #
 ###################
@@ -1866,8 +1856,8 @@  endif
 subdir('scripts')
 subdir('tools')
 subdir('pc-bios')
-subdir('tests')
 subdir('docs')
+subdir('tests')
 if 'CONFIG_GTK' in config_host
   subdir('po')
 endif
@@ -1949,7 +1939,7 @@  summary_info += {'QEMU_CFLAGS':       config_host['QEMU_CFLAGS']}
 summary_info += {'QEMU_LDFLAGS':      config_host['QEMU_LDFLAGS']}
 summary_info += {'make':              config_host['MAKE']}
 summary_info += {'python':            '@0@ (version: @1@)'.format(python.full_path(), python.language_version())}
-summary_info += {'sphinx-build':      config_host['SPHINX_BUILD']}
+summary_info += {'sphinx-build':      sphinx_build.found()}
 summary_info += {'genisoimage':       config_host['GENISOIMAGE']}
 # TODO: add back version
 summary_info += {'slirp support':     slirp_opt == 'disabled' ? false : slirp_opt}
@@ -2017,7 +2007,7 @@  if config_host.has_key('CONFIG_XEN_BACKEND')
   summary_info += {'xen ctrl version':  config_host['CONFIG_XEN_CTRL_INTERFACE_VERSION']}
 endif
 summary_info += {'brlapi support':    config_host.has_key('CONFIG_BRLAPI')}
-summary_info += {'Documentation':     config_host.has_key('BUILD_DOCS')}
+summary_info += {'Documentation':     build_docs}
 summary_info += {'PIE':               get_option('b_pie')}
 summary_info += {'vde support':       config_host.has_key('CONFIG_VDE')}
 summary_info += {'netmap support':    config_host.has_key('CONFIG_NETMAP')}
diff --git a/meson_options.txt b/meson_options.txt
index 77b3fabd00..967229b66e 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -2,7 +2,11 @@  option('qemu_suffix', type : 'string', value: 'qemu',
        description: 'Suffix for QEMU data/modules/config directories (can be empty)')
 option('docdir', type : 'string', value : 'doc',
        description: 'Base directory for documentation installation (can be empty)')
+option('sphinx_build', type : 'string', value : '',
+       description: 'Use specified sphinx-build [$sphinx_build] for building document (default to be empty)')
 
+option('docs', type : 'feature', value : 'auto',
+       description: 'Documentations build support')
 option('gettext', type : 'boolean', value : true,
        description: 'Localization of the GTK+ user interface')
 option('sparse', type : 'feature', value : 'auto',