Skip to content

Commit 15f6bee

Browse files
committed
Solve issues with ruby loader.
1 parent f468fc9 commit 15f6bee

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

source/cli/metacallcli/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,21 @@ if(OPTION_BUILD_LOADERS AND OPTION_BUILD_LOADERS_PY)
416416
)
417417
endif()
418418

419+
if(OPTION_BUILD_LOADERS AND OPTION_BUILD_LOADERS_RB)
420+
add_test(NAME ${target}-rb-simplest
421+
COMMAND $<TARGET_FILE:${target}> simplest.rb
422+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
423+
)
424+
set_tests_properties(${target}-rb-simplest PROPERTIES
425+
LABELS ${target}-rb-simplest
426+
PASS_REGULAR_EXPRESSION "Hello from Ruby"
427+
)
428+
test_environment_variables(${target}-rb-simplest
429+
""
430+
${TESTS_ENVIRONMENT_VARIABLES}
431+
)
432+
endif()
433+
419434
if(OPTION_BUILD_LOADERS AND OPTION_BUILD_LOADERS_TS AND OPTION_BUILD_SCRIPTS AND OPTION_BUILD_SCRIPTS_TS)
420435
add_test(NAME ${target}-ts
421436
COMMAND ${CMAKE_COMMAND} -D "EXECUTABLE=$<TARGET_FILE:${target}>" -D "INPUT=${TEST_COMMAND_INPUT}-ts.txt" -P ${TEST_COMMAND_RUNNER}

source/loaders/rb_loader/source/rb_loader_impl.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,12 @@ loader_handle rb_loader_impl_load_from_file(loader_impl impl, const loader_path
12371237

12381238
module_data = rb_loader_impl_load_data(impl, paths[0]);
12391239

1240+
if (module_data == Qnil)
1241+
{
1242+
log_write("metacall", LOG_LEVEL_ERROR, "Ruby module not found: %s", paths[0]);
1243+
goto load_error;
1244+
}
1245+
12401246
result = rb_eval_string_protect(StringValuePtr(module_data), &state);
12411247

12421248
if (state != 0)
@@ -1246,7 +1252,17 @@ loader_handle rb_loader_impl_load_from_file(loader_impl impl, const loader_path
12461252
goto load_error;
12471253
}
12481254

1249-
module_name = rb_funcall(result, rb_intern("name"), 0);
1255+
if (result == Qnil)
1256+
{
1257+
loader_path name;
1258+
size_t size = portability_path_get_name(paths[0], strnlen(paths[0], LOADER_PATH_SIZE), name, LOADER_PATH_SIZE);
1259+
1260+
module_name = rb_str_new(name, size);
1261+
}
1262+
else
1263+
{
1264+
module_name = rb_funcall(result, rb_intern("name"), 0);
1265+
}
12501266

12511267
rb_module = rb_loader_impl_create_module(module_name, result, module_data, result);
12521268

source/scripts/ruby/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ add_subdirectory(ducktype)
2121
add_subdirectory(invalid)
2222
add_subdirectory(klass)
2323
add_subdirectory(failempty)
24+
add_subdirectory(simplest)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Configure ruby project
3+
#
4+
5+
rb_project(simplest 0.1.0)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/ruby
2+
3+
print("Hello from Ruby")

0 commit comments

Comments
 (0)