1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ruby.c (add_gems, require_libraries, proc_options): add

--require and --gem options.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2011-02-11 03:06:50 +00:00
parent 020dc4ba60
commit 4ed23fe8c5
2 changed files with 45 additions and 2 deletions

View file

@ -1,3 +1,8 @@
Fri Feb 11 12:06:48 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (add_gems, require_libraries, proc_options): add
--require and --gem options.
Fri Feb 11 12:03:24 2011 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Feb 11 12:03:24 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (rubygems): add --disable-rubygems option. * configure.in (rubygems): add --disable-rubygems option.

42
ruby.c
View file

@ -480,6 +480,31 @@ add_modules(VALUE *req_list, const char *mod)
rb_ary_push(list, rb_obj_freeze(rb_str_new2(mod))); rb_ary_push(list, rb_obj_freeze(rb_str_new2(mod)));
} }
static void
add_gems(VALUE *req_list, const char *mod)
{
VALUE list = *req_list;
VALUE gem, ver;
const char *v;
if (!list) {
*req_list = list = rb_ary_new();
RBASIC(list)->klass = 0;
}
for (v = mod; *v && !ISSPACE(*v) && !strchr("=!<>~", *v); ++v);
gem = rb_obj_freeze(rb_str_new(mod, v-mod));
if (*v) {
while (ISSPACE(*v)) ++v;
}
if (*v) {
gem = rb_assoc_new(gem, rb_obj_freeze(rb_str_new2(v)));
}
else {
gem = rb_ary_new4(1, &gem);
}
rb_ary_push(list, rb_obj_freeze(gem));
}
extern void Init_ext(void); extern void Init_ext(void);
extern VALUE rb_vm_top_self(void); extern VALUE rb_vm_top_self(void);
@ -487,7 +512,8 @@ static void
require_libraries(VALUE *req_list) require_libraries(VALUE *req_list)
{ {
VALUE list = *req_list; VALUE list = *req_list;
ID require; VALUE self = rb_vm_top_self();
ID require, gem;
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
rb_block_t *prev_base_block = th->base_block; rb_block_t *prev_base_block = th->base_block;
int prev_parse_in_eval = th->parse_in_eval; int prev_parse_in_eval = th->parse_in_eval;
@ -496,9 +522,15 @@ require_libraries(VALUE *req_list)
Init_ext(); /* should be called here for some reason :-( */ Init_ext(); /* should be called here for some reason :-( */
CONST_ID(require, "require"); CONST_ID(require, "require");
CONST_ID(gem, "gem");
while (list && RARRAY_LEN(list) > 0) { while (list && RARRAY_LEN(list) > 0) {
VALUE feature = rb_ary_shift(list); VALUE feature = rb_ary_shift(list);
rb_funcall2(rb_vm_top_self(), require, 1, &feature); if (RB_TYPE_P(feature, T_ARRAY)) {
rb_funcall2(self, gem, RARRAY_LENINT(feature), RARRAY_PTR(feature));
}
else {
rb_funcall2(self, require, 1, &feature);
}
} }
*req_list = 0; *req_list = 0;
@ -1036,6 +1068,12 @@ proc_options(long argc, char **argv, struct cmdline_options *opt, int envopt)
set_source_encoding_once(opt, s, 0); set_source_encoding_once(opt, s, 0);
} }
#endif #endif
else if (is_option_with_arg("require", Qfalse, Qtrue)) {
add_modules(&opt->req_list, s);
}
else if (is_option_with_arg("gem", Qfalse, Qtrue)) {
add_gems(&opt->req_list, s);
}
else if (strcmp("version", s) == 0) { else if (strcmp("version", s) == 0) {
if (envopt) goto noenvopt_long; if (envopt) goto noenvopt_long;
opt->dump |= DUMP_BIT(version); opt->dump |= DUMP_BIT(version);