Sha256: b1e68b2e32b4fd1638a9c9ffc87c7489c47263f7389a42808183d09aac4764de

Contents?: true

Size: 1.72 KB

Versions: 5

Compression:

Stored size: 1.72 KB

Contents

require 'open3'

module Rake
  module Funnel
    module Support
      module MSBuild
        class BuildTool
          class << self
            def find
              mono_build || from_registry.compact.first
            end

            private

            def mono_build
              return nil if Rake::Win32.windows?

              begin
                out, status = Open3.capture2('mono', '--version')
                raise "Could not determine mono version: #{status}" unless status.success?
              rescue Errno::ENOENT
                raise 'mono is not installed'
              end

              return 'msbuild'.freeze if out[/^Mono JIT compiler version ([\d\.]+)/, 1] >= '5.0'

              'xbuild'.freeze
            end

            KEY = 'SOFTWARE\Microsoft\MSBuild\ToolsVersions'.freeze

            def from_registry
              return nil unless require_registry

              versions.map do |version|
                version_key(version) do |reg|
                  candidate = File.join(reg['MSBuildToolsPath'] || '', 'msbuild.exe')
                  next candidate if File.exist?(candidate)
                end
              end
            end

            def versions
              %w(14.0 12.0 4.0 3.5 2.0)
            end

            def require_registry
              require 'win32/registry'
              true
            rescue LoadError
              false
            end

            def version_key(version)
              key = KEY + '\\' + version

              ::Win32::Registry::HKEY_LOCAL_MACHINE.open(key) do |reg|
                yield(reg) if block_given?
              end
            rescue ::Win32::Registry::Error
              nil
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rake-funnel-0.21.2 lib/rake/funnel/support/msbuild/build_tool.rb
rake-funnel-0.21.1 lib/rake/funnel/support/msbuild/build_tool.rb
rake-funnel-0.21.0 lib/rake/funnel/support/msbuild/build_tool.rb
rake-funnel-0.20.2 lib/rake/funnel/support/msbuild/build_tool.rb
rake-funnel-0.20.1 lib/rake/funnel/support/msbuild/build_tool.rb