Skip to content

Commit

Permalink
Pathname()->Pathname.new()
Browse files Browse the repository at this point in the history
  • Loading branch information
shinokaro committed May 29, 2024
1 parent 52f75d3 commit 07bc407
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ module Ocran
require_relative "../lib/ocran/refine_pathname"
using RefinePathname

def self.Pathname(obj)
if obj.is_a?(Pathname)
obj
else
Pathname.new(obj)
end
end

IGNORE_MODULE_NAMES = /\A(enumerator.so|rational.so|complex.so|fiber.so|thread.rb|ruby2_keywords.rb)\z/

GEM_SCRIPT_RE = /\.rbw?$/
Expand Down Expand Up @@ -394,7 +386,7 @@ EOF
features.each do |feature|
# Detect load path unless absolute
if not feature.absolute?
feature = find_load_path($LOAD_PATH.map { |path| Pathname(path) }, feature)
feature = find_load_path($LOAD_PATH.map { |path| Pathname.new(path) }, feature)
next if feature.nil? # Could be enumerator.so
end
# Skip if found in known Gem dir
Expand All @@ -404,11 +396,11 @@ EOF
end
gempaths = Gem.path
gempaths.each do |gempath|
geminstallpath = Pathname(gempath) / "gems"
geminstallpath = Pathname.new(gempath) / "gems"
if feature.subpath?(geminstallpath)
gemlocalpath = feature.relative_path_from(geminstallpath)
fullgemname = gemlocalpath.to_s.split(Pathname::SEPARATOR_PAT).first
gemspecpath = Pathname(gempath) / "specifications" / "#{fullgemname}.gemspec"
gemspecpath = Pathname.new(gempath) / "specifications" / "#{fullgemname}.gemspec"
if spec = Gem::Specification.load(gemspecpath.to_s)
gems[spec.name] ||= spec
features_from_gems << feature
Expand All @@ -423,13 +415,13 @@ EOF

gems.each do |gemname, spec|
if File.exist?(spec.spec_file) then
@gemspecs << Pathname(spec.spec_file)
@gemspecs << Pathname.new(spec.spec_file)
else
spec_name = File.basename(spec.spec_file)
spec_path = File.dirname(spec.spec_file)
default_spec_file = spec_path + "/default/" + spec_name
if File.exist?(default_spec_file) then
@gemspecs << Pathname(default_spec_file)
@gemspecs << Pathname.new(default_spec_file)
Ocran.msg "Using default specification #{default_spec_file} for gem #{spec.full_name}"
end
end
Expand Down Expand Up @@ -473,7 +465,7 @@ EOF

Ocran.msg "Detected gem #{spec.full_name} (#{include.join(", ")})"

gem_root = Pathname(spec.gem_dir)
gem_root = Pathname.new(spec.gem_dir)
unless gem_root.directory?
Ocran.warn "Gem #{spec.full_name} root folder was not found, skipping"
next
Expand All @@ -492,7 +484,7 @@ EOF
include.each do |set|
case set
when :spec
files << spec.files.map { |file| Pathname(file) }
files << spec.files.map { |file| Pathname.new(file) }
when :loaded
files << features_from_gems.select { |feature| feature.subpath?(gem_root) }
when :files
Expand Down Expand Up @@ -536,8 +528,8 @@ EOF
end

def Ocran.build_exe
all_load_paths = $LOAD_PATH.map { |loadpath| Pathname(loadpath).expand_path }
@added_load_paths = ($LOAD_PATH - @load_path_before).map { |loadpath| Pathname(loadpath).expand_path }
all_load_paths = $LOAD_PATH.map { |loadpath| Pathname.new(loadpath).expand_path }
@added_load_paths = ($LOAD_PATH - @load_path_before).map { |loadpath| Pathname.new(loadpath).expand_path }
working_directory = Pathname.pwd

restore_environment
Expand All @@ -549,18 +541,18 @@ EOF

# Store the currently loaded files (before we require rbconfig for
# our own use).
features = $LOADED_FEATURES.map { |feature| Pathname(feature) }
features = $LOADED_FEATURES.map { |feature| Pathname.new(feature) }

# Since https://github.com/rubygems/rubygems/commit/cad4cf16cf8fcc637d9da643ef97cf0be2ed63cb
# rubygems/core_ext/kernel_require.rb is evaled and thus missing in $LOADED_FEATURES, so we can't find it and need to add it manually
features.push(Pathname("rubygems/core_ext/kernel_require.rb"))
features.push(Pathname.new("rubygems/core_ext/kernel_require.rb"))

# Find gemspecs to include
if defined?(Gem)
# Since Bundler is integrated into RubyGems from Ruby 3.2 onwards,
# Bundler's loaded_from points to the root directory of the bundler gem.
# Here, we are only collecting gemspecs files.
@gemspecs = Gem.loaded_specs.map { |name, info| Pathname(info.loaded_from) }.reject(&:directory?)
@gemspecs = Gem.loaded_specs.map { |name, info| Pathname.new(info.loaded_from) }.reject(&:directory?)
else
@gemspecs = []
end
Expand Down Expand Up @@ -613,7 +605,7 @@ EOF
elsif defined?(Gem) and gemhome = Gem.path.find { |pth| fullpath.subpath?(pth) }
# Features found in any other Gem path (e.g. ~/.gems) is put
# in a special 'gemhome' folder.
libs << [fullpath, GEMHOMEDIR / fullpath.relative_path_from(Pathname(gemhome))]
libs << [fullpath, GEMHOMEDIR / fullpath.relative_path_from(Pathname.new(gemhome))]
elsif fullpath.subpath?(src_prefix) || path == working_directory
# Any feature found inside the src_prefix automatically gets
# added as a source file (to go in 'src').
Expand Down Expand Up @@ -651,7 +643,7 @@ EOF
if gemfile.subpath?(exec_prefix)
libs << [gemfile, gemfile.relative_path_from(exec_prefix)]
elsif defined?(Gem) and gemhome = Gem.path.find { |pth| gemfile.subpath?(pth) }
libs << [gemfile, GEMHOMEDIR / gemfile.relative_path_from(Pathname(gemhome))]
libs << [gemfile, GEMHOMEDIR / gemfile.relative_path_from(Pathname.new(gemhome))]
else
Ocran.fatal_error "Don't know where to put gemfile #{gemfile}"
end
Expand Down Expand Up @@ -743,7 +735,7 @@ EOF
if gemspec.subpath?(exec_prefix)
sb.create_file(gemspec, gemspec.relative_path_from(exec_prefix))
elsif defined?(Gem) and gemhome = Gem.path.find { |pth| gemspec.subpath?(pth) }
sb.create_file(gemspec, GEMHOMEDIR / gemspec.relative_path_from(Pathname(gemhome)))
sb.create_file(gemspec, GEMHOMEDIR / gemspec.relative_path_from(Pathname.new(gemhome)))
else
Ocran.fatal_error "Gem spec #{gemspec} does not exist in the Ruby installation. Don't know where to put it."
end
Expand All @@ -758,7 +750,7 @@ EOF
# Workaround: RubyInstaller cannot find the msys folder if ../msys64/usr/bin/msys-2.0.dll is not present (since RubyInstaller-2.4.1 rubyinstaller 2 issue 23)
# Add an empty file to /msys64/usr/bin/msys-2.0.dll if the dll was not required otherwise
unless sb.files.values.any? { |entry, _src| entry.to_s.include?("msys-2.0.dll") }
sb.create_file(Pathname(File.dirname(__FILE__)) / "../share/ocran/empty-msys-2.0.dll", 'msys64/usr/bin/msys-2.0.dll')
sb.create_file(Pathname.new(File.dirname(__FILE__)) / "../share/ocran/empty-msys-2.0.dll", 'msys64/usr/bin/msys-2.0.dll')
end

# Set environment variable
Expand Down

0 comments on commit 07bc407

Please sign in to comment.