<commit_before># typed: true
# frozen_string_literal: true

require "os/mac/version"

module OS
  module Mac
    # Class representing a macOS SDK.
    #
    # @api private
    class SDK
      extend T::Sig

      # 11.x SDKs are explicitly excluded - we want the MacOSX11.sdk symlink instead.
      VERSIONED_SDK_REGEX = /MacOSX(10\.\d+|\d+)\.sdk$/.freeze

      sig { returns(OS::Mac::Version) }
      attr_reader :version

      sig { returns(Pathname) }
      attr_reader :path

      sig { returns(Symbol) }
      attr_reader :source

      sig { params(version: OS::Mac::Version, path: T.any(String, Pathname), source: Symbol).void }
      def initialize(version, path, source)
        @version = version
        @path = Pathname.new(path)
        @source = source
      end
    end

    # Base class for SDK locators.
    #
    # @api private
    class BaseSDKLocator
      extend T::Sig
      extend T::Helpers

      abstract!

      class NoSDKError < StandardError; end

      sig { params(v: OS::Mac::Version).returns(SDK) }
      def sdk_for(v)
        sdk = all_sdks.find { |s| s.version == v }
        raise NoSDKError if sdk.nil?

        sdk
      end

      sig { returns(T::Array[SDK]) }
      def all_sdks
        return @all_sdks if @all_sdks

        @all_sdks = []

        # Bail out if there is no SDK prefix at all
        return @all_sdks unless File.directory? sdk_prefix

        Dir["#{sdk_prefix}/MacOSX*.sdk"].each do |sdk_path|
          next unless sdk_path.match?(SDK::VERSIONED_SDK_REGEX)

          version = read_sdk_version(Pathname.new(sdk_path))
          next if version.nil?

          @all_sdks << SDK.new(version, sdk_path, source)
        end

        # Fall back onto unversioned SDK if we've not found a suitable SDK
        if @all_sdks.empty?
          sdk_path = Pathname.new("#{sdk_prefix}/MacOSX.sdk")
          if (version = read_sdk_version(sdk_path))
            @all_sdks << SDK.new(version, sdk_path, source)
          end
        end
<commit_msg>os/mac/sdk: use unversioned SDK if matching version isn't found<commit_after># typed: true
# frozen_string_literal: true

require "os/mac/version"

module OS
  module Mac
    # Class representing a macOS SDK.
    #
    # @api private
    class SDK
      extend T::Sig

      # 11.x SDKs are explicitly excluded - we want the MacOSX11.sdk symlink instead.
      VERSIONED_SDK_REGEX = /MacOSX(10\.\d+|\d+)\.sdk$/.freeze

      sig { returns(OS::Mac::Version) }
      attr_reader :version

      sig { returns(Pathname) }
      attr_reader :path

      sig { returns(Symbol) }
      attr_reader :source

      sig { params(version: OS::Mac::Version, path: T.any(String, Pathname), source: Symbol).void }
      def initialize(version, path, source)
        @version = version
        @path = Pathname.new(path)
        @source = source
      end
    end

    # Base class for SDK locators.
    #
    # @api private
    class BaseSDKLocator
      extend T::Sig
      extend T::Helpers

      abstract!

      class NoSDKError < StandardError; end

      sig { params(v: OS::Mac::Version).returns(SDK) }
      def sdk_for(v)
        sdk = all_sdks.find { |s| s.version == v }
        raise NoSDKError if sdk.nil?

        sdk
      end

      sig { returns(T::Array[SDK]) }
      def all_sdks
        return @all_sdks if @all_sdks

        @all_sdks = []

        # Bail out if there is no SDK prefix at all
        return @all_sdks unless File.directory? sdk_prefix

        found_versions = Set.new

        Dir["#{sdk_prefix}/MacOSX*.sdk"].each do |sdk_path|
          next unless sdk_path.match?(SDK::VERSIONED_SDK_REGEX)

          version = read_sdk_version(Pathname.new(sdk_path))
          next if version.nil?

          @all_sdks << SDK.new(version, sdk_path, source)
          found_versions << version
        end

        # Use unversioned SDK only if we don't have one matching that version.
        sdk_path = Pathname.new("#{sdk_prefix}/MacOSX.sdk")
        if (version = read_sdk_version(sdk_path)) && found_versions.exclude?(version)
          @all_sdks << SDK.new(version, sdk_path, source)
        end

{'fraction_non_alphanumeric': 0.10388349514563107, 'fraction_numerical': 0.002912621359223301, 'mean_word_length': 2.2525651144435677, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7195577', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1299, 'n_words': 342}