meson: migrate ChangeLog generator to a proper build target
authorEli Schwartz <eschwartz93@gmail.com>
Wed, 19 Oct 2022 22:08:08 +0000 (18:08 -0400)
committerColin Clark <colin.clark@cclark.uk>
Thu, 20 Oct 2022 11:11:46 +0000 (12:11 +0100)
We still run the same script. But now it is run at build time, not
configure time, and Meson checks that it successfully ran -- it
really, really, really, should.

That is, assuming that git is installed and this is a git repo. If not,
we can simply refrain from running anything at all, instead of checking
the return code of gen_changelog.sh

meson.build

index a0aa694..475b679 100644 (file)
@@ -65,6 +65,7 @@ gnome = import('gnome')
 thread_dep = dependency('threads')
 cc = meson.get_compiler('c')
 i18n = import('i18n')
+fs = import('fs')
 configuration_inc = include_directories('.')
 
 # External programs
@@ -77,6 +78,8 @@ else
     summary({'help' : ['yelp-build not found - Help files created:', false]}, section : 'Documentation', bool_yn : true)
 endif
 
+running_from_git = find_program('git', required: false).found() and fs.is_dir('.git')
+
 debug = get_option('debug')
 
 # Note that main.cc sets prefix to the directory above where the executable is run from.
@@ -489,10 +492,14 @@ subdir('src')
 subdir('doc')
 
 # Install other project files
-res = run_command(find_program('gen_changelog.sh'), meson.source_root(), meson.build_root(), check : false)
-
-if res.returncode() == 0
-    install_data(join_paths(meson.build_root(), 'ChangeLog'), join_paths(meson.build_root(), 'ChangeLog.html'), install_dir : helpdir)
+if running_from_git
+    custom_target(
+        'ChangeLog',
+        input: 'ChangeLog.gqview',
+        output: ['ChangeLog', 'ChangeLog.html'],
+        command: [find_program('gen_changelog.sh'), meson.current_source_dir(), meson.current_build_dir()],
+        install: true,
+        install_dir: helpdir)
     summary({'ChangeLog' : ['ChangeLog, ChangeLog.html created:', true]}, section : 'Documentation', bool_yn : true)
 else
     summary({'ChangeLog' : ['ChangeLog, ChangeLog.html created:', false]}, section : 'Documentation', bool_yn : true)