mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-09-11 19:17:17 +03:00
add git commit hash to --version output
This commit is contained in:
parent
720c7b7519
commit
821dabb138
4
.github/workflows/ci-tests.yml
vendored
4
.github/workflows/ci-tests.yml
vendored
@ -256,6 +256,10 @@ jobs:
|
||||
working-directory: /home/nominatim
|
||||
if: matrix.flavour == 'centos'
|
||||
|
||||
- name: Print version
|
||||
run: nominatim --version
|
||||
working-directory: /home/nominatim/nominatim-project
|
||||
|
||||
- name: Import
|
||||
run: nominatim import --osm-file ../test.pbf
|
||||
working-directory: /home/nominatim/nominatim-project
|
||||
|
@ -26,6 +26,17 @@ set(NOMINATIM_VERSION "${NOMINATIM_VERSION_MAJOR}.${NOMINATIM_VERSION_MINOR}.${N
|
||||
|
||||
add_definitions(-DNOMINATIM_VERSION="${NOMINATIM_VERSION}")
|
||||
|
||||
# Setting GIT_HASH
|
||||
find_package(Git)
|
||||
if (GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
OUTPUT_VARIABLE GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
endif()
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Configuration
|
||||
|
@ -7,6 +7,9 @@ sys.path.insert(1, '@NOMINATIM_LIBDIR@/lib-python')
|
||||
os.environ['NOMINATIM_NOMINATIM_TOOL'] = os.path.abspath(__file__)
|
||||
|
||||
from nominatim import cli
|
||||
from nominatim import version
|
||||
|
||||
version.GIT_COMMIT_HASH = '@GIT_HASH@'
|
||||
|
||||
exit(cli.nominatim(module_dir='@NOMINATIM_LIBDIR@/module',
|
||||
osm2pgsql_path='@NOMINATIM_LIBDIR@/osm2pgsql',
|
||||
|
@ -7,6 +7,9 @@ sys.path.insert(1, '@CMAKE_SOURCE_DIR@')
|
||||
os.environ['NOMINATIM_NOMINATIM_TOOL'] = os.path.abspath(__file__)
|
||||
|
||||
from nominatim import cli
|
||||
from nominatim import version
|
||||
|
||||
version.GIT_COMMIT_HASH = '@GIT_HASH@'
|
||||
|
||||
exit(cli.nominatim(module_dir='@CMAKE_BINARY_DIR@/module',
|
||||
osm2pgsql_path='@CMAKE_BINARY_DIR@/osm2pgsql/osm2pgsql',
|
||||
|
@ -38,8 +38,7 @@ class CommandlineParser:
|
||||
dest='subcommand')
|
||||
|
||||
# Global arguments that only work if no sub-command given
|
||||
self.parser.add_argument('--version', action='version',
|
||||
version=CommandlineParser.nominatim_version_text(),
|
||||
self.parser.add_argument('--version', action='store_true',
|
||||
help='Print Nominatim version and exit')
|
||||
|
||||
# Arguments added to every sub-command
|
||||
@ -61,7 +60,10 @@ class CommandlineParser:
|
||||
def nominatim_version_text():
|
||||
""" Program name and version number as string
|
||||
"""
|
||||
return "Nominatim version %s.%s.%s.%s\n" % version.NOMINATIM_VERSION
|
||||
text = 'Nominatim version %s.%s.%s.%s' % version.NOMINATIM_VERSION
|
||||
if version.GIT_COMMIT_HASH is not None:
|
||||
text += ' (%s)' % version.GIT_COMMIT_HASH
|
||||
return text
|
||||
|
||||
def add_subcommand(self, name, cmd):
|
||||
""" Add a subcommand to the parser. The subcommand must be a class
|
||||
@ -86,6 +88,10 @@ class CommandlineParser:
|
||||
except SystemExit:
|
||||
return 1
|
||||
|
||||
if args.version:
|
||||
print(CommandlineParser.nominatim_version_text())
|
||||
return 0
|
||||
|
||||
if args.subcommand is None:
|
||||
self.parser.print_help()
|
||||
return 1
|
||||
|
@ -28,3 +28,9 @@ NOMINATIM_VERSION = (4, 0, 99, 6)
|
||||
|
||||
POSTGRESQL_REQUIRED_VERSION = (9, 5)
|
||||
POSTGIS_REQUIRED_VERSION = (2, 2)
|
||||
|
||||
# Cmake sets a variabe @GIT_HASH@ by executing 'git --log'. It is not run
|
||||
# on every execution of 'make'.
|
||||
# cmake/tool-installed.tmpl is used to build the binary 'nominatim'. Inside
|
||||
# there is a call to set the variable value below.
|
||||
GIT_COMMIT_HASH = None
|
||||
|
@ -29,7 +29,7 @@ def test_cli_help(cli_call, capsys):
|
||||
def test_cli_version(cli_call, capsys):
|
||||
""" Running nominatim tool --version prints a version string.
|
||||
"""
|
||||
assert cli_call('--version') == 1
|
||||
assert cli_call('--version') == 0
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert captured.out.startswith('Nominatim version')
|
||||
|
Loading…
Reference in New Issue
Block a user