]> git.openstreetmap.org Git - nominatim.git/commitdiff
add git commit hash to --version output
authorMarc Tobias <mtmail@gmx.net>
Wed, 4 May 2022 13:48:23 +0000 (15:48 +0200)
committerMarc Tobias <mtmail@gmx.net>
Mon, 9 May 2022 21:56:13 +0000 (23:56 +0200)
.github/workflows/ci-tests.yml
CMakeLists.txt
cmake/tool-installed.tmpl
cmake/tool.tmpl
nominatim/cli.py
nominatim/version.py
test/python/cli/test_cli.py

index b3d91cdf987eca7f4f94a19eb66e6abc07e29070..6ebf1ab97d154c7d5841d77f35e2cbdf3a1d8d56 100644 (file)
@@ -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
index 1aa9c315a5e2ad2181ff2a3da5b996f06080aae4..52bb9a01d906aa518f3e0e283a11589c3016f5e2 100644 (file)
@@ -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
index 0b245dbbe74b6dd43e34dfaaa6418aaa559cb570..8825daaf9b3b1599f67ac4bff156b602b29954fd 100644 (file)
@@ -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',
index a6022402650719a53db6f1e0d3cdf3841130258c..c1ecd3f03eec002aa686e065c17c6255cc3dd816 100755 (executable)
@@ -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',
index 2ddf5882376dab7b4174112016695dfb5d647a8d..01eb61190e25d0ecd059052a91bfe73dbce0ed61 100644 (file)
@@ -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
index b876002ef7f29cab99552a252dbe3e75fae6416d..47fe3b309e8f2ccab217f54faad430b2cbaff8ff 100644 (file)
@@ -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
index e8e185049a15ba46f5672f4c397e83845d15e615..07d6c31fded55d7adc57bed1192b56f1e8ff2858 100644 (file)
@@ -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')