summaryrefslogtreecommitdiff
path: root/ruby-runner.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-22 06:03:18 (GMT)
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-22 07:01:38 (GMT)
commitc7b71af9e21b3f0b8fe413a3c20cf4bd633c40d0 (patch)
treeea4cc957b4c2291669d844f44b38c445e2ae2727 /ruby-runner.c
parentf744d80106ad236cb517c3a6eae5e591562e2377 (diff)
Prefer `exe/ruby` to execute from it
Diffstat (limited to 'ruby-runner.c')
-rw-r--r--ruby-runner.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/ruby-runner.c b/ruby-runner.c
index d41ba27..7e0ed6e 100644
--- a/ruby-runner.c
+++ b/ruby-runner.c
@@ -17,7 +17,7 @@ const char MJIT_HEADER[] = BUILDDIR "/" MJIT_MIN_HEADER;
#define STRINGIZE0(expr) #expr
static void
-insert_env_path(const char *envname, const char *paths, size_t size, int prepend)
+insert_env_path(const char *envname, const char *paths, size_t size, int prepend, int add)
{
const char *env = getenv(envname);
char c = 0;
@@ -28,6 +28,9 @@ insert_env_path(const char *envname, const char *paths, size_t size, int prepend
n = strlen(env);
while (n > 0 && env[n-1] == PATH_SEP) --n;
}
+ else if (!add) {
+ return;
+ }
if (c) {
char *e = malloc(size+n+1);
size_t pos = 0;
@@ -56,6 +59,7 @@ int
main(int argc, char **argv)
{
static const char builddir[] = BUILDDIR;
+ static const char exedir[] = BUILDDIR"/"STRINGIZE(RUBY_RUNNER_PATH);
static const char rubypath[] = BUILDDIR"/"STRINGIZE(RUBY_INSTALL_NAME);
static const char rubylib[] =
ABS_SRCDIR"/lib"
@@ -73,11 +77,12 @@ main(int argc, char **argv)
const char *rubyname = rubypath + dirsize;
char *arg0 = argv[0], *p;
- insert_env_path(LIBPATHENV, builddir, dirsize, 1);
- insert_env_path("RUBYLIB", rubylib, sizeof(rubylib), 0);
+ insert_env_path(LIBPATHENV, builddir, dirsize, 1, 1);
+ insert_env_path("RUBYLIB", rubylib, sizeof(rubylib), 0, 1);
+ insert_env_path("PATH", exedir, sizeof(exedir), 1, 0);
#ifndef LOAD_RELATIVE
if (PRELOADENV[0] && stat(mjit_build_dir, &stbuf) == 0) {
- insert_env_path(PRELOADENV, mjit_build_dir, sizeof(mjit_build_dir), 1);
+ insert_env_path(PRELOADENV, mjit_build_dir, sizeof(mjit_build_dir), 1, 1);
setenv("MJIT_SEARCH_BUILD_DIR", "true", 0);
}
#endif