From 536e266e58e6fda550e781d7a88317fdfe149cfa Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 9 Nov 2010 22:20:12 +0000 Subject: * cygwin/GNUmakefile.in (scriptbin): make executable file from scripts with stub. * ruby.c (load_file_internal): assume xflag for exe file as well as no-shebang file. * tool/rbinstall.rb: install script programs. * win32/mkexports.rb (Exports#initialize): alias ruby_sysinit for stub. * win32/stub.c: stub for scripts. [EXPERIMENTAL] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 15 +++++++++++++++ cygwin/GNUmakefile.in | 11 +++++++++++ ruby.c | 9 ++++++--- tool/rbinstall.rb | 9 ++++++++- version.h | 4 ++-- win32/mkexports.rb | 1 + win32/stub.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 win32/stub.c diff --git a/ChangeLog b/ChangeLog index 87dfcc4310..b7cd78bcdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Wed Nov 10 07:20:10 2010 Nobuyoshi Nakada + + * cygwin/GNUmakefile.in (scriptbin): make executable file from + scripts with stub. + + * ruby.c (load_file_internal): assume xflag for exe file as well + as no-shebang file. + + * tool/rbinstall.rb: install script programs. + + * win32/mkexports.rb (Exports#initialize): alias ruby_sysinit for + stub. + + * win32/stub.c: stub for scripts. [EXPERIMENTAL] + Tue Nov 9 21:57:45 2010 Nobuyoshi Nakada * dln.c (init_funcname): allocate and build initialization diff --git a/cygwin/GNUmakefile.in b/cygwin/GNUmakefile.in index 025f460c9c..04005466b5 100644 --- a/cygwin/GNUmakefile.in +++ b/cygwin/GNUmakefile.in @@ -31,9 +31,16 @@ SOLIBS := $(DLL_BASE_NAME).res.@OBJEXT@ $(SOLIBS) EXTOBJS += $(if $(filter-out $(RUBYW_INSTALL_NAME),$(@:$(EXEEXT)=)),$(RUBY_INSTALL_NAME),$(@:$(EXEEXT)=)).res.$(OBJEXT) RCFILES = $(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(DLL_BASE_NAME).rc RUBYDEF = $(DLL_BASE_NAME).def +STUBPROGRAM = rubystub$(EXEEXT) +SCRIPTPROGRAMS = $(addsuffix $(EXEEXT),$(notdir $(wildcard $(srcdir)/bin/*))) ruby: $(PROGRAM) rubyw: $(WPROGRAM) +stub: $(STUBPROGRAM) +scriptbin: $(SCRIPTPROGRAMS) + +%$(EXEEXT): bin/% $(STUBPROGRAM) + { cat $(STUBPROGRAM); echo; sed -e '1{' -e '/^#!.*ruby/!i\' -e '#!/bin/ruby' -e '}' $<; } > $@ $(LIBRUBY): $(RUBY_EXP) $(LIBRUBY_SO) $(RUBY_EXP) $(LIBRUBY_SO): $(DLL_BASE_NAME).res.@OBJEXT@ @@ -52,6 +59,10 @@ $(WPROGRAM): $(RUBYW_INSTALL_NAME).res.@OBJEXT@ @rm -f $@ $(PURIFY) $(CC) -mwindows -e _mainCRTStartup $(LDFLAGS) $(XLDFLAGS) \ $(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ +$(STUBPROGRAM): $(RUBY_INSTALL_NAME).res.@OBJEXT@ stub.@OBJEXT@ + @rm -f $@ + $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) \ + stub.@OBJEXT@ $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ $(RUBY_EXP): $(LIBRUBY_A) $(DLLWRAP) \ diff --git a/ruby.c b/ruby.c index 155ef5fbfa..61e8dcc443 100644 --- a/ruby.c +++ b/ruby.c @@ -1506,6 +1506,7 @@ load_file_internal(VALUE arg) NODE *tree = 0; rb_encoding *enc; ID set_encoding; + int xflag = 0; if (!fname) rb_load_fail(fname); @@ -1517,8 +1518,10 @@ load_file_internal(VALUE arg) #if defined DOSISH || defined __CYGWIN__ { const char *ext = strrchr(fname, '.'); - if (ext && STRCASECMP(ext, ".exe") == 0) + if (ext && STRCASECMP(ext, ".exe") == 0) { mode |= O_BINARY; + xflag = 1; + } } #endif if ((fd = open(fname, mode)) < 0) { @@ -1540,7 +1543,7 @@ load_file_internal(VALUE arg) enc = rb_ascii8bit_encoding(); rb_funcall(f, set_encoding, 1, rb_enc_from_encoding(enc)); - if (opt->xflag) { + if (xflag || opt->xflag) { search_shebang: forbid_setid("-x"); opt->xflag = FALSE; @@ -1852,7 +1855,7 @@ ruby_set_argv(int argc, char **argv) #endif rb_ary_clear(av); for (i = 0; i < argc; i++) { - VALUE arg = rb_external_str_new(argv[i], strlen(argv[i])); + VALUE arg = rb_external_str_new_cstr(argv[i]); OBJ_FREEZE(arg); rb_ary_push(av, arg); diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb index eec790b3ee..908b586934 100755 --- a/tool/rbinstall.rb +++ b/tool/rbinstall.rb @@ -36,7 +36,9 @@ def parse_args(argv = ARGV) $dir_mode = nil $script_mode = nil $strip = false - $cmdtype = ('bat' if File::ALT_SEPARATOR == '\\') + $cmdtype = (if File::ALT_SEPARATOR == '\\' + File.exist?("rubystub.exe") ? 'exe' : 'bat' + end) mflags = [] opt = OptionParser.new opt.on('-n', '--dry-run') {$dryrun = true} @@ -405,6 +407,9 @@ install?(:local, :comm, :bin, :'bin-comm') do ruby_shebang = File.join(bindir, ruby_install_name) if File::ALT_SEPARATOR ruby_bin = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR) + if $cmdtype == 'exe' + stub = File.open("rubystub.exe", "rb") {|f| f.read} << "\n" rescue nil + end end if trans = CONFIG["program_transform_name"] exp = [] @@ -456,6 +461,8 @@ install?(:local, :comm, :bin, :'bin-comm') do cmd << ".#{$cmdtype}" if $cmdtype open_for_install(cmd, $script_mode) do case $cmdtype + when "exe" + stub + shebang + body when "bat" [<<-"EOH".gsub(/^\s+/, ''), shebang, body, "__END__\n:endofruby\n"].join.gsub(/$/, "\r") @echo off diff --git a/version.h b/version.h index c4d414910c..4ad4850d49 100644 --- a/version.h +++ b/version.h @@ -1,11 +1,11 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_RELEASE_DATE "2010-11-09" +#define RUBY_RELEASE_DATE "2010-11-10" #define RUBY_PATCHLEVEL -1 #define RUBY_BRANCH_NAME "trunk" #define RUBY_RELEASE_YEAR 2010 #define RUBY_RELEASE_MONTH 11 -#define RUBY_RELEASE_DAY 9 +#define RUBY_RELEASE_DAY 10 #include "ruby/version.h" diff --git a/win32/mkexports.rb b/win32/mkexports.rb index e96f9339d0..f6d40f8cfb 100755 --- a/win32/mkexports.rb +++ b/win32/mkexports.rb @@ -36,6 +36,7 @@ class Exports def initialize(objs) syms = {} winapis = {} + syms["ruby_sysinit_real"] = "ruby_sysinit" each_export(objs) do |internal, export| syms[internal] = export winapis[$1] = internal if /^_?(rb_w32_\w+)(?:@\d+)?$/ =~ internal diff --git a/win32/stub.c b/win32/stub.c new file mode 100644 index 0000000000..fc82d73e2c --- /dev/null +++ b/win32/stub.c @@ -0,0 +1,42 @@ +#include +static void stub_sysinit(int *argc, char ***argv); +#define ruby_sysinit stub_sysinit +#include +#undef ruby_sysinit + +void +stub_sysinit(int *argc, char ***argv) +{ + char exename[4096]; + size_t lenexe, len0, lenall; + int i, ac; + char **av, *p; + + lenexe = (size_t)GetModuleFileName(NULL, exename, sizeof exename); + ruby_sysinit(argc, argv); + ac = *argc; + av = *argv; + len0 = strlen(av[0]) + 1; + lenall = 0; + for (i = 1; i < ac; ++i) { + lenall += strlen(av[i]) + 1; + } + *argv = av = realloc(av, lenall + (lenexe + 1) * 2 + sizeof(char *) * (i + 2)); + *argc = ++ac; + p = (char *)(av + i + 2); + memmove(p + (lenexe + 1) * 2, (char *)(av + ac) + len0, lenall); + memcpy(p, exename, lenexe); + p[lenexe] = '\0'; + *av++ = p; + p += lenexe + 1; + memcpy(p, exename, lenexe); + p[lenexe] = '\0'; + *av++ = p; + p += lenexe + 1; + while (--i) { + *av++ = p; + p += strlen(p) + 1; + } + *av = NULL; +} + -- cgit v1.2.3