Skip to content

Commit 4e4c31f

Browse files
committed
Only check the working directory if needed in FeatureLoader
* Otherwise it is not possible to initialize TruffleRuby in a Context with no IO and no native permissions. #require is called in post-boot.rb. (cherry picked from commit 0e3b021)
1 parent a06117d commit 4e4c31f

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/main/ruby/truffleruby/core/truffle/feature_loader.rb

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ module FeatureLoader
2121
@expanded_load_path = []
2222
# A snapshot of $LOAD_PATH, to check if the @expanded_load_path cache is up to date.
2323
@load_path_copy = []
24-
@working_directory_copy = ''
24+
@relative_path_in_load_path = false
25+
@working_directory_copy = nil
2526

2627
def self.clear_cache
2728
@loaded_features_index.clear
2829
@loaded_features_copy.clear
2930
@expanded_load_path.clear
3031
@load_path_copy.clear
31-
@working_directory_copy.clear
32+
@working_directory_copy = nil
3233
end
3334

3435
class FeatureEntry
@@ -280,13 +281,33 @@ def self.features_index_add(feature, offset)
280281
end
281282

282283
def self.get_expanded_load_path
283-
unless Primitive.array_storage_equal?(@load_path_copy, $LOAD_PATH) && Primitive.working_directory == @working_directory_copy
284-
@expanded_load_path = $LOAD_PATH.map { |path| Primitive.canonicalize_path(Truffle::Type.coerce_to_path(path)) }
284+
unless Primitive.array_storage_equal?(@load_path_copy, $LOAD_PATH) && same_working_directory_for_load_path?
285+
@expanded_load_path = $LOAD_PATH.map do |path|
286+
path = Truffle::Type.coerce_to_path(path)
287+
unless @relative_path_in_load_path
288+
unless File.absolute_path?(path)
289+
@working_directory_copy = Primitive.working_directory
290+
@relative_path_in_load_path = true
291+
end
292+
end
293+
Primitive.canonicalize_path(path)
294+
end
285295
@load_path_copy = $LOAD_PATH.dup
286-
@working_directory_copy = Primitive.working_directory
287296
end
288297
@expanded_load_path
289298
end
290299

300+
def self.same_working_directory_for_load_path?
301+
if @relative_path_in_load_path
302+
if Primitive.working_directory == @working_directory_copy
303+
true
304+
else
305+
@working_directory_copy = Primitive.working_directory
306+
false
307+
end
308+
else
309+
true # no relative path in $LOAD_PATH, no need to check the working directory
310+
end
311+
end
291312
end
292313
end

0 commit comments

Comments
 (0)