File: compile_cache.rb

package info (click to toggle)
ruby-bootsnap 1.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 520 kB
  • sloc: ruby: 3,637; ansic: 844; sh: 14; makefile: 9
file content (47 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true

module Bootsnap
  module CompileCache
    UNCOMPILABLE = BasicObject.new
    def UNCOMPILABLE.inspect
      "<Bootsnap::UNCOMPILABLE>"
    end

    Error = Class.new(StandardError)

    def self.setup(cache_dir:, iseq:, yaml:, json: (json_unset = true), readonly: false, revalidation: false)
      unless json_unset
        warn("Bootsnap::CompileCache.setup `json` argument is deprecated and has no effect")
      end

      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

      if supported? && defined?(Bootsnap::CompileCache::Native)
        Bootsnap::CompileCache::Native.readonly = readonly
        Bootsnap::CompileCache::Native.revalidation = revalidation
      end
    end

    def self.supported?
      # only enable on 'ruby' (MRI) and TruffleRuby for POSIX (darwin, linux, *bsd), Windows (RubyInstaller2)
      %w[ruby truffleruby].include?(RUBY_ENGINE) &&
        RUBY_PLATFORM.match?(/darwin|linux|bsd|mswin|mingw|cygwin/)
    end
  end
end