Skip to content

Commit 3fc6041

Browse files
committed
Use root CMakeLists.txt as the default version
Following on from !331 this patch fixes an issue where running `scripts/run.py` without the `--ver` argument would result in the wrong version number being generated in the spec HTML. The default value for the `--ver` argument is now read from the `project()` command in root `CMakeLists.txt` file, making it the single source of truth for the version.
1 parent 22c6e96 commit 3fc6041

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Build Documentation
4747
working-directory: ${{github.workspace}}/scripts
4848
run: python3 run.py --core
49-
49+
5050
- name: Upload artifact
5151
uses: actions/upload-pages-artifact@v1
5252
with:

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ set(API_JSON_FILE ${PROJECT_BINARY_DIR}/unified_runtime.json)
205205
# Generate source from the specification
206206
add_custom_target(generate-code USES_TERMINAL
207207
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/scripts
208-
COMMAND ${Python3_EXECUTABLE} run.py --api-json ${API_JSON_FILE} --ver ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
208+
COMMAND ${Python3_EXECUTABLE} run.py --api-json ${API_JSON_FILE}
209209
COMMAND ${Python3_EXECUTABLE} json2src.py --api-json ${API_JSON_FILE} ${PROJECT_SOURCE_DIR}
210210
)
211211

scripts/run.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
"""
77
import argparse
8+
import re
89
import util
910
import parse_specs
1011
import generate_code
@@ -71,15 +72,30 @@ def revision():
7172
print("Version is %s" % tag)
7273
count = 0
7374
if len(items) > 1 and items[1].isdigit():
74-
count = int(items[1])
75+
count = int(items[1])
7576

76-
# Bump count if any local files are dirty.
77+
# Bump count if any local files are dirty.
7778
# Keeps the count the same after doing a commit (assuming all dirty files are committed)
7879
if 'dirty' in items[-1]:
7980
count += 1
8081
return '%s.%s'%(tag, count)
8182

8283

84+
"""
85+
helper for getting the default version from the project() command in the
86+
root CMakeLists.txt file
87+
"""
88+
def get_version_from_cmakelists():
89+
cmakelists_path = os.path.abspath(
90+
os.path.join(os.path.dirname(__file__), '..', 'CMakeLists.txt'))
91+
with open(cmakelists_path, 'r') as cmakelists_file:
92+
for line in cmakelists_file.readlines():
93+
line = line.strip()
94+
if line.startswith('project('):
95+
return re.findall(r'\d+\.\d+', line)[0]
96+
raise Exception(f'unable to read project version from {cmakelists_path}')
97+
98+
8399
"""
84100
Main entry:
85101
Do everything...
@@ -98,11 +114,14 @@ def main():
98114
add_argument(parser, "pdf", "generation of PDF file.")
99115
add_argument(parser, "rst", "generation of reStructuredText files.", True)
100116
parser.add_argument("--update_spec", type=str, help="root of integrated spec directory to update")
101-
parser.add_argument("--ver", type=str, default="0.5", required=False, help="specification version to generate.")
117+
parser.add_argument("--ver", type=str, default=get_version_from_cmakelists(),
118+
required=False, help="specification version to generate.")
102119
parser.add_argument("--api-json", type=str, default="unified_runtime.json", required=False, help="json output file for the spec")
103120
args = vars(parser.parse_args())
104121
args['rev'] = revision()
105122

123+
print('Version', args['ver'])
124+
106125
start = time.time()
107126

108127
# phase 1: extract configuration info from ini file

0 commit comments

Comments
 (0)