[gobject-introspection/wip/jtojnar/glib-subproject] Use glib subproject to generate the GIR files




commit 7e7bdab6f4ee67e04fccf542ea72f3084d28e997
Author: Jan Tojnar <jtojnar gmail com>
Date:   Thu Sep 23 17:13:17 2021 +0200

    Use glib subproject to generate the GIR files
    
    Previously, we included C files with documentation comments extracted from GLib libraries
    in the repository to make it self-contained. Unfortunately, that obscured the source file names,
    leading to incorrect links in the generated documentation.
    
    Since we switched to Meson, we can just use subprojects and the build system will handle it for us.

 .gitlab-ci.yml                  |     5 +
 .gitlab-ci/test-msys2-meson.sh  |     1 +
 gir/gio-2.0.c                   | 43896 --------------------------------------
 gir/glib-2.0.c                  | 42618 ------------------------------------
 gir/gmodule-2.0.c               |   289 -
 gir/gobject-2.0.c               |  7336 -------
 gir/meson.build                 |    97 +-
 meson.build                     |     2 +
 misc/update-glib-annotations.py |    90 -
 9 files changed, 53 insertions(+), 94281 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5f455f50..2c9ff68e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -16,6 +16,7 @@ example-meson:
   variables:
     EXTRA_MESON_FLAGS: "-Ddoctool=enabled -Dgtk_doc=true"
   script:
+    - meson subprojects download glib
     - meson setup ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} _build .
     - meson compile -C _build
     - sudo meson install -C _build
@@ -35,6 +36,7 @@ example-autotools:
   variables:
     EXTRA_MESON_FLAGS: "-Ddoctool=enabled -Dgtk_doc=true"
   script:
+    - meson subprojects download glib
     - meson setup ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} _build .
     - meson compile -C _build
     - sudo meson install -C _build
@@ -52,6 +54,7 @@ fedora-x86_64-meson:
     CCACHE_DIR: "${CI_PROJECT_DIR}/_ccache"
     EXTRA_MESON_FLAGS: "-Ddoctool=enabled -Dgtk_doc=true -Dwerror=true"
   script:
+    - meson subprojects download glib
     - meson setup ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} _build .
     - meson compile -C _build
     - meson test -C _build --print-errorlogs --suite=gobject-introspection --no-suite=glib
@@ -96,6 +99,7 @@ fedora-x86_64-no-introspection-data:
     CCACHE_DIR: "${CI_PROJECT_DIR}/_ccache"
     EXTRA_MESON_FLAGS: "-Dwerror=true"
   script:
+    - meson subprojects download glib
     - meson setup ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} _build .
     - meson compile -C _build
     - meson test -C _build --print-errorlogs --suite=gobject-introspection --no-suite=glib
@@ -115,6 +119,7 @@ fedora-x86_64-python3.6:
     CCACHE_DIR: "${CI_PROJECT_DIR}/_ccache"
     PYENV_VERSION: "3.6.12"
   script:
+    - meson subprojects download glib
     - meson setup ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} _build .
     - meson compile -C _build
     - meson test -C _build --print-errorlogs --suite=gobject-introspection --no-suite=glib
diff --git a/.gitlab-ci/test-msys2-meson.sh b/.gitlab-ci/test-msys2-meson.sh
index ead7bf7b..47ded3d1 100644
--- a/.gitlab-ci/test-msys2-meson.sh
+++ b/.gitlab-ci/test-msys2-meson.sh
@@ -33,6 +33,7 @@ export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache"
 pip3 install --upgrade --user meson==0.55.3 flake8 mypy==0.790
 export PATH="$HOME/.local/bin:$PATH"
 
+meson subprojects download glib
 export CFLAGS="-Werror"
 meson -Dcairo=enabled -Ddoctool=enabled --buildtype debug _build
 cd _build
diff --git a/gir/meson.build b/gir/meson.build
index 5d646335..dcf65e72 100644
--- a/gir/meson.build
+++ b/gir/meson.build
@@ -52,12 +52,12 @@ scanner_command = [
 ]
 
 dep_type = glib_dep.type_name()
+# XXX: Instead of hard-coding the subproject directory, we should use
+# gnome.generate_gir() because that will take care of dependencies, include
+# paths, library paths, and more that we now have to handle manually when
+# building with subprojects.
+subprojdir = 'subprojects'
 if dep_type == 'internal'
-  # XXX: Instead of hard-coding the subproject directory, we should use
-  # gnome.generate_gir() because that will take care of dependencies, include
-  # paths, library paths, and more that we now have to handle manually when
-  # building with subprojects.
-  subprojdir = 'subprojects'
   scanner_command += [
     '--extra-library=glib-2.0',
     '--extra-library=gmodule-2.0',
@@ -96,6 +96,33 @@ glib_command = scanner_command + [
   '--library=gobject-2.0',
 ]
 
+glib_srcdir = get_option('glib_src_dir')
+if dep_type == 'internal'
+  # XXX: This is a pile of hacks to allow gobject-introspection to parse the
+  #      GLib source files when GLib is used as a subproject
+  #      Assumes the location of the glib subproject dir
+  #      We should add API to meson to get a specific file from a specific
+  #      subproject
+  glib_subproject = subproject('glib')
+
+  glibproj_sourcedir = join_paths(meson.source_root(), subprojdir, 'glib')
+  glibproj_builddir = join_paths(meson.build_root(), subprojdir, 'glib')
+endif
+
+if glib_srcdir == ''
+  if dep_type == 'pkgconfig'
+    # Cannot use subproject directly, or Meson will try to “configure” it.
+    glib_srcdir = join_paths(meson.source_root(), subprojdir, 'glib')
+    if not fs.is_dir(glib_srcdir)
+      error('Missing glib subproject required for generating glib GIR files. Either download it, or specify 
path to source code using glib_src_dir Meson option.')
+    endif
+  elif dep_type == 'internal'
+    glib_srcdir = glibproj_sourcedir
+  else
+    error('Unknown glib dependency type: ' + dep_type)
+  endif
+endif
+
 if dep_type == 'pkgconfig'
   glib_command += ['--external-library', '--pkg=glib-2.0']
   glib_libdir = get_option('gi_cross_pkgconfig_sysroot_path') + glib_dep.get_pkgconfig_variable('libdir')
@@ -113,14 +140,11 @@ if dep_type == 'pkgconfig'
   endif
   glib_headers = ret.stdout().strip().split('\n')
   # Get a list of all source files
-  glib_srcdir = get_option('glib_src_dir')
-  if glib_srcdir != ''
-    ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'glib', '*.c')))
-    if ret.returncode() != 0
-      error('Failed to get glib source list')
-    endif
-    glib_files += ret.stdout().strip().split('\n')
+  ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'glib', '*.c')))
+  if ret.returncode() != 0
+    error('Failed to get glib source list')
   endif
+  glib_files += ret.stdout().strip().split('\n')
   glib_includes = ['-I' + glib_incdir, '-I' + glib_libincdir]
   glib_gir_dep = []
 elif dep_type == 'internal'
@@ -131,11 +155,6 @@ elif dep_type == 'internal'
   #      We should add API to meson to get a specific file from a specific
   #      subproject
   # We know exactly what headers will be installed, so just fetch that
-  glib_subproject = subproject('glib')
-
-  glibproj_sourcedir = join_paths(meson.source_root(), subprojdir, 'glib')
-  glibproj_builddir = join_paths(meson.build_root(), subprojdir, 'glib')
-
   glib_files += join_paths(glibproj_sourcedir, 'gobject', 'glib-types.h')
 
   # Generated files, relative to the build directory
@@ -211,11 +230,6 @@ foreach h : glib_headers
   endif
 endforeach
 
-# NOTE: Always add this last so that we prefer the annotations in the sources
-# (if they are available) since it contains 'backup' annotations that can be
-# out of date.
-glib_files += files('glib-2.0.c')
-
 gir_giscanner_pymod = []
 gir_giscanner_built_files = []
 if not get_option('gi_cross_use_prebuilt_gi')
@@ -262,13 +276,11 @@ if dep_type == 'pkgconfig'
     error('Failed to get gobject header list')
   endif
   gobject_headers = ret.stdout().strip().split('\n')
-  if glib_srcdir != ''
-    ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'gobject', '*.c')))
-    if ret.returncode() != 0
-      error('Failed to get gobject source list')
-    endif
-    gobject_files += ret.stdout().strip().split('\n')
+  ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'gobject', '*.c')))
+  if ret.returncode() != 0
+    error('Failed to get gobject source list')
   endif
+  gobject_files += ret.stdout().strip().split('\n')
   gobject_gir_dep = []
 else
   gobject_command += ['--pkg-export=gobject-2.0']
@@ -287,11 +299,6 @@ foreach h : gobject_headers
   endif
 endforeach
 
-# NOTE: Always add this last so that we prefer the annotations in the sources
-# (if they are available) since it contains 'backup' annotations that can be
-# out of date.
-gobject_files += files('gobject-2.0.c')
-
 gobject_gir = custom_target('gir-gobject',
   input: gobject_files,
   output: 'GObject-2.0.gir',
@@ -324,9 +331,7 @@ gmodule_command = scanner_command + [
 if dep_type == 'pkgconfig'
   gmodule_command += ['--external-library', '--pkg=gmodule-2.0']
   gmodule_files += join_paths(glib_incdir, 'gmodule.h')
-  if glib_srcdir != ''
-    gmodule_files += join_paths(glib_srcdir, 'gmodule', 'gmodule.c')
-  endif
+  gmodule_files += join_paths(glib_srcdir, 'gmodule', 'gmodule.c')
   gmodule_gir_dep = []
 else
   gmodule_command += ['--pkg-export=gmodule-2.0']
@@ -339,11 +344,6 @@ else
   gmodule_gir_dep = glib_subproject.get_variable('libgmodule')
 endif
 
-# NOTE: Always add this last so that we prefer the annotations in the sources
-# (if they are available) since it contains 'backup' annotations that can be
-# out of date.
-gmodule_files += files('gmodule-2.0.c')
-
 gir_files += custom_target('gir-gmodule',
   input: gmodule_files,
   output: 'GModule-2.0.gir',
@@ -381,13 +381,11 @@ if dep_type == 'pkgconfig'
   # Get all gio (and gio-unix) sources. This is not entirely correct, but it's
   # probably fine since it matches what Autotools does. We are more exact in
   # the subproject case.
-  if glib_srcdir != ''
-    ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'gio', '*.c')))
-    if ret.returncode() != 0
-      error('Failed to get gio source list')
-    endif
-    gio_files += ret.stdout().strip().split('\n')
+  ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'gio', '*.c')))
+  if ret.returncode() != 0
+    error('Failed to get gio source list')
   endif
+  gio_files += ret.stdout().strip().split('\n')
   gio_gir_dep = []
 else
   gio_command += ['--pkg-export=gio-2.0']
@@ -434,11 +432,6 @@ if giounix_dep.found()
   endforeach
 endif
 
-# NOTE: Always add this last so that we prefer the annotations in the sources
-# (if they are available) since it contains 'backup' annotations that can be
-# out of date.
-gio_files += files('gio-2.0.c')
-
 gio_gir = custom_target('gir-gio',
   input: gio_files,
   output: 'Gio-2.0.gir',
diff --git a/meson.build b/meson.build
index 79532462..c3d64bd4 100644
--- a/meson.build
+++ b/meson.build
@@ -17,6 +17,8 @@ configinc = include_directories('.')
 pymod = import('python')
 python = pymod.find_installation(get_option('python'))
 
+fs = import('fs')
+
 python_version = python.language_version()
 python_version_req = '>=3.6'
 if not python_version.version_compare(python_version_req)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]