Module: RubyInstaller::Build::Utils
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/ruby_installer/build/utils.rb |
Constant Summary
-
GEM_ROOT =
# File 'lib/ruby_installer/build/utils.rb', line 42File. ("../../../..", __FILE__)
-
WINDOWS_CMD_SHEBANG =
# File 'lib/ruby_installer/build/utils.rb', line 4<<-EOT.freeze :""||{ ""=> %q<-*- ruby -*- @"%~dp0ruby" -x "%~f0" %* @exit /b %ERRORLEVEL% };{ # bindir="${0%/*}" # exec "$bindir/ruby" -x "$0" "$@" # >, # } # EOT
Instance Method Summary
- #eval_file(filename)
-
#file(name, *args, &block)
Extend rake’s file task to be defined only once and to check the expected file is indeed generated.
- #msys_sh(cmd)
-
#ovl_expand_file(rel_file)
Returns the absolute path of
rel_file
within the current directory or, if it doesn’t exist, from the gem root directory. -
#ovl_glob(rel_pattern)
Scan the current and the gem root directory for files matching
rel_pattern
. -
#ovl_read_file(rel_file)
Read
rel_file
from the current directory or, if it doesn’t exist, from the gem root directory. -
#q_inno(text)
Quote a string according to the rules of Inno-Setup.
-
#rubyinstaller_build_gem_files
Return the gem files of “rubyinstaller-build”.
-
#task(name, *args, &block)
Extend rake’s task definition to be defined only once, even if called several times.
- #with_env(hash)
- #with_sandbox_ruby
- #task_once(name, block) private
Instance Method Details
#eval_file(filename)
[ GitHub ]# File 'lib/ruby_installer/build/utils.rb', line 86
def eval_file(filename) code = File.read(filename, encoding: "UTF-8") instance_eval(code, filename) end
#file(name, *args, &block)
Extend rake’s file task to be defined only once and to check the expected file is indeed generated
The same as #task, but for #file. In addition this file task raises an error, if the file that is expected to be generated is not present after the block was executed.
# File 'lib/ruby_installer/build/utils.rb', line 108
def file(name, *args, &block) task_once(name, block) do super(name, *args) do |ta| block&.call(ta).tap do raise "file #{ta.name} is missing after task executed" unless File.exist?(ta.name) end end end end
#msys_sh(cmd)
[ GitHub ]# 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_expand_file(rel_file)
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 76
def (rel_file) if File.exist?(rel_file) File. (rel_file) elsif File.exist?(a=File.join(GEM_ROOT, rel_file)) File. (a) else raise Errno::ENOENT, rel_file end end
#ovl_glob(rel_pattern)
Scan the current and the gem root directory for files matching rel_pattern
.
All paths returned are relative.
#ovl_read_file(rel_file)
Read rel_file
from the current directory or, if it doesn’t exist, from the gem root directory. Raises Errno::ENOENT if neither of them exist.
Returns the file content as String with UTF-8 encoding.
# File 'lib/ruby_installer/build/utils.rb', line 95
def ovl_read_file(rel_file) File.read( (rel_file), encoding: "UTF-8") end
#q_inno(text)
Quote a string according to the rules of Inno-Setup
# File 'lib/ruby_installer/build/utils.rb', line 100
def q_inno(text) '"' + text.to_s.gsub('"', '""') + '"' end
#rubyinstaller_build_gem_files
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 47
def spec = Gem.loaded_specs["rubyinstaller-build"] if spec # A loaded gemspec has empty #files -> fetch the files from its 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
#task(name, *args, &block)
Extend rake’s task definition to be defined only once, even if called several times
This allows to define common tasks next to specific tasks. It is expected that any variation of the task’s block is reflected in the task name or namespace. If the task name is identical, the task block is executed only once, even if the file task definition is executed twice.
# File 'lib/ruby_installer/build/utils.rb', line 123
def task(name, *args, &block) task_once(name, block) do super end end
#task_once(name, block) (private)
[ GitHub ]# File 'lib/ruby_installer/build/utils.rb', line 129
private def task_once(name, block) name = name.keys.first if name.is_a?(Hash) if block && Rake::Task.task_defined?(name) && Rake::Task[name].instance_variable_get('@task_block_location') == block.source_location # task is already defined for this target and the same block # So skip double definition of the same action Rake::Task[name] elsif block yield.tap do Rake::Task[name].instance_variable_set('@task_block_location', block.source_location) end else yield end end
#with_env(hash)
[ GitHub ]# 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
#with_sandbox_ruby
[ GitHub ]# File 'lib/ruby_installer/build/utils.rb', line 35
def with_sandbox_ruby path = "#{ File. (File.join(sandboxdir, "bin")) };#{ ENV["PATH"] }" with_env(GEM_HOME: nil, GEM_PATH: nil, RUBYOPT: nil, RUBYLIB: nil, PATH: path) do yield end end