Skip to content

Enable Windows CI #39

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

Merged
merged 19 commits into from
May 6, 2018
Merged
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/.bundle/
/.yardoc
/Gemfile.lock
Gemfile.lock
/_yardoc/
/coverage/
/doc/
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Layout/EmptyLinesAroundModuleBody:
Layout/ExtraSpacing:
Enabled: false

Layout/EndOfLine:
EnforcedStyle: lf

Metrics/LineLength:
Description: Limit lines to 80 characters.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Arduino `force_install` on Linux now attempts downloading 3 times and provides more information on failure
- Explicit check for `wget`
- Windows / Appveyor support, enabled largely by contributions from @tomduff
- `long long` support in `String`
- Representative `.gitignore` files in sample projects
- Cross-platform symlinking

### Changed
- Author
- Splash-screen-skip hack on OSX now falls back on "official" launch method if the hack doesn't work
- Refactored download/install code in prepration for windows CI
- Explicitly use 32-bit math for mocked Random()

### Deprecated

### Removed

### Fixed
- `Gemfile.lock` files are properly ignored
- Windows hosts won't try to open a display manager

### Security

Expand Down
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
2 changes: 2 additions & 0 deletions SampleProjects/DoSomething/.arduino-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ unittest:
- uno
- due
- leonardo
compilers:
- g++
17 changes: 17 additions & 0 deletions SampleProjects/DoSomething/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/.bundle/
/.yardoc
Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
vendor
*.gem

# rspec failure tracking
.rspec_status

# C++ stuff
*.bin
*.bin.dSYM
19 changes: 0 additions & 19 deletions SampleProjects/DoSomething/Gemfile.lock

This file was deleted.

17 changes: 17 additions & 0 deletions SampleProjects/TestSomething/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/.bundle/
/.yardoc
Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
vendor
*.gem

# rspec failure tracking
.rspec_status

# C++ stuff
*.bin
*.bin.dSYM
19 changes: 0 additions & 19 deletions SampleProjects/TestSomething/Gemfile.lock

This file was deleted.

11 changes: 9 additions & 2 deletions SampleProjects/TestSomething/test/godmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ unittest(millis_micros_and_delay)

unittest(random)
{
GodmodeState* state = GODMODE();
state->reset();
randomSeed(1);
assertEqual(state->seed, 1);

unsigned long x;
x = random(4294967293);
assertEqual(4294967292, x);
assertEqual(state->seed, 4294967292);
x = random(50, 100);
assertEqual(83, x);
assertEqual(87, x);
assertEqual(state->seed, 4294967287);
x = random(100);
assertEqual(74, x);
assertEqual(82, x);
assertEqual(state->seed, 4294967282);
}

void myInterruptHandler() {
Expand Down
27 changes: 27 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
install:
- set PATH=C:\Ruby22\bin;C:\cygwin\bin;C:\cygwin64\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'

environment:
matrix:
- CYG_ARCH: x86_64
CYG_ROOT: C:/cygwin64

build: off

before_test:
- ruby -v
- gem -v
- bundle -v
- g++ -v

test_script:
# https://help.appveyor.com/discussions/problems/5170-progresspreference-not-works-always-shown-preparing-modules-for-first-use-in-stderr
- ps: $ProgressPreference = "SilentlyContinue"
- bundle exec rubocop --version
- bundle exec rubocop -D .
- bundle exec rspec
- cd SampleProjects\TestSomething
- bundle install
- bundle exec arduino_ci_remote.rb
1 change: 1 addition & 0 deletions arduino_ci.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "os", "~> 1.0"
spec.add_dependency "rubyzip", "~> 1.2.1"

spec.add_development_dependency "bundler", "~> 1.15"
spec.add_development_dependency "rspec", "~> 3.0"
Expand Down
1 change: 1 addition & 0 deletions cpp/arduino/Godmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ long random(long vmax)
{
GodmodeState* godmode = GODMODE();
godmode->seed += 4294967291; // it's a prime that fits in 32 bits
godmode->seed = godmode->seed % 4294967296; // explicitly wrap in case we're on a 64-bit impl
return godmode->seed % vmax;
}

Expand Down
14 changes: 13 additions & 1 deletion cpp/arduino/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class String: public string
explicit String(unsigned int val , unsigned char base=10): string(mytoa(val, base)) {}
explicit String(long val, unsigned char base=10): string(mytoas(val, base)) {}
explicit String(unsigned long val, unsigned char base=10): string(mytoa(val, base)) {}
explicit String(long long val, unsigned char base=10): string(mytoas(val, base)) {}
explicit String(unsigned long long val, unsigned char base=10): string(mytoa(val, base)) {}

explicit String(float val, unsigned char decimalPlaces=2): string(dtoas(val, decimalPlaces)) {}
explicit String(double val, unsigned char decimalPlaces=2): string(dtoas(val, decimalPlaces)) {}
Expand All @@ -95,6 +97,8 @@ class String: public string
unsigned char concat(unsigned int num) { append(String(num)); return 1; }
unsigned char concat(long num) { append(String(num)); return 1; }
unsigned char concat(unsigned long num) { append(String(num)); return 1; }
unsigned char concat(long long num) { append(String(num)); return 1; }
unsigned char concat(unsigned long long num) { append(String(num)); return 1; }
unsigned char concat(float num) { append(String(num)); return 1; }
unsigned char concat(double num) { append(String(num)); return 1; }

Expand All @@ -107,6 +111,8 @@ class String: public string
String & operator += (unsigned int num) { concat(num); return *this; }
String & operator += (long num) { concat(num); return *this; }
String & operator += (unsigned long num) { concat(num); return *this; }
String & operator += (long long num) { concat(num); return *this; }
String & operator += (unsigned long long num) { concat(num); return *this; }
String & operator += (float num) { concat(num); return *this; }
String & operator += (double num) { concat(num); return *this; }

Expand Down Expand Up @@ -169,9 +175,15 @@ class String: public string
assign(substr(b, e - b + 1));
}

long toInt(void) const { return std::stol(*this); }
float toFloat(void) const { return std::stof(*this); }
double toDouble(void) const { return std::stod(*this); }
long toInt(void) const {
try {
return std::stol(*this);
} catch (std::out_of_range) {
return std::stoll(*this);
}
}

};

Expand Down
2 changes: 1 addition & 1 deletion lib/arduino_ci/arduino_cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def install_local_library(path)
end

# install the library
FileUtils.ln_s(realpath, destination_path)
Host.symlink(realpath, destination_path)
destination_path
end

Expand Down
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
107 changes: 107 additions & 0 deletions lib/arduino_ci/arduino_downloader_windows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
require 'base64'
require 'shellwords' # fingers crossed this works on win32
require 'win32/registry'
require "arduino_ci/arduino_downloader"
require 'open-uri'
require 'zip'
require "fileutils"

module ArduinoCI

# Manage the POSIX download & install of Arduino
class ArduinoDownloaderWindows < ArduinoDownloader

# 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
"open-uri"
end

# Download the package_url to package_file
# @return [bool] whether successful
def download
# Turned off ssl verification
# This should be acceptable because it won't happen on a user's machine, just CI
open(URI.parse(package_url), ssl_verify_mode: 0) do |url|
File.open(package_file, 'wb') { |file| file.write(url.read) }
end
end

# Move the extracted package file from extracted_file to the force_install_location
# @return [bool] whether successful
def install
# Move only the content of the directory
FileUtils.mv extracted_file, self.class.force_install_location
# clean up the no longer required root extracted folder
FileUtils.rm_rf extracted_file
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
Zip::File.open(package_file) do |zip|
zip.each do |file|
file.extract(file.name)
end
end
# clean up the no longer required zip
FileUtils.rm_rf package_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\WOW6432Node\Arduino'
Win32::Registry::HKEY_LOCAL_MACHINE.open(arduino_reg) do |reg|
path = reg.read_s('Install_Dir')
exe = File.join(path, "arduino_debug.exe")
return exe if File.exist? exe
end
rescue
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_debug.exe")
return nil if exe.nil?
exe
end

end
end
Loading