From 38a7a13ac6ed6bba2584def7d7121257eb85e051 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sat, 17 Sep 2022 21:16:06 +0900 Subject: [PATCH] Auto-generate the release date on version.h from git CommitDate (#6382) * Auto-generate the release date on version.h from git CommitDate * Generate revision.h on mswin --- common.mk | 3 ++- tool/file2lastrev.rb | 10 ++++++++-- tool/lib/vcs.rb | 22 ++++++++++++++++++---- tool/make-snapshot | 2 +- version.h | 13 +++++-------- win32/Makefile.sub | 2 ++ win32/ifchange.bat | 1 + 7 files changed, 37 insertions(+), 16 deletions(-) diff --git a/common.mk b/common.mk index ad492c0079..fb1b785534 100644 --- a/common.mk +++ b/common.mk @@ -1214,7 +1214,7 @@ $(BUILTIN_RB_INCS): $(top_srcdir)/tool/mk_builtin_loader.rb $(srcdir)/revision.h: $(srcdir)/revision.h$(gnumake:yes=-nongnumake): $(Q)$(RM) $(@F) - $(Q)$(NULLCMD) > $@ || $(NULLCMD) > $(@F) + $(NULLCMD) > $(@F) revision.tmp:: $(Q) $(NULLCMD) > $@ @@ -8275,6 +8275,7 @@ load.$(OBJEXT): {$(VPATH)}vm_core.h load.$(OBJEXT): {$(VPATH)}vm_opts.h loadpath.$(OBJEXT): $(hdrdir)/ruby/ruby.h loadpath.$(OBJEXT): $(hdrdir)/ruby/version.h +loadpath.$(OBJEXT): $(top_srcdir)/revision.h loadpath.$(OBJEXT): $(top_srcdir)/version.h loadpath.$(OBJEXT): {$(VPATH)}assert.h loadpath.$(OBJEXT): {$(VPATH)}backward/2/assume.h diff --git a/tool/file2lastrev.rb b/tool/file2lastrev.rb index 008e4b55e5..476437a995 100755 --- a/tool/file2lastrev.rb +++ b/tool/file2lastrev.rb @@ -66,7 +66,13 @@ OptionParser.new {|opts| new_vcs["."] end } -exit unless vcs +unless vcs + # Output only release_date when .git is missing + if @output == :revision_h + puts VCS.release_date(Time.now - 10) # same as make-snapshot + end + exit +end @output = case @output @@ -76,7 +82,7 @@ exit unless vcs } when :revision_h Proc.new {|last, changed, modified, branch, title| - vcs.revision_header(last, modified, branch, title, limit: @limit) + vcs.revision_header(last, modified, modified, branch, title, limit: @limit) } when :doxygen Proc.new {|last, changed| diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb index 05d95061c4..d33d41dba1 100644 --- a/tool/lib/vcs.rb +++ b/tool/lib/vcs.rb @@ -95,6 +95,15 @@ class VCS opts end + def self.release_date(time) + t = time.utc + [ + t.strftime('#define RUBY_RELEASE_YEAR %Y'), + t.strftime('#define RUBY_RELEASE_MONTH %-m'), + t.strftime('#define RUBY_RELEASE_DAY %-d'), + ] + end + attr_reader :srcdir def initialize(path) @@ -204,7 +213,8 @@ class VCS revision_handler(rev).short_revision(rev) end - def revision_header(last, modified = nil, branch = nil, title = nil, limit: 20) + # make-snapshot generates only release_date whereas file2lastrev generates both release_date and release_datetime + def revision_header(last, release_date, release_datetime = nil, branch = nil, title = nil, limit: 20) short = short_revision(last) if /[^\x00-\x7f]/ =~ title and title.respond_to?(:force_encoding) title = title.dup.force_encoding("US-ASCII") @@ -225,10 +235,11 @@ class VCS title = title.dump.sub(/\\#/, '#') code << "#define RUBY_LAST_COMMIT_TITLE #{title}" end - if modified - t = modified.utc + if release_datetime + t = release_datetime.utc code << t.strftime('#define RUBY_RELEASE_DATETIME "%FT%TZ"') end + code += VCS.release_date(release_date) code end @@ -386,7 +397,10 @@ class VCS end class GIT < self - register(".git") {|path, dir| File.exist?(File.join(path, dir))} + register(".git") do |path, dir| + File.exist?(File.join(path, dir)) && + (`#{COMMAND} -v` rescue false) # make sure git command exists + end COMMAND = ENV["GIT"] || 'git' def cmd_args(cmds, srcdir = nil) diff --git a/tool/make-snapshot b/tool/make-snapshot index 02b5d182f5..22ae360c3e 100755 --- a/tool/make-snapshot +++ b/tool/make-snapshot @@ -347,7 +347,7 @@ def package(vcs, rev, destdir, tmp = nil) end File.open("#{v}/revision.h", "wb") {|f| - f.puts vcs.revision_header(revision) + f.puts vcs.revision_header(revision, modified) } version ||= (versionhdr = IO.read("#{v}/version.h"))[RUBY_VERSION_PATTERN, 1] version ||= diff --git a/version.h b/version.h index 7ce07104d1..46f14e3f14 100644 --- a/version.h +++ b/version.h @@ -13,13 +13,12 @@ #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR #define RUBY_PATCHLEVEL -1 -#define RUBY_RELEASE_YEAR 2022 -#define RUBY_RELEASE_MONTH 9 -#define RUBY_RELEASE_DAY 17 - #include "ruby/version.h" #include "ruby/internal/abi.h" +#ifndef RUBY_REVISION +#include "revision.h" + #ifndef TOKEN_PASTE #define TOKEN_PASTE(x,y) x##y #endif @@ -38,6 +37,8 @@ #define RUBY_RELEASE_DAY_STR STRINGIZE(RUBY_RELEASE_DAY) #endif +#endif + #ifdef RUBY_ABI_VERSION # define RUBY_ABI_VERSION_SUFFIX "+"STRINGIZE(RUBY_ABI_VERSION) #else @@ -61,8 +62,4 @@ #define RUBY_PATCHLEVEL_STR "" #endif -#ifndef RUBY_REVISION -# include "revision.h" -#endif - #endif /* RUBY_TOPLEVEL_VERSION_H */ diff --git a/win32/Makefile.sub b/win32/Makefile.sub index 361af556cd..e802b80968 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -1244,6 +1244,8 @@ $(RCFILES): $(RBCONFIG) $(srcdir)/revision.h $(srcdir)/win32/resource.rb -so_name=$(RUBY_SO_NAME) \ . $(icondirs) $(win_srcdir) +$(srcdir)/revision.h: $(REVISION_H) + update-benchmark-driver: $(GIT) clone https://github.com/benchmark-driver/benchmark-driver $(srcdir)/benchmark/benchmark-driver || \ $(GIT) -C $(srcdir)/benchmark/benchmark-driver pull origin master diff --git a/win32/ifchange.bat b/win32/ifchange.bat index c7db628a04..fb9ad27337 100755 --- a/win32/ifchange.bat +++ b/win32/ifchange.bat @@ -89,6 +89,7 @@ if exist %dest% ( ) ) for %%I in (%1) do echo %%~I updated +del /f %dest% copy %src% %dest% > nul del %src%