diff --git a/meson.build b/meson.build index 3393d25..8ab99a4 100644 --- a/meson.build +++ b/meson.build @@ -22,16 +22,18 @@ project( 'bridge', ['c', 'cpp'], + version : 'remix-0.2.0', meson_version : '>= 0.58', default_options : ['werror=true', 'b_vscrt=static_from_buildtype', 'cpp_std=vc++17'] ) +python_interpreter = find_program('python3', 'python') +global_src_root_norm = meson.global_source_root().replace('\\', '/') output_dir = meson.global_source_root() + '/_output/' cpu_family = target_machine.cpu_family() build_os = build_machine.system() - # Get script paths if build_os == 'windows' @@ -164,9 +166,68 @@ else output : [ '@BASENAME@' + res_ext ], arguments : [ '-i', '@INPUT@', '-o', '@OUTPUT@' ]) endif + +message('##############') +message('# Versioning #') +message('##############') + +full_version = meson.project_version() + +git_rev_parse_out = run_command('git',['rev-parse','--verify','--short=8', 'HEAD']) +git_hash = '' +if git_rev_parse_out.returncode() != 0 + error('Failed to get current git hash') +else + git_hash = git_rev_parse_out.stdout().replace('\n','') + message('Current git hash: ' + git_hash) +endif + +found_tag = '' +ci_commit_tag = '' +get_env_out = run_command(python_interpreter.full_path(),[global_src_root_norm + './scripts-common/get_env.py', 'CI_COMMIT_TAG']) +if get_env_out.returncode() != 0 + error('get_env.py failed, which is unexpected') +else + ci_commit_tag = get_env_out.stdout().replace('\n','') +endif +b_found_ci_commit_tag = (ci_commit_tag != '') + +if b_found_ci_commit_tag + message('Found tag in CI_COMMIT_TAG envvar: ' + ci_commit_tag) + found_tag = ci_commit_tag +else + git_describe_tag = '' + git_describe_out = run_command('git',['describe','--always','--exact-match', git_hash]) + if git_describe_out.returncode() == 0 + git_describe_tag = git_describe_out.stdout().replace('\n','') + message('Found tag via git describe: ' + git_describe_tag) + endif + found_tag = git_describe_tag +endif + +b_found_tag = found_tag != '' +b_found_tag_matches = false +if b_found_tag + b_found_tag_matches = found_tag == meson.project_version() +endif + +if b_found_tag + if not b_found_tag_matches + warning('Tag does not match current version: ' + meson.project_version() + '. Please reconcile tag with version in meson.build.') + else + message('Found tag matches current version: ' + meson.project_version()) + message('This is a release version.') + endif +else + message('No tag found at current commit.') + message('This is NOT a release version') + full_version += '+' + git_hash +endif + +message('Full version: ' + full_version) bridge_version = vcs_tag( - command: ['git', 'describe', '--dirty=+'], + command: [python_interpreter.full_path(), global_src_root_norm + './scripts-common/echo.py', full_version], input: 'version.h.in', output: 'version.h') diff --git a/scripts-common/echo.py b/scripts-common/echo.py new file mode 100644 index 0000000..05e7ad7 --- /dev/null +++ b/scripts-common/echo.py @@ -0,0 +1,7 @@ +import sys + +if len(sys.argv) != 2: + print("ERROR: Must provide one and only one positional arg to echo.py", sys.stderr) + exit(1) +print(sys.argv[1]) +exit(0) \ No newline at end of file diff --git a/scripts-common/get_env.py b/scripts-common/get_env.py new file mode 100644 index 0000000..794a46d --- /dev/null +++ b/scripts-common/get_env.py @@ -0,0 +1,11 @@ +import sys +import os + +if len(sys.argv) != 2: + print("ERROR: Must provide one and only one envvar name to get_env.py", sys.stderr) + exit(1) +envvar = sys.argv[1] +if envvar in os.environ.keys(): + val = os.environ[envvar] + print(val) +exit(0) \ No newline at end of file diff --git a/src/client/meson.build b/src/client/meson.build index 05bc07f..4c47d48 100644 --- a/src/client/meson.build +++ b/src/client/meson.build @@ -21,9 +21,9 @@ ############################################################################# d3d9_version = vcs_tag( - command: ['git', 'describe', '--dirty=+'], - input: 'version.rc.in', - output: 'version.rc') + command: [python_interpreter.full_path(), global_src_root_norm + './scripts-common/echo.py', full_version], + input: 'version.rc.in', + output: 'version.rc') d3d9_res = wrc_generator.process(d3d9_version) diff --git a/src/server/meson.build b/src/server/meson.build index 451903a..6738c4f 100644 --- a/src/server/meson.build +++ b/src/server/meson.build @@ -33,9 +33,9 @@ server_header = files([ thread_dep = dependency('threads') server_tag = vcs_tag( - command: ['git', 'describe', '--dirty=+'], - input: 'version.rc.in', - output: 'version.rc') + command: [python_interpreter.full_path(), global_src_root_norm + './scripts-common/echo.py', full_version], + input: 'version.rc.in', + output: 'version.rc') server_version = wrc_generator.process(server_tag)