Skip to content

Add Windows CI #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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`)
Expand Down
20 changes: 20 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions lib/arduino_ci/arduino_cmd_windows.rb
Original file line number Diff line number Diff line change
@@ -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
105 changes: 105 additions & 0 deletions lib/arduino_ci/arduino_downloader_windows.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 9 additions & 6 deletions lib/arduino_ci/arduino_installation.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down