From f6051f73f5c55fe8e83aa358f8f2563abbb90229 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 22 Jun 2019 18:54:58 +0530 Subject: [PATCH] Use SPECIAL_SOURCES for KITTY_VCS_REV Fixes #1734 --- setup.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 591ed825e..5d0178f6c 100755 --- a/setup.py +++ b/setup.py @@ -303,8 +303,21 @@ def run_tool(cmd, desc=None): raise SystemExit(ret) +def get_vcs_rev_defines(): + ans = [] + if os.path.exists('.git'): + try: + rev = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip() + except FileNotFoundError: + with open('.git/refs/heads/master') as f: + rev = f.read() + ans.append('KITTY_VCS_REV="{}"'.format(rev)) + return ans + + SPECIAL_SOURCES = { 'kitty/parser_dump.c': ('kitty/parser.c', ['DUMP_COMMANDS']), + 'kitty/data-types.c': ('kitty/data-types.c', get_vcs_rev_defines), } @@ -392,12 +405,10 @@ def compile_c_extension(kenv, module, incremental, compilation_database, all_key is_special = src in SPECIAL_SOURCES if is_special: src, defines = SPECIAL_SOURCES[src] + if callable(defines): + defines = defines() cppflags.extend(map(define, defines)) - if src == 'kitty/data-types.c': - if os.path.exists('.git'): - rev = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('utf-8').strip() - cppflags.append(define('KITTY_VCS_REV="{}"'.format(rev))) cmd = [kenv.cc, '-MMD'] + cppflags + kenv.cflags key = original_src, os.path.basename(dest) all_keys.add(key)