Skip to content

Commit e25d45c

Browse files
committed
Added cygpath for cygwin file paths
1 parent 04e1102 commit e25d45c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

mrblib/jruby_opts_parser.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ def parse(opts)
129129
@ruby_opts << opt
130130
else
131131
# Abort processing on first non-opt arg
132+
if JRubySupport.is_cygwin? and opt.start_with?("/")
133+
opt = JRubySupport.cygpath(opt).strip
134+
end
132135
@ruby_opts << opt
133136
@ruby_opts += opts
134137
opts.clear

src/jruby_support.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include "mruby/ext/io.h"
1010

1111
#if defined(_WIN32) || defined(_WIN64)
12+
#include <windows.h>
13+
#include <stdio.h>
14+
#include <string.h>
1215
#define SYSTEM_SHELL "cmd.exe"
1316
#define DEFAULT_JAVA_OPTS ""
1417
#define IS_WINDOWS "true"
@@ -22,12 +25,39 @@
2225
#define IS_WINDOWS "false"
2326
#endif
2427

28+
mrb_value mrb_cygpath(mrb_state *mrb)
29+
{
30+
#if defined(_WIN32) || defined(_WIN64)
31+
char *windowsPath = NULL;
32+
char psBuffer[128];
33+
FILE *pPipe;
34+
mrb_value *argv;
35+
mrb_int argc;
36+
char cmd[32*1024] = "cygpath -w -p ";
37+
38+
mrb_get_args(mrb, "*", &argv, &argc);
39+
40+
const char *cygwinPath = mrb_string_value_cstr(mrb, &argv[0]);
41+
strcat(cmd, cygwinPath);
42+
43+
if( (pPipe = _popen(cmd, "rt")) == NULL )
44+
mrb_raise(mrb, E_RUNTIME_ERROR, "Could not execute cygpath");
45+
46+
windowsPath = fgets(psBuffer, 128, pPipe);
47+
_pclose(pPipe);
48+
49+
return mrb_str_new_cstr(mrb, windowsPath);
50+
#else
51+
mrb_raise(mrb, E_RUNTIME_ERROR, "Could not execute cygpath outside of Windows");
52+
#endif
53+
}
54+
2555
mrb_bool mrb_is_windows(mrb_state *mrb)
2656
{
2757
#if defined(_WIN32) || defined(_WIN64)
2858
return TRUE;
2959
#else
30-
return NULL;
60+
return FALSE;
3161
#endif
3262
}
3363

@@ -37,6 +67,8 @@ mrb_init_jruby_support(mrb_state *mrb)
3767
struct RClass *c;
3868
c = mrb_define_class(mrb, "JRubySupport", mrb->object_class);
3969

70+
mrb_define_class_method(mrb, c, "cygpath", mrb_cygpath, MRB_ARGS_ANY());
71+
4072
mrb_define_const(mrb, c, "IS_WINDOWS", mrb_str_new_cstr(mrb, IS_WINDOWS));
4173
mrb_define_const(mrb, c, "SYSTEM_SHELL", mrb_str_new_cstr(mrb, SYSTEM_SHELL));
4274
mrb_define_const(mrb, c, "DEFAULT_JAVA_OPTS", mrb_str_new_cstr(mrb, DEFAULT_JAVA_OPTS));

0 commit comments

Comments
 (0)