diff --git a/README.md b/README.md index df7b609d..6b01acef 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Gem Version](https://badge.fury.io/rb/arduino_ci.svg)](https://rubygems.org/gems/arduino_ci) -[![Build Status](https://travis-ci.org/ianfixes/arduino_ci.svg)](https://travis-ci.org/ianfixes/arduino_ci) +[![Linux Build Status](https://travis-ci.org/ianfixes/arduino_ci.svg)](https://travis-ci.org/ianfixes/arduino_ci) +[![Windows Build status](https://ci.appveyor.com/api/projects/status/8f6e39dea319m83q?svg=true)](https://ci.appveyor.com/project/ianfixes/arduino-ci) [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/0.1.9) # ArduinoCI Ruby gem (`arduino_ci`) diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..7f5b5b57 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,20 @@ +install: + - set PATH=C:\Ruby22\bin;%PATH% + - bundle install + - '%CYG_ROOT%\setup-%CYG_ARCH%.exe -qnNdO -R %CYG_ROOT% -s http://cygwin.mirror.constant.com -l %CYG_ROOT%/var/cache/setup -P autoconf -P automake -P bison -P libgmp-devel -P gcc-core -P gcc-g++ -P mingw-runtime -P mingw-binutils -P mingw-gcc-core -P mingw-gcc-g++ -P mingw-pthreads -P mingw-w32api -P libtool -P make -P gettext-devel -P gettext -P intltool -P libiconv -P pkg-config -P git -P wget -P curl' + +build: off + +before_test: + - ruby -v + - gem -v + - bundle -v + - g++ -v + +test_script: + - bundle exec rubocop --version + - bundle exec rubocop -D . + - bundle exec rspec + - cd SampleProjects\TestSomething + - bundle install + - bundle exec arduino_ci_remote.rb diff --git a/lib/arduino_ci/arduino_cmd_windows.rb b/lib/arduino_ci/arduino_cmd_windows.rb new file mode 100644 index 00000000..52be6f12 --- /dev/null +++ b/lib/arduino_ci/arduino_cmd_windows.rb @@ -0,0 +1,34 @@ +require "arduino_ci/host" +require 'arduino_ci/arduino_cmd' + +module ArduinoCI + + # Implementation of OSX commands + class ArduinoCmdWindows < ArduinoCmd + flag :get_pref, "--get-pref" + flag :set_pref, "--pref" + flag :save_prefs, "--save-prefs" + flag :use_board, "--board" + flag :install_boards, "--install-boards" + flag :install_library, "--install-library" + flag :verify, "--verify" + + # run the arduino command + # @return [bool] whether the command succeeded + def _run_and_output(*args, **kwargs) + Host.run_and_output(*args, **kwargs) + end + + # run the arduino command + # @return [Hash] keys for :success, :out, and :err + def _run_and_capture(*args, **kwargs) + Host.run_and_capture(*args, **kwargs) + end + + def _lib_dir + File.join(ENV['userprofile'], "Documents", "Arduino", "libraries") + end + + end + +end diff --git a/lib/arduino_ci/arduino_downloader_windows.rb b/lib/arduino_ci/arduino_downloader_windows.rb new file mode 100644 index 00000000..995c5d24 --- /dev/null +++ b/lib/arduino_ci/arduino_downloader_windows.rb @@ -0,0 +1,105 @@ +require 'base64' +require 'shellwords' # fingers crossed this works on win32 +require 'win32' +require "arduino_ci/arduino_downloader" + +module ArduinoCI + + # Manage the POSIX download & install of Arduino + class ArduinoDownloaderWindows < ArduinoDownloader + + def powershell(*args) + encoded_cmd = Base64.strict_encode64(args.shelljoin.encode('utf-16le')) + system("powershell.exe", "-encodedCommand", encoded_cmd) + end + + def cygwin(*args) + system("%CYG_ROOT%/bin/bash", "-lc", args.shelljoin) + end + + # Make any preparations or run any checks prior to making changes + # @return [string] Error message, or nil if success + def prepare + nil + end + + # The technology that will be used to complete the download + # (for logging purposes) + # @return [string] + def downloader + "wget" + end + + # Download the package_url to package_file + # @return [bool] whether successful + def download + powershell("(New-Object Net.WebClient).DownloadFile('#{package_url}', '#{package_file}')") + end + + # Move the extracted package file from extracted_file to the force_install_location + # @return [bool] whether successful + def install + powershell("Move-Item", extracted_file, self.class.force_install_location) + end + + # The local filename of the desired IDE package (zip/tar/etc) + # @return [string] + def package_file + "#{extracted_file}-windows.zip" + end + + # The technology that will be used to extract the download + # (for logging purposes) + # @return [string] + def extracter + "Expand-Archive" + end + + # Extract the package_file to extracted_file + # @return [bool] whether successful + def extract + powershell("Expand-Archive", package_file, "-dest", extracted_file) + end + + # The local file (dir) name of the extracted IDE package (zip/tar/etc) + # @return [string] + def extracted_file + "arduino-#{@desired_ide_version}" + end + + # The path to the directory of an existing installation, or nil + # @return [string] + def self.existing_installation + exe = self.existing_executable + return nil if exe.nil? + File.dirname(exe) + end + + # The executable Arduino file in an existing installation, or nil + # @return [string] + def self.existing_executable + arduino_reg = 'Software\SOFTWARE\Classes\Arduino file\shell\open\command' + Win32::Registry::HKEY_LOCAL_MACHINE.open(arduino_reg) do |reg| + reg.each_key do |key| + k = reg.open(key) + puts key + puts k + return k + # puts k["DisplayName"] rescue "?" + # puts k["DisplayVersion"] rescue "?" + # puts + end + end + nil + end + + # The executable Arduino file in a forced installation, or nil + # @return [string] + def self.force_installed_executable + exe = File.join(self.force_install_location, "arduino.exe") + return nil if exe.nil? + exe + end + + end +end diff --git a/lib/arduino_ci/arduino_installation.rb b/lib/arduino_ci/arduino_installation.rb index ad1cef47..5ffaf1b8 100644 --- a/lib/arduino_ci/arduino_installation.rb +++ b/lib/arduino_ci/arduino_installation.rb @@ -1,9 +1,12 @@ require "arduino_ci/host" require "arduino_ci/arduino_cmd_osx" require "arduino_ci/arduino_cmd_linux" +require "arduino_ci/arduino_cmd_windows" require "arduino_ci/arduino_cmd_linux_builder" -require "arduino_ci/arduino_downloader_linux" require "arduino_ci/arduino_downloader_osx" +require "arduino_ci/arduino_downloader_linux" + +require "arduino_ci/arduino_downloader_windows" if ArduinoCI::Host.os == :windows DESIRED_ARDUINO_IDE_VERSION = "1.8.5".freeze @@ -28,11 +31,11 @@ def autolocate return nil if loc.nil? ret = ArduinoCmdLinux.new ret.base_cmd = [loc] - # when :windows then - # ArduinoDownloaderWindows.autolocation - # return nil if loc.nil? - # ret = ArduinoCmdWindows.new - # ret.base_cmd = [loc] + when :windows then + ArduinoDownloaderWindows.autolocation + return nil if loc.nil? + ret = ArduinoCmdWindows.new + ret.base_cmd = [loc] end ret end