diff --git a/Rakefile b/Rakefile index 2c868ba..9468af7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,51 +1,55 @@ require 'rubygems' require 'bundler' require 'rspec/core/rake_task' +require File.expand_path('../lib/rautomation/adapter/helper', __FILE__) Bundler::GemHelper.install_tasks -def ext_dependencies(name) - FileList["ext/#{name}/**/*"].reject { |file| file =~ /(Release|Debug)/ } -end - -def ms_build(name) - name = File.basename(name, File.extname(name)) - cmd = "msbuild /p:Configuration=Release ext\\#{name}\\#{name}.sln" - cmd += " && #{cmd} /p:Platform=x64" unless name == 'WindowsForms' - sh(cmd) -end - -namespace :build do - build_tasks = [ +namespace :compile do + compile_tasks = [ {:name => :uia_dll, :path => "UiaDll", :ext => "dll"}, {:name => :i_accessible_dll, :path => "IAccessibleDLL", :ext => "dll"}, {:name => :windows_forms, :path => "WindowsForms", :ext => "exe"} ] - build_tasks.each do |build_task| - full_ext_path = "ext/#{build_task[:path]}/Release/#{build_task[:path]}.#{build_task[:ext]}" - - %w[x86Release x64Release].each do |output_dir| - full_ext_path = full_ext_path.gsub(/(? ext_dependencies(build_task[:path]) do |t| - ms_build(t.name) + compile_tasks.each do |compile_task| + desc "Compile #{compile_task[:path]}" + task compile_task[:name] do + full_ext_path = "ext/#{compile_task[:path]}/Release/#{compile_task[:path]}.#{compile_task[:ext]}" + %w[x86Release x64Release].each do |output_dir| + full_ext_path = full_ext_path.gsub(/(? compile_tasks.map { |t| "compile:#{t[:name]}"} +end - desc "Build #{build_task[:path]}" - task build_task[:name] => full_ext_path +task :compile => "compile:all" + +namespace :build do + platforms = %w[x86-mingw32 x64-mingw32 x86-mingw-ucrt x64-mingw-ucrt] + platforms.each do |platform| + desc "Build gem for platform: #{platform}" + task platform => "compile:all" do + RAutomation::Adapter::Helper.move_adapter_dlls(platform) + sh "gem build --platform #{platform}" + mkdir_p 'pkg' unless Dir.exist?('pkg') + mv Dir.glob("rautomation-*-#{platform}.gem"), 'pkg' + end end - desc "Build all external dependencies" - task :all => build_tasks.map { |t| "build:#{t[:name]}"} + desc "Build gem for all platforms" + task :all => platforms.map(&:to_sym) end -task :build => "build:all" +task :build => 'build:all' namespace :spec do adapters = %w[win_32] - adapters << "ms_uia" if Platform.is_x86? + adapters << "ms_uia" if %w[x86 i386].any? { |p| RUBY_PLATFORM =~ /#{p}/i } adapters.each do |adapter| desc "Run RSpec code examples against #{adapter} adapter" diff --git a/lib/rautomation/adapter/helper.rb b/lib/rautomation/adapter/helper.rb index 0e99cd3..b0e1943 100644 --- a/lib/rautomation/adapter/helper.rb +++ b/lib/rautomation/adapter/helper.rb @@ -9,6 +9,12 @@ module Helper require File.expand_path('../../platform', __FILE__) extend self + ADAPTER_DIRS = [ + "ext/IAccessibleDLL/Release/IAccessibleDLL.dll", + "ext/UiaDll/Release/UiaDll.dll", + "ext/UiaDll/Release/RAutomation.UIA.dll" + ] + # @private # Retrieves default {Adapter} for the current platform. def default_adapter @@ -23,15 +29,17 @@ def supported_for_current_platform?(adapter) Platform.is_x86? || adapter == :win_32 end - def find_missing_externals(externals) - externals.select do |ext| + def find_missing_externals + ADAPTER_DIRS.select do |ext| path = "#{Dir.pwd}/#{File.dirname(ext)}" file = File.basename(ext) - !Dir.exist?(path) && !File.exist?("#{path}/#{file}") + full_path = "#{path}/#{file}" + !Dir.exist?(path) || !File.exist?(full_path) end end def build_solution(ext) + return if File.exist?(ext) return if ext =~ /RAutomation.UIA.dll/ # skip this since its built in UiaDll.sln name = File.basename(ext, File.extname(ext)) @@ -45,19 +53,17 @@ def msbuild_solution(name) "Make sure msbuild binary is in your PATH and the project is configured correctly" end - def move_adapter_dlls(externals, architecture) + def move_adapter_dlls(ruby_platform) + architecture = ruby_platform.split("-").first raise ArgumentError, "Invalid platform #{architecture}" unless %w[x86 x64].any? { |arch| arch == architecture } puts "Moving #{architecture} dll's into 'Release' folder.." - externals.each do |dest_path| - next if dest_path =~ /WindowsForms/ + ADAPTER_DIRS.each do |dest_path| dll_path = dest_path.gsub('Release', "#{architecture}Release") dest_dir = File.dirname(dest_path) FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir) FileUtils.cp(dll_path, dest_path) end - - externals end end end diff --git a/rautomation.gemspec b/rautomation.gemspec index db54d85..031e5f8 100644 --- a/rautomation.gemspec +++ b/rautomation.gemspec @@ -20,26 +20,20 @@ RAutomation provides: s.license = "MIT" s.platform = Gem::Platform.local if s.platform == 'ruby' - ext_locations = [ - "ext/IAccessibleDLL/Release/IAccessibleDLL.dll", - "ext/UiaDll/Release/UiaDll.dll", - "ext/UiaDll/Release/RAutomation.UIA.dll" - ] + missing_externals = RAutomation::Adapter::Helper.find_missing_externals + if missing_externals.any? + missing_externals.each { |ext_location | puts "Missing external: #{ext_location}" } + raise Gem::InstallError, + "One or more required DLL files are missing. See Rake task 'compile' in order to build." + end + ext_locations = RAutomation::Adapter::Helper::ADAPTER_DIRS winforms_files = Dir[ - "ext/WindowsForms/Release/*.dll", - "ext/WindowsForms/Release/*.exe" + "ext/WindowsForms/Release/*.dll", + "ext/WindowsForms/Release/*.exe" ] - RAutomation::Adapter::Helper.find_missing_externals(ext_locations).each do |ext| - RAutomation::Adapter::Helper.build_solution(ext) - end - - # move .dll files and get array containing paths - # send first three externals and first three characters from platform eg 'x86' from 'x86-mingw32' - externals = RAutomation::Adapter::Helper.move_adapter_dlls(ext_locations[0, 3], s.platform.to_s[0, 3]) - - s.files = `git ls-files`.split("\n") + externals + winforms_files + s.files = `git ls-files`.split("\n") + ext_locations + winforms_files s.test_files = `git ls-files -- spec/*`.split("\n") s.require_paths = ["lib"] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e5402e6..7f2669e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -61,8 +61,8 @@ def navigate_to_simple_elements # Path to some binary, which opens up a window, what can be # minimized, maximized, activated, closed and etc. window1: "ext\\WindowsForms\\Release\\WindowsForms.exe", - window2: "notepad", - window2_title: /notepad/i, + window2: "regedit", + window2_title: /registry editor/i, # Window 1 title, has to be a Regexp. window1_title: /FormWindow/i, window1_full_title: 'MainFormWindow',