Skip to content

Commit

Permalink
Use root CMakeLists.txt as the default version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kbenzie committed Mar 13, 2023
1 parent 22c6e96 commit 3fc6041
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Build Documentation
working-directory: ${{github.workspace}}/scripts
run: python3 run.py --core

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ set(API_JSON_FILE ${PROJECT_BINARY_DIR}/unified_runtime.json)
# Generate source from the specification
add_custom_target(generate-code USES_TERMINAL
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/scripts
COMMAND ${Python3_EXECUTABLE} run.py --api-json ${API_JSON_FILE} --ver ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
COMMAND ${Python3_EXECUTABLE} run.py --api-json ${API_JSON_FILE}
COMMAND ${Python3_EXECUTABLE} json2src.py --api-json ${API_JSON_FILE} ${PROJECT_SOURCE_DIR}
)

Expand Down
25 changes: 22 additions & 3 deletions scripts/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import argparse
import re
import util
import parse_specs
import generate_code
Expand Down Expand Up @@ -71,15 +72,30 @@ def revision():
print("Version is %s" % tag)
count = 0
if len(items) > 1 and items[1].isdigit():
count = int(items[1])
count = int(items[1])

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


"""
helper for getting the default version from the project() command in the
root CMakeLists.txt file
"""
def get_version_from_cmakelists():
cmakelists_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'CMakeLists.txt'))
with open(cmakelists_path, 'r') as cmakelists_file:
for line in cmakelists_file.readlines():
line = line.strip()
if line.startswith('project('):
return re.findall(r'\d+\.\d+', line)[0]
raise Exception(f'unable to read project version from {cmakelists_path}')


"""
Main entry:
Do everything...
Expand All @@ -98,11 +114,14 @@ def main():
add_argument(parser, "pdf", "generation of PDF file.")
add_argument(parser, "rst", "generation of reStructuredText files.", True)
parser.add_argument("--update_spec", type=str, help="root of integrated spec directory to update")
parser.add_argument("--ver", type=str, default="0.5", required=False, help="specification version to generate.")
parser.add_argument("--ver", type=str, default=get_version_from_cmakelists(),
required=False, help="specification version to generate.")
parser.add_argument("--api-json", type=str, default="unified_runtime.json", required=False, help="json output file for the spec")
args = vars(parser.parse_args())
args['rev'] = revision()

print('Version', args['ver'])

start = time.time()

# phase 1: extract configuration info from ini file
Expand Down

0 comments on commit 3fc6041

Please sign in to comment.