diff --git a/.gitignore b/.gitignore index 110ff652e..537014764 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ /src/common/common_pch.h.[gp]ch /src/common/common_pch.h.pch-???????? /src/common/libmtxcommon.dll +/src/common/mkvtoolnix_version.h /src/info/forms/*.h /src/info/static_plugins.cpp /src/mkvextract diff --git a/Rakefile b/Rakefile index 976c8007e..db7297926 100644 --- a/Rakefile +++ b/Rakefile @@ -100,6 +100,8 @@ def setup_globals $dependency_dir = "#{$source_dir}/rake.d/dependency.d" $dependency_tmp_dir = "#{$dependency_dir}/tmp" + $version_header_name = "#{$build_dir}/src/common/mkvtoolnix_version.h" + $languages = { :programs => c(:TRANSLATIONS).split(/\s+/), :manpages => c(:MANPAGES_TRANSLATIONS).split(/\s+/), @@ -279,6 +281,7 @@ setup_globals setup_overrides import_dependencies generate_helper_files +update_version_number_include # Default task define_default_task @@ -977,6 +980,7 @@ task :clean do } patterns += $applications + $tools.collect { |name| "src/tools/#{name}" } patterns += PCH.clean_patterns + patterns << $version_header_name remove_files_by_patterns patterns diff --git a/rake.d/helpers.rb b/rake.d/helpers.rb index ad5a265a7..fde8267f9 100644 --- a/rake.d/helpers.rb +++ b/rake.d/helpers.rb @@ -1,4 +1,7 @@ # coding: utf-8 + +require "shellwords" + $use_tempfile_for_run = defined?(RUBY_PLATFORM) && /mingw/i.match(RUBY_PLATFORM) $git_mutex = Mutex.new @@ -252,6 +255,38 @@ def ensure_file file_name, content = "" File.open(file_name, 'w') { |file| file.write(content) } end +def update_version_number_include + git_dir = $source_dir + '/.git' + current_version = nil + wanted_version = c(:PACKAGE_VERSION) + + if FileTest.exists?($version_header_name) + lines = IO.readlines($version_header_name) + + if !lines.empty? && %r{#define.*?"([0-9.]+)"}.match(lines[0]) + current_version = $1 + end + end + + if FileTest.directory?(git_dir) + command = ["git", "--git-dir=#{$source_dir}/.git", "describe", "HEAD"]. + map { |e| Shellwords.escape(e) }. + join(' ') + + description = `#{command} 2> /dev/null`.chomp + + if %r{^release-#{Regexp.escape(c(:PACKAGE_VERSION))}-(\d+)}.match(description) && ($1.to_i != 0) + wanted_version += ".#{$1}" + end + end + + return if current_version == wanted_version + + File.open($version_header_name, "w") do |file| + file.puts("#define MKVTOOLNIX_VERSION \"#{wanted_version}\"") + end +end + class Rake::Task def mo_all_prerequisites todo = [name] diff --git a/src/common/version.cpp b/src/common/version.cpp index 69314295f..4feb21c39 100644 --- a/src/common/version.cpp +++ b/src/common/version.cpp @@ -18,6 +18,7 @@ #include "common/debugging.h" #include "common/hacks.h" +#include "common/mkvtoolnix_version.h" #include "common/strings/formatting.h" #include "common/strings/parsing.h" #include "common/version.h" @@ -135,7 +136,7 @@ get_version_info(const std::string &program, if (!program.empty()) info.push_back(program); - info.push_back(fmt::format("v{0} ('{1}')", PACKAGE_VERSION, VERSIONNAME)); + info.push_back(fmt::format("v{0} ('{1}')", MKVTOOLNIX_VERSION, VERSIONNAME)); if (flags & vif_architecture) info.push_back(fmt::format("{0}-bit", __SIZEOF_POINTER__ * 8)); @@ -145,12 +146,12 @@ get_version_info(const std::string &program, int compare_current_version_to(const std::string &other_version_str) { - return version_number_t(PACKAGE_VERSION).compare(version_number_t(other_version_str)); + return version_number_t(MKVTOOLNIX_VERSION).compare(version_number_t(other_version_str)); } version_number_t get_current_version() { - return version_number_t(PACKAGE_VERSION); + return version_number_t(MKVTOOLNIX_VERSION); } mtx_release_version_t