Sha256: e0363695667cb4767fc4514866c148e0f4cc64a112fad1e418a25378d12fd9db

Contents?: true

Size: 1.37 KB

Versions: 19

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true
module Bootsnap
  module CompileCache
    Error           = Class.new(StandardError)
    PermissionError = Class.new(Error)

    def self.setup(cache_dir:, iseq:, yaml:)
      if iseq
        if supported?
          require_relative('compile_cache/iseq')
          Bootsnap::CompileCache::ISeq.install!(cache_dir)
        elsif $VERBOSE
          warn("[bootsnap/setup] bytecode caching is not supported on this implementation of Ruby")
        end
      end

      if yaml
        if supported?
          require_relative('compile_cache/yaml')
          Bootsnap::CompileCache::YAML.install!(cache_dir)
        elsif $VERBOSE
          warn("[bootsnap/setup] YAML parsing caching is not supported on this implementation of Ruby")
        end
      end
    end

    def self.permission_error(path)
      cpath = Bootsnap::CompileCache::ISeq.cache_dir
      raise(
        PermissionError,
        "bootsnap doesn't have permission to write cache entries in '#{cpath}' " \
        "(or, less likely, doesn't have permission to read '#{path}')",
      )
    end

    def self.supported?
      # only enable on 'ruby' (MRI), POSIX (darwin, linux, *bsd), Windows (RubyInstaller2) and >= 2.3.0
      RUBY_ENGINE == 'ruby' &&
      RUBY_PLATFORM =~ /darwin|linux|bsd|mswin|mingw|cygwin/ &&
      Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.3.0")
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bootsnap-1.8.1 lib/bootsnap/compile_cache.rb
bootsnap-1.8.0 lib/bootsnap/compile_cache.rb
bootsnap-1.7.7 lib/bootsnap/compile_cache.rb
bootsnap-1.7.6 lib/bootsnap/compile_cache.rb
bootsnap-1.7.5 lib/bootsnap/compile_cache.rb
bootsnap-1.7.4 lib/bootsnap/compile_cache.rb
bootsnap-1.7.3 lib/bootsnap/compile_cache.rb
bootsnap-1.7.2 lib/bootsnap/compile_cache.rb
bootsnap-1.7.1 lib/bootsnap/compile_cache.rb
bootsnap-1.7.1.pre1 lib/bootsnap/compile_cache.rb
bootsnap-1.7.0 lib/bootsnap/compile_cache.rb
bootsnap-1.6.0 lib/bootsnap/compile_cache.rb
bootsnap-1.5.1-java lib/bootsnap/compile_cache.rb
bootsnap-1.5.0-java lib/bootsnap/compile_cache.rb
bootsnap-1.5.1 lib/bootsnap/compile_cache.rb
bootsnap-1.5.0 lib/bootsnap/compile_cache.rb
bootsnap-1.4.9-java lib/bootsnap/compile_cache.rb
bootsnap-1.4.9 lib/bootsnap/compile_cache.rb
bootsnap-1.4.9.rc1 lib/bootsnap/compile_cache.rb