build: improve portability of git-version.h gen
authorJohn Marshall <jtm.home@gmail.com>
Tue, 2 Jun 2020 16:01:21 +0000 (17:01 +0100)
committerJohn Marshall <jtm.home@gmail.com>
Thu, 25 Jun 2020 07:06:46 +0000 (08:06 +0100)
- use git to check if building from a git repo
- remove dependency on test program

babl/meson.build
meson.build

index 37d2e4d77e46b3b92fdb402d9a7bdf50d32e5fc0..c9f62ce33ca461cc1fda8a5bc7474f0e47da43bf 100644 (file)
@@ -57,13 +57,11 @@ babl_version_h = configure_file(
 # already exists because then we are probably working with a tarball
 # in which case the git-version.h we ship is correct.
 
-is_git_repo = (
-  test_bin.found() and
-  git_bin.found() and
-  run_command(test_bin, '-d', meson.source_root() / '.git').returncode() == 0
-)
-
-if is_git_repo
+if git_bin.found() and run_command(
+    git_bin,
+    'rev-parse',
+    '--is-inside-work-tree',
+).returncode() == 0
   git_version_h = vcs_tag(
     input : 'git-version.h.in',
     output: 'git-version.h',
@@ -71,18 +69,18 @@ if is_git_repo
     command: [ git_bin.path(), 'describe', '--always' ],
   )
 
-  meson.add_dist_script(
-    [ 'ninja', 'babl/git-version.h', ],
-  )
-  meson.add_dist_script(
-    [ 'sh', '-c', ' '.join(
-    [ 'cp', git_version_h.full_path(), '${MESON_DIST_ROOT}/babl' ]
-    )]
-  )
-
+  if env_bin.found()
+    meson.add_dist_script(
+      [ 'ninja', 'babl/git-version.h', ],
+    )
+    meson.add_dist_script(
+      [ 'sh', '-c', ' '.join(
+      [ 'cp', git_version_h.full_path(), '${MESON_DIST_ROOT}/babl' ]
+      )]
+    )
+  endif
 else
   git_version_h = files('git-version.h')
-
 endif
 
 babl_sources = [
index db5960e06dca3250828d77eb37b08de3e8ea97c4..4b40419d8a4b3d8c0acf482102b6e80ef2ab94c2 100644 (file)
@@ -346,7 +346,6 @@ env_bin = find_program('env', required: false, native: true)
 git_bin = find_program('git', required: false, native: true)
 rsvg_convert_bin = find_program('rsvg-convert', required: false,
   native: true)
-test_bin = find_program('test', required: false, native: true)
 w3m_bin = find_program('w3m', required: false, native: true)
 
 ################################################################################