Skip to content

Commit 9b576cd

Browse files
committed
Extract ruby_api_version_name
1 parent c8233db commit 9b576cd

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

depend

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14598,7 +14598,6 @@ ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_newline_list.h
1459814598
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_string.h
1459914599
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_strncasecmp.h
1460014600
ruby.$(OBJEXT): $(top_srcdir)/prism/util/pm_strpbrk.h
14601-
ruby.$(OBJEXT): $(top_srcdir)/version.h
1460214601
ruby.$(OBJEXT): {$(VPATH)}assert.h
1460314602
ruby.$(OBJEXT): {$(VPATH)}atomic.h
1460414603
ruby.$(OBJEXT): {$(VPATH)}backward/2/assume.h
@@ -14782,7 +14781,6 @@ ruby.$(OBJEXT): {$(VPATH)}prism/ast.h
1478214781
ruby.$(OBJEXT): {$(VPATH)}prism/diagnostic.h
1478314782
ruby.$(OBJEXT): {$(VPATH)}prism/version.h
1478414783
ruby.$(OBJEXT): {$(VPATH)}prism_compile.h
14785-
ruby.$(OBJEXT): {$(VPATH)}revision.h
1478614784
ruby.$(OBJEXT): {$(VPATH)}ruby.c
1478714785
ruby.$(OBJEXT): {$(VPATH)}ruby_assert.h
1478814786
ruby.$(OBJEXT): {$(VPATH)}ruby_atomic.h

ruby.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
#include "ruby/util.h"
6262
#include "ruby/version.h"
6363
#include "ruby/internal/error.h"
64-
#include "version.h"
6564

6665
#define singlebit_only_p(x) !((x) & ((x)-1))
6766
STATIC_ASSERT(Qnil_1bit_from_Qfalse, singlebit_only_p(Qnil^Qfalse));
@@ -302,6 +301,8 @@ ruby_show_usage_line(const char *name, const char *secondary, const char *descri
302301
description, help, highlight, width, columns);
303302
}
304303

304+
RUBY_EXTERN const char ruby_api_version_name[];
305+
305306
static void
306307
usage(const char *name, int help, int highlight, int columns)
307308
{
@@ -404,9 +405,9 @@ usage(const char *name, int help, int highlight, int columns)
404405
unsigned int w = (columns > 80 ? (columns - 79) / 2 : 0) + 16;
405406
#define SHOW(m) show_usage_line(&(m), help, highlight, w, columns)
406407

407-
printf("%sUsage:%s %s [options] [--] [filepath] [arguments]\n\n", sb, se, name);
408-
printf("Details and examples at https://docs.ruby-lang.org/en/%s/ruby/options_md.html\n",
409-
RUBY_PATCHLEVEL == -1 ? "master" : STRINGIZE(RUBY_VERSION_MAJOR) "." STRINGIZE(RUBY_VERSION_MINOR));
408+
printf("%sUsage:%s %s [options] [--] [filepath] [arguments]\n", sb, se, name);
409+
printf("\n""Details and examples at https://docs.ruby-lang.org/en/%s/ruby/options_md.html\n",
410+
ruby_api_version_name);
410411

411412
for (i = 0; i < num; ++i)
412413
SHOW(usage_msg[i]);

test/ruby/test_rubyoptions.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,27 @@ def test_source_file
4747
assert_in_out_err([], "", [], [])
4848
end
4949

50+
version = RUBY_PATCHLEVEL == -1 ? "master" : "#{RUBY_VERSION_MAJOR}.#{RUBY_VERSION_MINOR}"
51+
OPTIONS_LINK = "https://docs.ruby-lang.org/en/#{version}/ruby/options_md.html"
52+
5053
def test_usage
5154
assert_in_out_err(%w(-h)) do |r, e|
52-
assert_operator(r.size, :<=, 26)
53-
longer = r[3..-1].select {|x| x.size >= 80}
55+
_, _, link, *r = r
56+
assert_include(link, OPTIONS_LINK)
57+
assert_operator(r.size, :<=, 24)
58+
longer = r.select {|x| x.size >= 80}
5459
assert_equal([], longer)
5560
assert_equal([], e)
56-
57-
version = RUBY_PATCHLEVEL == -1 ? "master" : "#{RUBY_VERSION_MAJOR}.#{RUBY_VERSION_MINOR}"
58-
assert_include(r, "Details and examples at https://docs.ruby-lang.org/en/#{version}/ruby/options_md.html")
5961
end
6062
end
6163

6264
def test_usage_long
6365
assert_in_out_err(%w(--help)) do |r, e|
64-
longer = r[3..-1].select {|x| x.size > 80}
66+
_, _, link, *r = r
67+
assert_include(link, OPTIONS_LINK)
68+
longer = r.select {|x| x.size > 80}
6569
assert_equal([], longer)
6670
assert_equal([], e)
67-
68-
version = RUBY_PATCHLEVEL == -1 ? "master" : "#{RUBY_VERSION_MAJOR}.#{RUBY_VERSION_MINOR}"
69-
assert_include(r, "Details and examples at https://docs.ruby-lang.org/en/#{version}/ruby/options_md.html")
7071
end
7172
end
7273

version.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424

2525
#ifdef RUBY_REVISION
2626
# if RUBY_PATCHLEVEL == -1
27+
# define RUBY_API_VERSION_NAME "master"
2728
# ifndef RUBY_BRANCH_NAME
28-
# define RUBY_BRANCH_NAME "master"
29+
# define RUBY_BRANCH_NAME RUBY_API_VERSION_NAME
2930
# endif
3031
# define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
3132
# else
33+
# define RUBY_API_VERSION_NAME RUBY_API_VERSION_STR
3234
# define RUBY_REVISION_STR " revision "RUBY_REVISION
3335
# endif
3436
#else
@@ -44,6 +46,10 @@
4446
#define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
4547
#define MKINT(name) INT2FIX(ruby_##name)
4648

49+
#define RUBY_API_VERSION_STR \
50+
STRINGIZE(RUBY_API_VERSION_MAJOR) "." \
51+
STRINGIZE(RUBY_API_VERSION_MINOR) "." \
52+
""
4753
const int ruby_api_version[] = {
4854
RUBY_API_VERSION_MAJOR,
4955
RUBY_API_VERSION_MINOR,
@@ -81,6 +87,7 @@ const char ruby_revision[] = RUBY_FULL_REVISION;
8187
const char ruby_release_date[] = RUBY_RELEASE_DATE;
8288
const char ruby_platform[] = RUBY_PLATFORM;
8389
const int ruby_patchlevel = RUBY_PATCHLEVEL;
90+
const char ruby_api_version_name[] = RUBY_API_VERSION_NAME;
8491
const char ruby_description[] =
8592
"ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR " "
8693
"(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR ") "

0 commit comments

Comments
 (0)