1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
* rubystub.c: generalize win32/stub.c.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-08-20 02:20:34 +00:00
parent e79b23c12f
commit 9b454bfaf3
7 changed files with 99 additions and 66 deletions

View file

@ -1,3 +1,7 @@
Sat Aug 20 11:20:32 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* rubystub.c: generalize win32/stub.c.
Fri Aug 19 11:39:06 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (primary): allow parenthesised statement as a method

View file

@ -13,9 +13,6 @@ else
DLL_BASE_NAME := $(RUBY_SO_NAME)
DLLWRAP += -mno-cygwin
VPATH := $(VPATH):$(srcdir)/win32
STUBPROGRAM = rubystub$(EXEEXT)
IGNOREDPATTERNS = %~ .% %.orig %.rej \#%\#
SCRIPTPROGRAMS = $(addsuffix $(EXEEXT),$(filter-out $(IGNOREDPATTERNS),$(notdir $(wildcard $(srcdir)/bin/*))))
endif
ifneq ($(ENABLE_SHARED),yes)
@ -44,13 +41,6 @@ RUBYDEF = $(DLL_BASE_NAME).def
ruby: $(PROGRAM)
rubyw: $(WPROGRAM)
stub: $(STUBPROGRAM)
scriptbin: $(SCRIPTPROGRAMS)
%$(EXEEXT): bin/% $(STUBPROGRAM)
$(ECHO) generating $@
$(Q) { cat $(STUBPROGRAM); echo; sed -e '1{' -e '/^#!.*ruby/!i\' -e '#!/bin/ruby' -e '}' $<; } > $@
$(Q) chmod +x $@
$(LIBRUBY): $(RUBY_EXP) $(LIBRUBY_SO)
$(RUBY_EXP) $(LIBRUBY_SO): $(DLL_BASE_NAME).res.@OBJEXT@
@ -72,12 +62,7 @@ $(WPROGRAM): $(RUBYW_INSTALL_NAME).res.@OBJEXT@
$(ECHO) linking $@
$(Q) $(PURIFY) $(CC) -mwindows -e $(SYMBOL_PREFIX)mainCRTStartup $(LDFLAGS) $(XLDFLAGS) \
$(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@
$(STUBPROGRAM): $(RUBY_INSTALL_NAME).res.@OBJEXT@ win32/stub.@OBJEXT@
@rm -f $@
$(ECHO) linking $@
$(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) \
win32/stub.@OBJEXT@ $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@
$(if $(STRIP),$(Q) $(STRIP) $@)
$(STUBPROGRAM): $(RUBY_INSTALL_NAME).res.@OBJEXT@
$(RUBY_EXP): $(LIBRUBY_A)
$(ECHO) creating $@

View file

@ -92,3 +92,36 @@ else
$(Q) mv $@.new $@
$(Q) $(RMALL) make_des_table*
endif
STUBPROGRAM = rubystub$(EXEEXT)
IGNOREDPATTERNS = %~ .% %.orig %.rej \#%\#
SCRIPTBINDIR := $(if $(EXEEXT),,exec/)
SCRIPTPROGRAMS = $(addprefix $(SCRIPTBINDIR),$(addsuffix $(EXEEXT),$(filter-out $(IGNOREDPATTERNS),$(notdir $(wildcard $(srcdir)/bin/*)))))
stub: $(STUBPROGRAM)
scriptbin: $(SCRIPTPROGRAMS)
ifneq ($(STUBPROGRAM),rubystub)
rubystub: $(STUBPROGRAM)
endif
$(SCRIPTPROGRAMS): $(STUBPROGRAM)
$(STUBPROGRAM): rubystub.$(OBJEXT) $(LIBRUBY) $(MAINOBJ) $(OBJS) $(EXTOBJS) $(SETUP) $(PREP)
rubystub$(EXEEXT):
@rm -f $@
$(ECHO) linking $@
$(Q) $(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) rubystub.$(OBJEXT) $(EXTOBJS) $(LIBRUBYARG) $(MAINLIBS) $(LIBS) $(EXTLIBS) $(OUTFLAG)$@
$(Q) $(POSTLINK)
$(if $(STRIP),$(Q) $(STRIP) $@)
$(SCRIPTBINDIR)%$(EXEEXT): bin/% $(STUBPROGRAM) \
$(if $(SCRIPTBINDIR),$(TIMESTAMPDIR)/.exec.time)
$(ECHO) generating $@
$(Q) { cat $(STUBPROGRAM); echo; sed -e '1{' -e '/^#!.*ruby/!i\' -e '#!/bin/ruby' -e '}' $<; } > $@
$(Q) chmod +x $@
$(Q) $(POSTLINK)
$(TIMESTAMPDIR)/.exec.time:
$(Q) mkdir exec
$(Q) exit > $@

View file

@ -35,6 +35,7 @@
#include "ruby.h"
#include "ruby/util.h"
#define compat_init_setproctitle ruby_init_setproctitle
RUBY_FUNC_EXPORTED void ruby_init_setproctitle(int argc, char *argv[]);
#ifndef HAVE_SETPROCTITLE

57
rubystub.c Normal file
View file

@ -0,0 +1,57 @@
#include "internal.h"
#if defined HAVE_DLADDR
#include <dlfcn.h>
#endif
static void* stub_options(int argc, char **argv);
#define ruby_options stub_options
#include <main.c>
#undef ruby_options
void *
stub_options(int argc, char **argv)
{
char xflag[] = "-x";
char *xargv[4] = {NULL, xflag};
char *cmd = argv[0];
void *ret;
#if defined __CYGWIN__ || defined _WIN32
/* GetCommandLineW should contain the accessible path,
* use argv[0] as is */
#elif defined __linux__
{
char selfexe[MAXPATHLEN];
ssize_t len = readlink("/proc/self/exe", selfexe, sizeof(selfexe));
if (len < 0) {
perror("readlink(\"/proc/self/exe\")");
return NULL;
}
selfexe[len] = '\0';
cmd = selfexe;
}
#elif defined HAVE_DLADDR
{
Dl_info dli;
if (!dladdr(stub_options, &dli)) {
perror("dladdr");
return NULL;
}
cmd = (char *)dli.dli_fname;
}
#endif
#ifndef HAVE_SETPROCTITLE
/* argc and argv must be the original */
ruby_init_setproctitle(argc, argv);
#endif
/* set script with -x option */
/* xargv[0] is NULL not to re-initialize setproctitle again */
xargv[2] = cmd;
ret = ruby_options(3, xargv);
/* set all arguments to ARGV */
ruby_set_argv(argc - 1, argv + 1);
return ret;
}

View file

@ -418,6 +418,7 @@ prog: config
ruby: $(PROGRAM)
rubyw: $(WPROGRAM)
stub: $(STUBPROGRAM)
rubystub: $(STUBPROGRAM)
!if !exist(enc/trans/newline.c) && exist($(srcdir)/enc/trans/newline.c)
NEWLINE_C = $(srcdir)/enc/trans/newline.c
@ -1005,9 +1006,9 @@ $(WPROGRAM): $(MAINOBJ) $(WINMAINOBJ) $(LIBRUBY_SO) $(RUBYW_INSTALL_NAME).res
!endif
!if "$(STUBPROGRAM)" != ""
$(STUBPROGRAM): win32/stub.$(OBJEXT) $(LIBRUBY) $(LIBRUBY_SO) $(RUBY_INSTALL_NAME).res
$(STUBPROGRAM): rubystub.$(OBJEXT) $(LIBRUBY) $(LIBRUBY_SO) $(RUBY_INSTALL_NAME).res
$(ECHO) linking $(@:\=/)
$(Q) $(PURIFY) $(CC) win32/stub.$(OBJEXT) $(RUBY_INSTALL_NAME).res \
$(Q) $(PURIFY) $(CC) rubystub.$(OBJEXT) $(RUBY_INSTALL_NAME).res \
$(OUTFLAG)$@ $(LIBRUBYARG) -link $(LDFLAGS) $(XLDFLAGS)
$(Q) $(LDSHARED_0)
$(Q) $(LDSHARED_1)

View file

@ -1,48 +0,0 @@
#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)
{
WCHAR exename[4096];
size_t wlenexe, len0, lenall;
int lenexe;
int i, ac;
char **av, *p;
wlenexe = (size_t)GetModuleFileNameW(NULL, exename, sizeof(exename) / sizeof(*exename));
lenexe = WideCharToMultiByte(CP_UTF8, 0, exename, wlenexe, NULL, 0, NULL, NULL);
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;
}
av = realloc(av, lenall + len0 + (lenexe + 1) + sizeof(char *) * (i + 2));
if (!av) {
perror("realloc command line");
exit(-1);
}
*argv = av;
*argc = ++ac;
p = (char *)(av + i + 2);
memmove(p + len0 + lenexe + 1, (char *)(av + ac) + len0, lenall);
memmove(p, (char *)(av + ac), len0);
*av++ = p;
p += len0;
WideCharToMultiByte(CP_UTF8, 0, exename, wlenexe, p, lenexe, NULL, NULL);
p[lenexe] = '\0';
*av++ = p;
p += lenexe + 1;
while (--i) {
*av++ = p;
p += strlen(p) + 1;
}
*av = NULL;
}