Sha256: 8061cf53c301f55e2c4edc02833316c480a52a34386e2f166f7c94417ce4ae0d

Contents?: true

Size: 1.99 KB

Versions: 94

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module Appsignal
  # System environment detection module.
  #
  # Provides useful methods to find out more about the host system.
  #
  # @api private
  module System
    LINUX_TARGET = "linux".freeze
    MUSL_TARGET = "linux-musl".freeze
    FREEBSD_TARGET = "freebsd".freeze
    GEM_EXT_PATH = File.expand_path("../../../ext", __FILE__).freeze

    def self.heroku?
      ENV.key? "DYNO".freeze
    end

    # Detect agent and extension platform build
    #
    # Used by `ext/extconf.rb` to select which build it should download and
    # install.
    #
    # Use `export APPSIGNAL_BUILD_FOR_MUSL=1` if the detection doesn't work
    # and to force selection of the musl build.
    #
    # @api private
    # @return [String]
    def self.agent_platform
      return MUSL_TARGET if force_musl_build?

      host_os = RbConfig::CONFIG["host_os"].downcase
      local_os =
        case host_os
        when /#{LINUX_TARGET}/
          LINUX_TARGET
        when /darwin/
          "darwin"
        when /#{FREEBSD_TARGET}/
          FREEBSD_TARGET
        else
          host_os
        end
      if local_os =~ /linux/
        ldd_output = ldd_version_output
        return MUSL_TARGET if ldd_output.include? "musl"
        ldd_version = extract_ldd_version(ldd_output)
        if ldd_version && versionify(ldd_version) < versionify("2.15")
          return MUSL_TARGET
        end
      end

      local_os
    end

    # Returns whether or not the musl build was forced by the user.
    #
    # @api private
    def self.force_musl_build?
      %w[true 1].include?(ENV["APPSIGNAL_BUILD_FOR_MUSL"])
    end

    # @api private
    def self.versionify(version)
      Gem::Version.new(version)
    end

    # @api private
    def self.ldd_version_output
      `ldd --version 2>&1`
    end

    # @api private
    def self.extract_ldd_version(string)
      ldd_version = string.match(/\d+\.\d+/)
      ldd_version && ldd_version[0]
    end

    def self.jruby?
      RUBY_PLATFORM == "java"
    end
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
appsignal-2.11.3-java lib/appsignal/system.rb
appsignal-2.11.3 lib/appsignal/system.rb
appsignal-2.11.2-java lib/appsignal/system.rb
appsignal-2.11.2 lib/appsignal/system.rb
appsignal-2.11.1-java lib/appsignal/system.rb
appsignal-2.11.1 lib/appsignal/system.rb
appsignal-2.11.1.beta.2 lib/appsignal/system.rb
appsignal-2.11.1.beta.2-java lib/appsignal/system.rb
appsignal-2.11.0-java lib/appsignal/system.rb
appsignal-2.11.0 lib/appsignal/system.rb
appsignal-2.10.12 lib/appsignal/system.rb
appsignal-2.10.12-java lib/appsignal/system.rb
appsignal-2.11.0.beta.5 lib/appsignal/system.rb
appsignal-2.11.0.beta.5-java lib/appsignal/system.rb
appsignal-2.10.11 lib/appsignal/system.rb
appsignal-2.10.11-java lib/appsignal/system.rb
appsignal-2.11.0.beta.4 lib/appsignal/system.rb
appsignal-2.11.0.beta.4-java lib/appsignal/system.rb
appsignal-2.11.0.beta.3 lib/appsignal/system.rb
appsignal-2.11.0.beta.3-java lib/appsignal/system.rb