[gtk/ebassi/rev-parse-fallback] build: Check CI envvars before rev-parse




commit 84293c50b7525f259d7ef387422a16307a242dcf
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon May 17 21:12:09 2021 +0100

    build: Check CI envvars before rev-parse
    
    The CI pipeline does not do a full clone, so we cannot use `git
    rev-parse` to get the short SHA checksum for the current commit.
    
    Of course, since nothing's ever easy, we cannot use vcs_tag() with a
    custom command, so we need to generate our out `demo_conf.h` header
    straight from a script.

 build-aux/meson/gen-demo-header.py | 24 ++++++++++++++++++++++++
 demos/meson.build                  | 18 ++++++------------
 2 files changed, 30 insertions(+), 12 deletions(-)
---
diff --git a/build-aux/meson/gen-demo-header.py b/build-aux/meson/gen-demo-header.py
new file mode 100755
index 0000000000..f82ca972fc
--- /dev/null
+++ b/build-aux/meson/gen-demo-header.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import os
+import subprocess
+import sys
+
+if len(sys.argv) > 1:
+    profile = sys.argv[1]
+else:
+    profile = "default"
+
+sys.stdout.write("/* This file is auto-generated. Do not edit. */\n")
+sys.stdout.write("#pragma once\n")
+sys.stdout.write("\n")
+sys.stdout.write("#define PROFILE \"{profile}\"\n")
+
+short_sha = os.environ.get('CI_COMMIT_SHORT_SHA')
+if short_sha is not None:
+    sys.stdout.write(f"#define VCS_TAG \"{short_sha}\"\n")
+else:
+    cmd = ["git", "rev-parse", "--short", "HEAD"]
+    with subprocess.Popen(cmd, stdout=subprocess.PIPE) as p:
+        short_sha = p.stdout.read().decode('utf-8').rstrip("\n")
+        sys.stdout.write(f"#define VCS_TAG \"{short_sha}\"\n")
diff --git a/demos/meson.build b/demos/meson.build
index 79c530f4b7..f964100ac3 100644
--- a/demos/meson.build
+++ b/demos/meson.build
@@ -1,17 +1,11 @@
-demo_conf = configuration_data()
-demo_conf.set_quoted('PROFILE', get_option('profile'))
-demo_conf.set_quoted('VCS_TAG', '@VCS_TAG@')
+gen_demo_header = find_program('../build-aux/meson/gen-demo-header.py')
 
 demo_conf_h = declare_dependency(
-  sources: vcs_tag(
-             command: [ 'git', 'rev-parse', '--short', 'HEAD' ],
-             fallback: get_option('profile') != 'default' ? 'devel' : '',
-             input: configure_file(
-                      output: 'demo_conf.h.in',
-                      configuration: demo_conf
-                    ),
-             output: 'demo_conf.h'
-           )
+  sources: custom_target('demo-header',
+    command: [gen_demo_header, get_option('profile')],
+    capture: true,
+    output: 'demo_conf.h',
+  )
 )
 
 subdir('constraint-editor')


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