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

ruby-changes:47887

From: nobu <ko1@a...>
Date: Sun, 24 Sep 2017 10:48:30 +0900 (JST)
Subject: [ruby-changes:47887] nobu:r60006 (trunk): ruby-runner.c: RUBYLIB

nobu	2017-09-24 10:48:25 +0900 (Sun, 24 Sep 2017)

  New Revision: 60006

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60006

  Log:
    ruby-runner.c: RUBYLIB
    
    * ruby-runner.c (insert_env_path): extracted the function which
      insert path list to an environment variable.
    
    * ruby-runner.c (main): append library paths to RUBYLIB.

  Modified files:
    trunk/ruby-runner.c
    trunk/template/ruby-runner.h.in
Index: template/ruby-runner.h.in
===================================================================
--- template/ruby-runner.h.in	(revision 60005)
+++ template/ruby-runner.h.in	(revision 60006)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/template/ruby-runner.h.in#L1
+#define ABS_SRCDIR "@abs_srcdir@"
 #define BUILDDIR   "@abs_top_builddir@"
 #define LIBPATHENV "@LIBPATHENV@"
+#define PATH_SEPARATOR "@PATH_SEPARATOR@"
 #define PATH_SEP   '@PATH_SEPARATOR@'
+#define EXTOUT     "@EXTOUT@"
+#define ARCH       "@arch@"
Index: ruby-runner.c
===================================================================
--- ruby-runner.c	(revision 60005)
+++ ruby-runner.c	(revision 60006)
@@ -8,33 +8,61 @@ https://github.com/ruby/ruby/blob/trunk/ruby-runner.c#L8
 #define STRINGIZE(expr) STRINGIZE0(expr)
 #define STRINGIZE0(expr) #expr
 
+static void
+insert_env_path(const char *envname, const char *paths, size_t size, int prepend)
+{
+    const char *env = getenv(envname);
+    char c = 0;
+    size_t n = 0;
+
+    if (env) {
+	while ((c = *env) == PATH_SEP) ++env;
+	n = strlen(env);
+	while (n > 0 && env[n-1] == PATH_SEP) --n;
+    }
+    if (c) {
+	char *e = malloc(size+n+1);
+	size_t pos = 0;
+	if (prepend) {
+	    memcpy(e, paths, pos = size-1);
+	    e[pos++] = PATH_SEP;
+	}
+	memcpy(e+pos, env, n);
+	pos += n;
+	if (!prepend) {
+	    e[pos++] = PATH_SEP;
+	    memcpy(e+pos, paths, size-1);
+	    pos += size-1;
+	}
+	e[pos] = '\0';
+	env = e;
+    }
+    else {
+	env = paths;
+    }
+    setenv(envname, env, 1);
+}
+
+#define EXTOUT_DIR BUILDDIR"/"EXTOUT
 int
 main(int argc, char **argv)
 {
     static const char builddir[] = BUILDDIR;
     static const char rubypath[] = BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME);
+    static const char rubylib[] =
+	ABS_SRCDIR"/lib"
+	PATH_SEPARATOR
+	EXTOUT_DIR"/common"
+	PATH_SEPARATOR
+	EXTOUT_DIR"/"ARCH
+	;
     const size_t dirsize = sizeof(builddir);
     const size_t namesize = sizeof(rubypath) - dirsize;
     const char *rubyname = rubypath + dirsize;
     char *arg0 = argv[0], *p;
-    const char *libpath = getenv(LIBPATHENV);
-    char c = 0;
 
-    if (libpath) {
-	while ((c = *libpath) == PATH_SEP) ++libpath;
-    }
-    if (c) {
-	size_t n = strlen(libpath);
-	char *e = malloc(dirsize+n+1);
-	memcpy(e, builddir, dirsize-1);
-	e[dirsize-1] = PATH_SEP;
-	memcpy(e+dirsize, libpath, n+1);
-	libpath = e;
-    }
-    else {
-	libpath = builddir;
-    }
-    setenv(LIBPATHENV, libpath, 1);
+    insert_env_path(LIBPATHENV, builddir, dirsize, 1);
+    insert_env_path("RUBYLIB", rubylib, sizeof(rubylib), 0);
 
     if (!(p = strrchr(arg0, '/'))) p = arg0; else p++;
     if (strlen(p) < namesize - 1) {

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

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