Ruby 3.2.1p31 (2023-02-08 revision 31819e82c88c6f8ecfaeb162519bfa26a14b21fd)
version.c
1/**********************************************************************
2
3 version.c -
4
5 $Author$
6 created at: Thu Sep 30 20:08:01 JST 1993
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9
10**********************************************************************/
11
12#include "internal/cmdlineopt.h"
13#include "ruby/ruby.h"
14#include "version.h"
15#include "vm_core.h"
16#include "mjit.h"
17#include "yjit.h"
18#include <stdio.h>
19
20#ifndef EXIT_SUCCESS
21#define EXIT_SUCCESS 0
22#endif
23
24#ifdef RUBY_REVISION
25# if RUBY_PATCHLEVEL == -1
26# ifndef RUBY_BRANCH_NAME
27# define RUBY_BRANCH_NAME "master"
28# endif
29# define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
30# else
31# define RUBY_REVISION_STR " revision "RUBY_REVISION
32# endif
33#else
34# define RUBY_REVISION "HEAD"
35# define RUBY_REVISION_STR ""
36#endif
37#if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
38# undef RUBY_RELEASE_DATETIME
39# define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
40#endif
41
42# define RUBY_DESCRIPTION_WITH(opt) \
43 "ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR " " \
44 "(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR ")" opt " " \
45 "[" RUBY_PLATFORM "]"
46
47#define PRINT(type) puts(ruby_##type)
48#define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
49#define MKINT(name) INT2FIX(ruby_##name)
50
51const int ruby_api_version[] = {
55};
56#define RUBY_VERSION \
57 STRINGIZE(RUBY_VERSION_MAJOR) "." \
58 STRINGIZE(RUBY_VERSION_MINOR) "." \
59 STRINGIZE(RUBY_VERSION_TEENY) ""
60#ifndef RUBY_FULL_REVISION
61# define RUBY_FULL_REVISION RUBY_REVISION
62#endif
63#ifdef YJIT_SUPPORT
64#define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
65#else
66#define YJIT_DESCRIPTION " +YJIT"
67#endif
68const char ruby_version[] = RUBY_VERSION;
69const char ruby_revision[] = RUBY_FULL_REVISION;
70const char ruby_release_date[] = RUBY_RELEASE_DATE;
71const char ruby_platform[] = RUBY_PLATFORM;
72const int ruby_patchlevel = RUBY_PATCHLEVEL;
73const char ruby_description[] = RUBY_DESCRIPTION_WITH("");
74static const char ruby_description_with_mjit[] = RUBY_DESCRIPTION_WITH(" +MJIT");
75static const char ruby_description_with_yjit[] = RUBY_DESCRIPTION_WITH(YJIT_DESCRIPTION);
76const char ruby_copyright[] = "ruby - Copyright (C) "
77 RUBY_BIRTH_YEAR_STR "-" RUBY_RELEASE_YEAR_STR " "
79const char ruby_engine[] = "ruby";
80
81// Might change after initialization
82const char *rb_dynamic_description = ruby_description;
83
85void
86Init_version(void)
87{
88 enum {ruby_patchlevel = RUBY_PATCHLEVEL};
89 VALUE version;
90 VALUE ruby_engine_name;
91 /*
92 * The running version of ruby
93 */
94 rb_define_global_const("RUBY_VERSION", (version = MKSTR(version)));
95 /*
96 * The date this ruby was released
97 */
98 rb_define_global_const("RUBY_RELEASE_DATE", MKSTR(release_date));
99 /*
100 * The platform for this ruby
101 */
102 rb_define_global_const("RUBY_PLATFORM", MKSTR(platform));
103 /*
104 * The patchlevel for this ruby. If this is a development build of ruby
105 * the patchlevel will be -1
106 */
107 rb_define_global_const("RUBY_PATCHLEVEL", MKINT(patchlevel));
108 /*
109 * The GIT commit hash for this ruby.
110 */
111 rb_define_global_const("RUBY_REVISION", MKSTR(revision));
112 /*
113 * The copyright string for ruby
114 */
115 rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
116 /*
117 * The engine or interpreter this ruby uses.
118 */
119 rb_define_global_const("RUBY_ENGINE", ruby_engine_name = MKSTR(engine));
120 ruby_set_script_name(ruby_engine_name);
121 /*
122 * The version of the engine or interpreter this ruby uses.
123 */
124 rb_define_global_const("RUBY_ENGINE_VERSION", (1 ? version : MKSTR(version)));
125
126 rb_provide("ruby2_keywords.rb");
127}
128
129#if USE_MJIT
130#define MJIT_OPTS_ON opt->mjit.on
131#else
132#define MJIT_OPTS_ON 0
133#endif
134
135#if USE_YJIT
136#define YJIT_OPTS_ON opt->yjit
137#else
138#define YJIT_OPTS_ON 0
139#endif
140
141void
142Init_ruby_description(ruby_cmdline_options_t *opt)
143{
144 VALUE description;
145
146 if (MJIT_OPTS_ON) {
147 rb_dynamic_description = ruby_description_with_mjit;
148 description = MKSTR(description_with_mjit);
149 }
150 else if (YJIT_OPTS_ON) {
151 rb_dynamic_description = ruby_description_with_yjit;
152 description = MKSTR(description_with_yjit);
153 }
154 else {
155 description = MKSTR(description);
156 }
157
158 /*
159 * The full ruby version string, like <tt>ruby -v</tt> prints
160 */
161 rb_define_global_const("RUBY_DESCRIPTION", /* MKSTR(description) */ description);
162}
163
164void
166{
167 puts(rb_dynamic_description);
168
169#ifdef RUBY_LAST_COMMIT_TITLE
170 fputs("last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
171#endif
172#ifdef HAVE_MALLOC_CONF
173 if (malloc_conf) printf("malloc_conf=%s\n", malloc_conf);
174#endif
175 fflush(stdout);
176}
177
178void
180{
181 PRINT(copyright);
182 fflush(stdout);
183}
void ruby_set_script_name(VALUE name)
Identical to ruby_script(), except it takes the name as a Ruby String instance.
Definition ruby.c:2607
void ruby_show_copyright(void)
Prints the copyright notice of the CRuby interpreter to stdout.
Definition version.c:179
void ruby_show_version(void)
Prints the version information of the CRuby interpreter to stdout.
Definition version.c:165
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
Definition load.c:671
void rb_define_global_const(const char *name, VALUE val)
Identical to rb_define_const(), except it defines that of "global", i.e.
Definition variable.c:3439
const int ruby_api_version[3]
API versions, in { major, minor, teeny } order.
Definition version.c:51
const char ruby_engine[]
This is just "ruby" for us.
Definition version.c:79
#define RUBY_API_VERSION_TEENY
Teeny version.
Definition version.h:76
const char ruby_platform[]
Target platform identifier, in a C string.
Definition version.c:71
const char ruby_version[]
Stringised version.
Definition version.c:68
#define RUBY_API_VERSION_MAJOR
Major version.
Definition version.h:64
#define RUBY_API_VERSION_MINOR
Minor version.
Definition version.h:70
#define RUBY_AUTHOR
Author of this project.
Definition version.h:32
const char ruby_copyright[]
Copyright notice.
Definition version.c:76
const char ruby_release_date[]
Date of release, in a C string.
Definition version.c:70
const int ruby_patchlevel
This is a monotonic increasing integer that describes specific "patch" level.
Definition version.c:72
const char ruby_description[]
This is what ruby -v prints to the standard error.
Definition version.c:73
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40