[前][次][番号順一覧][スレッド一覧]

ruby-changes:17727

From: nobu <ko1@a...>
Date: Wed, 10 Nov 2010 07:20:31 +0900 (JST)
Subject: [ruby-changes:17727] Ruby:r29738 (trunk): * cygwin/GNUmakefile.in (scriptbin): make executable file from

nobu	2010-11-10 07:20:12 +0900 (Wed, 10 Nov 2010)

  New Revision: 29738

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29738

  Log:
    * 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]

  Added files:
    trunk/win32/stub.c
  Modified files:
    trunk/ChangeLog
    trunk/cygwin/GNUmakefile.in
    trunk/ruby.c
    trunk/tool/rbinstall.rb
    trunk/version.h
    trunk/win32/mkexports.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29737)
+++ ChangeLog	(revision 29738)
@@ -1,3 +1,18 @@
+Wed Nov 10 07:20:10 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <nobu@r...>
 
 	* dln.c (init_funcname): allocate and build initialization
Index: cygwin/GNUmakefile.in
===================================================================
--- cygwin/GNUmakefile.in	(revision 29737)
+++ cygwin/GNUmakefile.in	(revision 29738)
@@ -31,10 +31,17 @@
 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 @@
 	@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) \
Index: win32/mkexports.rb
===================================================================
--- win32/mkexports.rb	(revision 29737)
+++ win32/mkexports.rb	(revision 29738)
@@ -36,6 +36,7 @@
   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
Index: win32/stub.c
===================================================================
--- win32/stub.c	(revision 0)
+++ win32/stub.c	(revision 29738)
@@ -0,0 +1,42 @@
+#include <ruby.h>
+static void stub_sysinit(int *argc, char ***argv);
+#define ruby_sysinit stub_sysinit
+#include <main.c>
+#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;
+}
+

Property changes on: win32/stub.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: version.h
===================================================================
--- version.h	(revision 29737)
+++ version.h	(revision 29738)
@@ -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"
 
Index: ruby.c
===================================================================
--- ruby.c	(revision 29737)
+++ ruby.c	(revision 29738)
@@ -1506,6 +1506,7 @@
     NODE *tree = 0;
     rb_encoding *enc;
     ID set_encoding;
+    int xflag = 0;
 
     if (!fname)
 	rb_load_fail(fname);
@@ -1517,8 +1518,10 @@
 #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 @@
 	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 @@
 #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);
Index: tool/rbinstall.rb
===================================================================
--- tool/rbinstall.rb	(revision 29737)
+++ tool/rbinstall.rb	(revision 29738)
@@ -36,7 +36,9 @@
   $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 @@
   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 @@
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]