Skip to content

Commit 8382ad3

Browse files
Retreive the version from the single source
1 parent f88c2f1 commit 8382ad3

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

doc/source/conf.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import os
1717
import time
18+
import re
1819

1920
# If extensions (or modules to document with autodoc) are in another directory,
2021
# add these directories to sys.path here. If the directory is relative to the
@@ -58,7 +59,21 @@
5859
# |version| and |release|, also used in various other places throughout the
5960
# built documents.
6061
#
61-
version = u'4.9.2'
62+
def read_version_from_source():
63+
"""Extract version from squirrel.h"""
64+
header_path = os.path.join(os.path.dirname(__file__), '..', '..', 'include', 'squirrel.h')
65+
header_path = os.path.abspath(header_path)
66+
67+
with open(header_path, 'r') as f:
68+
content = f.read()
69+
70+
major = re.search(r'#define\s+SQUIRREL_VERSION_NUMBER_MAJOR\s+(\d+)', content).group(1)
71+
minor = re.search(r'#define\s+SQUIRREL_VERSION_NUMBER_MINOR\s+(\d+)', content).group(1)
72+
patch = re.search(r'#define\s+SQUIRREL_VERSION_NUMBER_PATCH\s+(\d+)', content).group(1)
73+
74+
return f'{major}.{minor}.{patch}'
75+
76+
version = read_version_from_source()
6277

6378
# The language for content autogenerated by Sphinx. Refer to documentation
6479
# for a list of supported languages.

include/squirrel.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,16 @@ namespace SQCompilation
8080
#define SQUIRREL_VERSION_NUMBER_MINOR 9
8181
#define SQUIRREL_VERSION_NUMBER_PATCH 2
8282

83-
#define SQUIRREL_VERSION _SC("4.9.2")
84-
#define SQUIRREL_COPYRIGHT _SC("Copyright (C) 2003-2016 Alberto Demichelis; 2016-2024 Gaijin Games KFT")
83+
#define SQ_STRINGIFY_HELPER(x) #x
84+
#define SQ_STRINGIFY(x) SQ_STRINGIFY_HELPER(x)
85+
86+
#define SQUIRREL_VERSION \
87+
SQ_STRINGIFY(SQUIRREL_VERSION_NUMBER_MAJOR) "." \
88+
SQ_STRINGIFY(SQUIRREL_VERSION_NUMBER_MINOR) "." \
89+
SQ_STRINGIFY(SQUIRREL_VERSION_NUMBER_PATCH)
90+
91+
#define SQUIRREL_COPYRIGHT "Copyright (C) 2003-2016 Alberto Demichelis; 2016-2025 Gaijin Games KFT"
92+
8593

8694
#define SQ_VMSTATE_IDLE 0
8795
#define SQ_VMSTATE_RUNNING 1

0 commit comments

Comments
 (0)