module RubyInstaller::Build::Utils
Constants
- GEM_ROOT
- WINDOWS_CMD_SHEBANG
Public Instance Methods
eval_file(filename)
click to toggle source
# File lib/ruby_installer/build/utils.rb, line 90 def eval_file(filename) code = File.read(filename, encoding: "UTF-8") instance_eval(code, filename) end
gem_expand_file(rel_file)
click to toggle source
Returns the absolute path of rel_file within the gem root directory.
Raises Errno::ENOENT if it doesn't exist.
# File lib/ruby_installer/build/utils.rb, line 82 def gem_expand_file(rel_file) if File.exist?(a=File.join(GEM_ROOT, rel_file)) File.expand_path(a) else raise Errno::ENOENT, rel_file end end
msys_sh(cmd)
click to toggle source
# File lib/ruby_installer/build/utils.rb, line 15 def msys_sh(cmd) Build.enable_msys_apps pwd = Dir.pwd sh "sh", "-lc", "cd `cygpath -u #{pwd.inspect}`; #{cmd}" end
ovl_compile_erb(erb_file_rel)
click to toggle source
# File lib/ruby_installer/build/utils.rb, line 100 def ovl_compile_erb(erb_file_rel) ErbCompiler.new(erb_file_rel).result end
ovl_expand_file(rel_file)
click to toggle source
Returns the absolute path of rel_file within the current directory or, if it doesn't exist, from the gem root directory.
Raises Errno::ENOENT if neither of them exist.
# File lib/ruby_installer/build/utils.rb, line 69 def ovl_expand_file(rel_file) if File.exist?(rel_file) File.expand_path(rel_file) elsif File.exist?(a=File.join(GEM_ROOT, rel_file)) File.expand_path(a) else raise Errno::ENOENT, rel_file end end
ovl_glob(rel_pattern)
click to toggle source
Scan the current and the gem root directory for files matching rel_pattern.
All paths returned are relative.
# File lib/ruby_installer/build/utils.rb, line 57 def ovl_glob(rel_pattern) gem_files = Dir.glob(File.join(GEM_ROOT, rel_pattern)).map do |path| path.sub(GEM_ROOT+"/", "") end (gem_files + Dir.glob(rel_pattern)).uniq end
ovl_read_file(file_rel)
click to toggle source
# File lib/ruby_installer/build/utils.rb, line 96 def ovl_read_file(file_rel) File.read(ovl_expand_file(file_rel), encoding: "UTF-8") end
q_inno(text)
click to toggle source
Quote a string according to the rules of Inno-Setup
# File lib/ruby_installer/build/utils.rb, line 105 def q_inno(text) '"' + text.to_s.gsub('"', '""') + '"' end
rubyinstaller_build_gem_files()
click to toggle source
Return the gem files of “rubyinstaller-build”
The gemspec is either already loaded or taken from our root directory.
# File lib/ruby_installer/build/utils.rb, line 40 def rubyinstaller_build_gem_files spec = Gem.loaded_specs["rubyinstaller-build"] if spec # A loaded gemspec has empty #files -> fetch the files from it's path. # This is preferred to gemspec loading to avoid a dependency to git. Dir["**/*", base: spec.full_gem_path].select do |f| FileTest.file?(File.join(spec.full_gem_path, f)) end else # Not yet loaded -> load the gemspec and return the files added to the gemspec. Gem::Specification.load(File.join(GEM_ROOT, "rubyinstaller-build.gemspec")).files end end
with_env(hash) { || ... }
click to toggle source
# File lib/ruby_installer/build/utils.rb, line 21 def with_env(hash) olds = hash.map{|k, _| [k, ENV[k.to_s]] } hash.each do |k, v| ENV[k.to_s] = v end begin yield ensure olds.each do |k, v| ENV[k.to_s] = v end end end