From bc8267480ee034a61caf03210ae674d01c52e2c0 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 11 Sep 2018 10:19:25 -0400 Subject: [PATCH 1/6] Revert "Enable installing custom libraries in CI setup" This reverts commit 9243f23b654e147c6f2cf79910c59c30715e2649. --- CHANGELOG.md | 1 - REFERENCE.md | 36 ------------------------------ exe/ensure_arduino_installation.rb | 5 ----- 3 files changed, 42 deletions(-) delete mode 100644 exe/ensure_arduino_installation.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a663f69..cb85c1ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Arduino command wrapper can now guess whether a library is installed - CPP library class now reaches into included Arduino libraries for source files - SPI mocks -- `ensure_arduino_installation.rb` to allow custom libraries to be installed ### Changed - Refactored documentation diff --git a/REFERENCE.md b/REFERENCE.md index ef4f177b..64c8028c 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -100,42 +100,6 @@ unittest_main() This test defines one `unittest` (a macro provided by `ArduinoUnitTests.h`), called `your_test_name`, which makes some assertions on the target library. The `unittest_main()` is a macro for the `int main()` boilerplate required for unit testing. -# Build Scripts - -For most build environments, the only script that need be executed by the CI system is - -```shell -# simplest build script -bundle install -bundle exec arduino_ci_remote.rb -``` - -However, more flexible usage is available: - -### Custom Versions of external Arduino Libraries - -Sometimes you need a fork of an Arduino library instead of the version that will be installed via their GUI. `arduino_ci_remote.rb` won't overwrite existing downloaded libraries with fresh downloads, but it won't fetch the custom versions for you either. - -If this is the behavior you need, `ensure_arduino_installation.rb` is for you. - -```shell -# Example build script -bundle install - -# ensure the Arduino installation -- creates the Library directory -bundle exec ensure_arduino_installation.rb - -# manually install the custom version you need -git clone https://repository.com/custom_library_repo.git -mv custom_library_repo /path/to/Arduino/libraries - -# now run CI -bundle exec arduino_ci_remote.rb -``` - - - - # Mocks ## Using `GODMODE` diff --git a/exe/ensure_arduino_installation.rb b/exe/ensure_arduino_installation.rb deleted file mode 100644 index c0e9799d..00000000 --- a/exe/ensure_arduino_installation.rb +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env ruby -require 'arduino_ci' - -# this will exit after Arduino is located and/or forcibly installed -ArduinoCI::ArduinoInstallation.autolocate! From 78fc45dfafb6f68294bd3465675de09d4844c12d Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 11 Sep 2018 10:19:25 -0400 Subject: [PATCH 2/6] Revert "Add SPI mocks" This reverts commit 937f10ad11fc4fe8b25216672c2b6837d0bb47c9. --- CHANGELOG.md | 1 - REFERENCE.md | 40 ----- SampleProjects/TestSomething/test/godmode.cpp | 38 ----- cpp/arduino/Arduino.h | 1 - cpp/arduino/Godmode.cpp | 4 - cpp/arduino/Godmode.h | 27 +--- cpp/arduino/SPI.h | 150 ------------------ 7 files changed, 8 insertions(+), 253 deletions(-) delete mode 100644 cpp/arduino/SPI.h diff --git a/CHANGELOG.md b/CHANGELOG.md index cb85c1ad..b4789f57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Explicit checks that the requested test platforms are defined in YML - Arduino command wrapper can now guess whether a library is installed - CPP library class now reaches into included Arduino libraries for source files -- SPI mocks ### Changed - Refactored documentation diff --git a/REFERENCE.md b/REFERENCE.md index 64c8028c..89d78643 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -366,43 +366,3 @@ unittest(interrupt_attachment) { detachInterrupt(7); assertFalse(state->interrupt[7].attached); }``` - - -### SPI - -These basic mocks of SPI store the values in Strings. - -```C++ -unittest(spi) { - GodmodeState *state = GODMODE(); - - // 8-bit - state->reset(); - state->spi.dataIn = "LMNO"; - uint8_t out8 = SPI.transfer('a'); - assertEqual("a", state->spi.dataOut); - assertEqual('L', out8); - assertEqual("MNO", state->spi.dataIn); - - // 16-bit - union { uint16_t val; struct { char lsb; char msb; }; } in16, out16; - state->reset(); - state->spi.dataIn = "LMNO"; - in16.lsb = 'a'; - in16.msb = 'b'; - out16.val = SPI.transfer16(in16.val); - assertEqual("NO", state->spi.dataIn); - assertEqual('L', out16.lsb); - assertEqual('M', out16.msb); - assertEqual("ab", state->spi.dataOut); - - // buffer - state->reset(); - state->spi.dataIn = "LMNOP"; - char inBuf[6] = "abcde"; - SPI.transfer(inBuf, 4); - - assertEqual("abcd", state->spi.dataOut); - assertEqual("LMNOe", String(inBuf)); -} -``` diff --git a/SampleProjects/TestSomething/test/godmode.cpp b/SampleProjects/TestSomething/test/godmode.cpp index e4cf69e2..61d16a40 100644 --- a/SampleProjects/TestSomething/test/godmode.cpp +++ b/SampleProjects/TestSomething/test/godmode.cpp @@ -183,44 +183,6 @@ unittest(interrupt_attachment) { assertFalse(state->interrupt[0].attached); } -unittest(spi) { - GodmodeState *state = GODMODE(); - state->reset(); - assertEqual("", state->spi.dataIn); - assertEqual("", state->spi.dataOut); - - // 8-bit - state->reset(); - state->spi.dataIn = "LMNO"; - uint8_t out8 = SPI.transfer('a'); - assertEqual("a", state->spi.dataOut); - assertEqual('L', out8); - assertEqual("MNO", state->spi.dataIn); - - // 16-bit - union { uint16_t val; struct { char lsb; char msb; }; } in16, out16; - state->reset(); - state->spi.dataIn = "LMNO"; - in16.lsb = 'a'; - in16.msb = 'b'; - out16.val = SPI.transfer16(in16.val); - assertEqual("NO", state->spi.dataIn); - assertEqual('L', out16.lsb); - assertEqual('M', out16.msb); - assertEqual("ab", state->spi.dataOut); - - // buffer - state->reset(); - state->spi.dataIn = "LMNOP"; - char inBuf[6] = "abcde"; - SPI.transfer(inBuf, 4); - - assertEqual("abcd", state->spi.dataOut); - assertEqual("LMNOe", String(inBuf)); -} - - - #ifdef HAVE_HWSERIAL0 void smartLightswitchSerialHandler(int pin) { diff --git a/cpp/arduino/Arduino.h b/cpp/arduino/Arduino.h index 0eb0796a..f1c642b5 100644 --- a/cpp/arduino/Arduino.h +++ b/cpp/arduino/Arduino.h @@ -14,7 +14,6 @@ Where possible, variable names from the Arduino library are used to avoid confli #include "Print.h" #include "Stream.h" #include "HardwareSerial.h" -#include "SPI.h" typedef bool boolean; typedef uint8_t byte; diff --git a/cpp/arduino/Godmode.cpp b/cpp/arduino/Godmode.cpp index 7d84e2b8..6bcdfbdd 100644 --- a/cpp/arduino/Godmode.cpp +++ b/cpp/arduino/Godmode.cpp @@ -1,6 +1,5 @@ #include "Godmode.h" #include "HardwareSerial.h" -#include "SPI.h" GodmodeState godmode = GodmodeState(); @@ -98,6 +97,3 @@ inline std::ostream& operator << ( std::ostream& out, const PinHistory& ph ) out << ph; return out; } - -// defined in SPI.h -SPIClass SPI = SPIClass(&godmode.spi.dataIn, &godmode.spi.dataOut); diff --git a/cpp/arduino/Godmode.h b/cpp/arduino/Godmode.h index b50f99d2..3214c0e5 100644 --- a/cpp/arduino/Godmode.h +++ b/cpp/arduino/Godmode.h @@ -51,7 +51,6 @@ class GodmodeState { PinHistory analogPin[MOCK_PINS_COUNT]; struct PortDef serialPort[NUM_SERIAL_PORTS]; struct InterruptDef interrupt[MOCK_PINS_COUNT]; // not sure how to get actual number - struct PortDef spi; void resetPins() { for (int i = 0; i < MOCK_PINS_COUNT; ++i) { @@ -70,27 +69,10 @@ class GodmodeState { } } - void resetPorts() { - for (int i = 0; i < serialPorts(); ++i) - { - serialPort[i].dataIn = ""; - serialPort[i].dataOut = ""; - serialPort[i].readDelayMicros = 0; - } - } - - void resetSPI() { - spi.dataIn = ""; - spi.dataOut = ""; - spi.readDelayMicros = 0; - } - void reset() { resetClock(); resetPins(); resetInterrupts(); - resetPorts(); - resetSPI(); seed = 1; } @@ -101,7 +83,14 @@ class GodmodeState { GodmodeState() { reset(); - } + for (int i = 0; i < serialPorts(); ++i) + { + serialPort[i].dataIn = ""; + serialPort[i].dataOut = ""; + serialPort[i].readDelayMicros = 0; + } + } + }; // io pins diff --git a/cpp/arduino/SPI.h b/cpp/arduino/SPI.h deleted file mode 100644 index d2666267..00000000 --- a/cpp/arduino/SPI.h +++ /dev/null @@ -1,150 +0,0 @@ -#pragma once - -#include "Stream.h" - -// defines from original file -#define _SPI_H_INCLUDED -#define SPI_HAS_TRANSACTION 1 -#define SPI_HAS_NOTUSINGINTERRUPT 1 -#define SPI_ATOMIC_VERSION 1 -#define SPI_CLOCK_DIV4 0x00 -#define SPI_CLOCK_DIV16 0x01 -#define SPI_CLOCK_DIV64 0x02 -#define SPI_CLOCK_DIV128 0x03 -#define SPI_CLOCK_DIV2 0x04 -#define SPI_CLOCK_DIV8 0x05 -#define SPI_CLOCK_DIV32 0x06 -#define SPI_MODE0 0x00 -#define SPI_MODE1 0x04 -#define SPI_MODE2 0x08 -#define SPI_MODE3 0x0C -#define SPI_MODE_MASK 0x0C -#define SPI_CLOCK_MASK 0x03 -#define SPI_2XCLOCK_MASK 0x01 - -#ifndef LSBFIRST -#define LSBFIRST 0 -#endif -#ifndef MSBFIRST -#define MSBFIRST 1 -#endif - -#if defined(EIMSK) - #define SPI_AVR_EIMSK EIMSK -#elif defined(GICR) - #define SPI_AVR_EIMSK GICR -#elif defined(GIMSK) - #define SPI_AVR_EIMSK GIMSK -#endif - - -class SPISettings { -public: - SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode){}; - SPISettings(){}; -}; - - -class SPIClass: public ObservableDataStream { -public: - - SPIClass(String* dataIn, String* dataOut) { - this->dataIn = dataIn; - this->dataOut = dataOut; - } - - // Initialize the SPI library - void begin() { isStarted = true; } - - // Disable the SPI bus - void end() { isStarted = false; } - - // this has no tangible effect in a mocked Arduino - void usingInterrupt(uint8_t interruptNumber){} - void notUsingInterrupt(uint8_t interruptNumber){} - - // Before using SPI.transfer() or asserting chip select pins, - // this function is used to gain exclusive access to the SPI bus - // and configure the correct settings. - void beginTransaction(SPISettings settings) - { - #ifdef SPI_TRANSACTION_MISMATCH_LED - if (inTransactionFlag) { - pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); - digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); - } - inTransactionFlag = 1; - #endif - } - - // Write to the SPI bus (MOSI pin) and also receive (MISO pin) - uint8_t transfer(uint8_t data) { - //FIXME! - // push memory->bus - dataOut->append(String((char)data)); - advertiseByte((char)data); - - // pop bus->memory data from its queue and return it - if (!dataIn->length()) return 0; - char ret = (*dataIn)[0]; - *dataIn = dataIn->substr(1, dataIn->length()); - return ret; - } - - uint16_t transfer16(uint16_t data) { - union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } in, out; - in.val = data; - if (!(SPCR & (1 << DORD))) { - out.msb = transfer(in.msb); - out.lsb = transfer(in.lsb); - } else { - out.lsb = transfer(in.lsb); - out.msb = transfer(in.msb); - } - return out.val; - } - - void transfer(void *buf, size_t count) { - // TODO: this logic is rewritten from the original, - // I'm not sure what role the SPDR register (which I removed) plays - - uint8_t *p = (uint8_t *)buf; - for (int i = 0; i < count; ++i) { - *(p + i) = transfer(*(p + i)); - } - } - - // After performing a group of transfers and releasing the chip select - // signal, this function allows others to access the SPI bus - void endTransaction(void) { - #ifdef SPI_TRANSACTION_MISMATCH_LED - if (!inTransactionFlag) { - pinMode(SPI_TRANSACTION_MISMATCH_LED, OUTPUT); - digitalWrite(SPI_TRANSACTION_MISMATCH_LED, HIGH); - } - inTransactionFlag = 0; - #endif - } - - // deprecated functions, skip 'em - void setBitOrder(uint8_t bitOrder){} - void setDataMode(uint8_t dataMode){} - void setClockDivider(uint8_t clockDiv){} - void attachInterrupt(){} - void detachInterrupt(){} - -private: - uint8_t initialized; // initialized in Godmode.cpp - uint8_t interruptMode; // 0=none, 1=mask, 2=global - uint8_t interruptMask; // which interrupts to mask - uint8_t interruptSave; // temp storage, to restore state - #ifdef SPI_TRANSACTION_MISMATCH_LED - uint8_t inTransactionFlag; - #endif - - bool isStarted = false; - String* dataIn; - String* dataOut; -}; - -extern SPIClass SPI; From 16e43c0e33c78123eb6b1295ddd2d44d434175b8 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 11 Sep 2018 10:19:25 -0400 Subject: [PATCH 3/6] Revert "Mock attachInterrupt and detachInterrupt" This reverts commit c22862cef7a1d25ec0d143e64e8ace8cece9e395. --- CHANGELOG.md | 1 - REFERENCE.md | 15 --------------- SampleProjects/TestSomething/test/godmode.cpp | 11 ----------- cpp/arduino/Arduino.h | 3 +++ cpp/arduino/Godmode.cpp | 10 ---------- cpp/arduino/Godmode.h | 15 --------------- 6 files changed, 3 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4789f57..3457723d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Refactored documentation - External libraries aren't forcibly installed via the Arduino binary (in `arduino_cmd_remote.rb`) if they appear to exist on disk already -- `attachInterrupt` and `detachInterrupt` are now mocked instead of `_NOP` ### Deprecated diff --git a/REFERENCE.md b/REFERENCE.md index 89d78643..941b3215 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -351,18 +351,3 @@ unittest(modem_hardware) Note that instead of setting `mLast = output` in the `onMatchInput()` function for test purposes, we could just as easily queue some bytes to state->serialPort[0].dataIn for the library under test to find on its next `peek()` or `read()`. Or we could execute some action on a digital or analog input pin; the possibilities are fairly endless in this regard, although you will have to define them yourself -- from scratch -- extending the `DataStreamObserver` class to emulate your physical device. -### Interrupts - -Although ISRs should be tested directly (as their asynchronous nature is not mocked), the act of attaching or detaching an interrupt can be measured. - -```C++ -unittest(interrupt_attachment) { - GodmodeState *state = GODMODE(); - state->reset(); - assertFalse(state->interrupt[7].attached); - attachInterrupt(7, (void (*)(void))0, 3); - assertTrue(state->interrupt[7].attached); - assertEqual(state->interrupt[7].mode, 3); - detachInterrupt(7); - assertFalse(state->interrupt[7].attached); -}``` diff --git a/SampleProjects/TestSomething/test/godmode.cpp b/SampleProjects/TestSomething/test/godmode.cpp index 61d16a40..9364a07f 100644 --- a/SampleProjects/TestSomething/test/godmode.cpp +++ b/SampleProjects/TestSomething/test/godmode.cpp @@ -172,17 +172,6 @@ unittest(pin_write_history) } -unittest(interrupt_attachment) { - GodmodeState *state = GODMODE(); - state->reset(); - assertFalse(state->interrupt[0].attached); - attachInterrupt(0, (void (*)(void))0, 3); - assertTrue(state->interrupt[0].attached); - assertEqual(state->interrupt[0].mode, 3); - detachInterrupt(0); - assertFalse(state->interrupt[0].attached); -} - #ifdef HAVE_HWSERIAL0 void smartLightswitchSerialHandler(int pin) { diff --git a/cpp/arduino/Arduino.h b/cpp/arduino/Arduino.h index f1c642b5..1d017bf2 100644 --- a/cpp/arduino/Arduino.h +++ b/cpp/arduino/Arduino.h @@ -43,6 +43,9 @@ typedef uint8_t byte; #define yield() _NOP() #define interrupts() _NOP() #define noInterrupts() _NOP() +#define attachInterrupt(...) _NOP() +#define detachInterrupt(...) _NOP() + // TODO: correctly establish this per-board! #define F_CPU 1000000UL diff --git a/cpp/arduino/Godmode.cpp b/cpp/arduino/Godmode.cpp index 6bcdfbdd..d9e46b52 100644 --- a/cpp/arduino/Godmode.cpp +++ b/cpp/arduino/Godmode.cpp @@ -67,16 +67,6 @@ int analogRead(unsigned char pin) { return godmode->analogPin[pin].retrieve(); } -void attachInterrupt(uint8_t interrupt, void ISR(void), uint8_t mode) { - GodmodeState* godmode = GODMODE(); - godmode->interrupt[interrupt].attached = true; - godmode->interrupt[interrupt].mode = mode; -} - -void detachInterrupt(uint8_t interrupt) { - GodmodeState* godmode = GODMODE(); - godmode->interrupt[interrupt].attached = false; -} // Serial ports #if defined(HAVE_HWSERIAL0) diff --git a/cpp/arduino/Godmode.h b/cpp/arduino/Godmode.h index 3214c0e5..b14d602f 100644 --- a/cpp/arduino/Godmode.h +++ b/cpp/arduino/Godmode.h @@ -38,11 +38,6 @@ class GodmodeState { unsigned long readDelayMicros; }; - struct InterruptDef { - bool attached; - uint8_t mode; - }; - public: unsigned long micros; unsigned long seed; @@ -50,7 +45,6 @@ class GodmodeState { PinHistory digitalPin[MOCK_PINS_COUNT]; PinHistory analogPin[MOCK_PINS_COUNT]; struct PortDef serialPort[NUM_SERIAL_PORTS]; - struct InterruptDef interrupt[MOCK_PINS_COUNT]; // not sure how to get actual number void resetPins() { for (int i = 0; i < MOCK_PINS_COUNT; ++i) { @@ -63,16 +57,9 @@ class GodmodeState { micros = 0; } - void resetInterrupts() { - for (int i = 0; i < MOCK_PINS_COUNT; ++i) { - interrupt[i].attached = false; - } - } - void reset() { resetClock(); resetPins(); - resetInterrupts(); seed = 1; } @@ -103,8 +90,6 @@ int analogRead(uint8_t); void analogWrite(uint8_t, int); #define analogReadResolution(...) _NOP() #define analogWriteResolution(...) _NOP() -void attachInterrupt(uint8_t interrupt, void ISR(void), uint8_t mode); -void detachInterrupt(uint8_t interrupt); // TODO: issue #26 to track the commanded state here inline void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0) {} From cde841808073233491e9022a5fcbb14fe3a4d026 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 11 Sep 2018 10:19:25 -0400 Subject: [PATCH 4/6] Revert "Compile with 3rd-party Arduino libraries (includes and CPP files)" This reverts commit 5d51f1ec729124595ab64fd3e8548ace16c3eef8. --- CHANGELOG.md | 3 +-- exe/arduino_ci_remote.rb | 2 +- lib/arduino_ci/arduino_cmd.rb | 6 ++--- lib/arduino_ci/arduino_cmd_linux.rb | 2 +- lib/arduino_ci/arduino_cmd_linux_builder.rb | 2 +- lib/arduino_ci/arduino_cmd_osx.rb | 2 +- lib/arduino_ci/arduino_cmd_windows.rb | 2 +- lib/arduino_ci/cpp_library.rb | 28 ++------------------- spec/arduino_cmd_spec.rb | 2 +- spec/arduino_installation_spec.rb | 2 +- spec/ci_config_spec.rb | 2 +- spec/cpp_library_spec.rb | 2 +- spec/testsomething_unittests_spec.rb | 2 +- 13 files changed, 16 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3457723d..c19f6679 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added - Explicit checks that the requested test platforms are defined in YML -- Arduino command wrapper can now guess whether a library is installed -- CPP library class now reaches into included Arduino libraries for source files +- Method to guess whether a library is installed ### Changed - Refactored documentation diff --git a/exe/arduino_ci_remote.rb b/exe/arduino_ci_remote.rb index 11852256..4d12723b 100755 --- a/exe/arduino_ci_remote.rb +++ b/exe/arduino_ci_remote.rb @@ -74,7 +74,7 @@ def assured_platform(purpose, name, config) # initialize library under test installed_library_path = assure("Installing library under test") { @arduino_cmd.install_local_library(".") } library_examples = @arduino_cmd.library_examples(installed_library_path) -cpp_library = ArduinoCI::CppLibrary.new(installed_library_path, @arduino_cmd.lib_dir) +cpp_library = ArduinoCI::CppLibrary.new(installed_library_path) attempt("Library installed at #{installed_library_path}") { true } # check GCC diff --git a/lib/arduino_ci/arduino_cmd.rb b/lib/arduino_ci/arduino_cmd.rb index af6188e4..711cacae 100644 --- a/lib/arduino_ci/arduino_cmd.rb +++ b/lib/arduino_ci/arduino_cmd.rb @@ -66,8 +66,8 @@ def parse_pref_string(arduino_output) end # @return [String] the path to the Arduino libraries directory - def lib_dir - "" + def _lib_dir + "" end # fetch preferences in their raw form @@ -190,7 +190,7 @@ def install_library(library_name) # @param library_name [String] The name of the library # @return [String] The fully qualified library name def library_path(library_name) - File.join(lib_dir, library_name) + File.join(_lib_dir, library_name) end # Determine whether a library is present in the lib dir diff --git a/lib/arduino_ci/arduino_cmd_linux.rb b/lib/arduino_ci/arduino_cmd_linux.rb index 7bf8bced..4485162a 100644 --- a/lib/arduino_ci/arduino_cmd_linux.rb +++ b/lib/arduino_ci/arduino_cmd_linux.rb @@ -33,7 +33,7 @@ def _prefs_raw # implementation for Arduino library dir location # @return [String] the path to the Arduino libraries directory - def lib_dir + def _lib_dir File.join(get_pref("sketchbook.path"), "libraries") end diff --git a/lib/arduino_ci/arduino_cmd_linux_builder.rb b/lib/arduino_ci/arduino_cmd_linux_builder.rb index 297e1e73..b4509b6d 100644 --- a/lib/arduino_ci/arduino_cmd_linux_builder.rb +++ b/lib/arduino_ci/arduino_cmd_linux_builder.rb @@ -16,7 +16,7 @@ class ArduinoCmdLinuxBuilder < ArduinoCmd # linux-specific implementation # @return [String] The path to the library dir - def lib_dir + def _lib_dir File.join(get_pref("sketchbook.path"), "libraries") end diff --git a/lib/arduino_ci/arduino_cmd_osx.rb b/lib/arduino_ci/arduino_cmd_osx.rb index 56ccf790..26f8fc82 100644 --- a/lib/arduino_ci/arduino_cmd_osx.rb +++ b/lib/arduino_ci/arduino_cmd_osx.rb @@ -13,7 +13,7 @@ class ArduinoCmdOSX < ArduinoCmd flag :install_library, "--install-library" flag :verify, "--verify" - def lib_dir + def _lib_dir File.join(ENV['HOME'], "Documents", "Arduino", "libraries") end diff --git a/lib/arduino_ci/arduino_cmd_windows.rb b/lib/arduino_ci/arduino_cmd_windows.rb index e4759bde..e542dd4d 100644 --- a/lib/arduino_ci/arduino_cmd_windows.rb +++ b/lib/arduino_ci/arduino_cmd_windows.rb @@ -13,7 +13,7 @@ class ArduinoCmdWindows < ArduinoCmd flag :install_library, "--install-library" flag :verify, "--verify" - def lib_dir + def _lib_dir File.join(ENV['userprofile'], "Documents", "Arduino", "libraries") end diff --git a/lib/arduino_ci/cpp_library.rb b/lib/arduino_ci/cpp_library.rb index 12e8e8a9..80654b34 100644 --- a/lib/arduino_ci/cpp_library.rb +++ b/lib/arduino_ci/cpp_library.rb @@ -14,9 +14,6 @@ class CppLibrary # @return [String] The path to the library being tested attr_reader :base_dir - # @return [String] The path to the Arduino 3rd-party library directory - attr_reader :arduino_lib_dir - # @return [Array] The set of artifacts created by this class (note: incomplete!) attr_reader :artifacts @@ -30,9 +27,8 @@ class CppLibrary attr_reader :last_cmd # @param base_dir [String] The path to the library being tested - def initialize(base_dir, arduino_lib_dir) + def initialize(base_dir) @base_dir = File.expand_path(base_dir) - @arduino_lib_dir = File.expand_path(arduino_lib_dir) @artifacts = [] @last_err = "" @last_out = "" @@ -87,12 +83,6 @@ def cpp_files_unittest cpp_files_in(UNITTEST_HEADER_DIR) end - # CPP files that are part of the 3rd-party libraries we're including - # @return [Array] - def cpp_files_libraries(aux_libraries) - arduino_library_src_dirs(aux_libraries).map { |d| cpp_files_in(d) }.flatten.uniq - end - # The directory where we expect to find unit test defintions provided by the user # @return [String] def tests_dir @@ -133,24 +123,11 @@ def gcc_version(gcc_binary) @last_err end - # Arduino library directories containing sources - def arduino_library_src_dirs(aux_libraries) - # Pull in all possible places that headers could live, according to the spec: - # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification - # TODO: be smart and implement library spec (library.properties, etc)? - subdirs = ["", "src", "utility"] - all_aux_include_dirs_nested = aux_libraries.map do |libdir| - subdirs.map { |subdir| File.join(@arduino_lib_dir, libdir, subdir) } - end - all_aux_include_dirs_nested.flatten.select { |d| File.exist?(d) } - end - # GCC command line arguments for including aux libraries # @param aux_libraries [String] The external Arduino libraries required by this project # @return [Array] The GCC command-line flags necessary to include those libraries def include_args(aux_libraries) - all_aux_include_dirs = arduino_library_src_dirs(aux_libraries) - places = [ARDUINO_HEADER_DIR, UNITTEST_HEADER_DIR] + header_dirs + all_aux_include_dirs + places = [ARDUINO_HEADER_DIR, UNITTEST_HEADER_DIR] + header_dirs + aux_libraries places.map { |d| "-I#{d}" } end @@ -212,7 +189,6 @@ def build_for_test_with_configuration(test_file, aux_libraries, gcc_binary, ci_g args = [ ["-std=c++0x", "-o", executable, "-DARDUINO=100"], test_args(aux_libraries, ci_gcc_config), - cpp_files_libraries(aux_libraries), [test_file], ].flatten(1) return nil unless run_gcc(gcc_binary, *args) diff --git a/spec/arduino_cmd_spec.rb b/spec/arduino_cmd_spec.rb index 4b02a12c..d656f478 100644 --- a/spec/arduino_cmd_spec.rb +++ b/spec/arduino_cmd_spec.rb @@ -49,7 +49,7 @@ def get_sketch(dir, file) context "libraries" do it "knows where to find libraries" do fake_lib = "_____nope" - expected_dir = File.join(arduino_cmd.lib_dir, fake_lib) + expected_dir = File.join(arduino_cmd._lib_dir, fake_lib) expect(arduino_cmd.library_path(fake_lib)).to eq(expected_dir) expect(arduino_cmd.library_present?(fake_lib)).to be false end diff --git a/spec/arduino_installation_spec.rb b/spec/arduino_installation_spec.rb index 87c81265..16ae8bf9 100644 --- a/spec/arduino_installation_spec.rb +++ b/spec/arduino_installation_spec.rb @@ -11,7 +11,7 @@ arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate! it "doesn't fail" do expect(arduino_cmd.base_cmd).not_to be nil - expect(arduino_cmd.lib_dir).not_to be nil + expect(arduino_cmd._lib_dir).not_to be nil end end diff --git a/spec/ci_config_spec.rb b/spec/ci_config_spec.rb index 0e569cec..077dfc17 100644 --- a/spec/ci_config_spec.rb +++ b/spec/ci_config_spec.rb @@ -110,7 +110,7 @@ context "allowable_unittest_files" do cpp_lib_path = File.join(File.dirname(__FILE__), "fake_library") - cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, "my_fake_arduino_lib_dir") + cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path) it "starts with a known set of files" do expect(cpp_library.test_files.map { |f| File.basename(f) }).to match_array([ diff --git a/spec/cpp_library_spec.rb b/spec/cpp_library_spec.rb index 99298f77..8fdabe48 100644 --- a/spec/cpp_library_spec.rb +++ b/spec/cpp_library_spec.rb @@ -4,7 +4,7 @@ RSpec.describe ArduinoCI::CppLibrary do cpp_lib_path = File.join(sampleproj_path, "DoSomething") - cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, "my_fake_arduino_lib_dir") + cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path) context "cpp_files" do it "finds cpp files in directory" do dosomething_cpp_files = ["DoSomething/do-something.cpp"] diff --git a/spec/testsomething_unittests_spec.rb b/spec/testsomething_unittests_spec.rb index 05d32da0..8a37bdb8 100644 --- a/spec/testsomething_unittests_spec.rb +++ b/spec/testsomething_unittests_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "TestSomething C++" do cpp_lib_path = File.join(sampleproj_path, "TestSomething") - cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, "my_fake_arduino_lib_dir") + cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path) context "cpp_files" do it "finds cpp files in directory" do testsomething_cpp_files = ["TestSomething/test-something.cpp"] From 79bc683cfbce99c7f44d741603fb0989fe57c023 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 11 Sep 2018 10:19:25 -0400 Subject: [PATCH 5/6] Revert "Detect and use (don't re-install) pre-existing Arduino libraries" This reverts commit 164c3a1c5008c79c2eec31193651aca3a5f5593d. --- CHANGELOG.md | 2 -- exe/arduino_ci_remote.rb | 6 +----- lib/arduino_ci/arduino_cmd.rb | 11 ----------- spec/arduino_cmd_spec.rb | 9 --------- 4 files changed, 1 insertion(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c19f6679..5272c0c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added - Explicit checks that the requested test platforms are defined in YML -- Method to guess whether a library is installed ### Changed - Refactored documentation -- External libraries aren't forcibly installed via the Arduino binary (in `arduino_cmd_remote.rb`) if they appear to exist on disk already ### Deprecated diff --git a/exe/arduino_ci_remote.rb b/exe/arduino_ci_remote.rb index 4d12723b..57503817 100755 --- a/exe/arduino_ci_remote.rb +++ b/exe/arduino_ci_remote.rb @@ -119,11 +119,7 @@ def assured_platform(purpose, name, config) end aux_libraries.each do |l| - if @arduino_cmd.library_present?(l) - assure("Using pre-existing library '#{l}'") { true } - else - assure("Installing aux library '#{l}'") { @arduino_cmd.install_library(l) } - end + assure("Installing aux library '#{l}'") { @arduino_cmd.install_library(l) } end # iterate boards / tests diff --git a/lib/arduino_ci/arduino_cmd.rb b/lib/arduino_ci/arduino_cmd.rb index 711cacae..78208fbd 100644 --- a/lib/arduino_ci/arduino_cmd.rb +++ b/lib/arduino_ci/arduino_cmd.rb @@ -193,17 +193,6 @@ def library_path(library_name) File.join(_lib_dir, library_name) end - # Determine whether a library is present in the lib dir - # - # Note that `true` doesn't guarantee that the library is valid/installed - # and `false` doesn't guarantee that the library isn't built-in - # - # @param library_name [String] The name of the library - # @return [bool] - def library_present?(library_name) - File.exist?(library_path(library_name)) - end - # update the library index # @return [bool] Whether the update succeeded def update_library_index diff --git a/spec/arduino_cmd_spec.rb b/spec/arduino_cmd_spec.rb index d656f478..325aea6b 100644 --- a/spec/arduino_cmd_spec.rb +++ b/spec/arduino_cmd_spec.rb @@ -46,15 +46,6 @@ def get_sketch(dir, file) end end - context "libraries" do - it "knows where to find libraries" do - fake_lib = "_____nope" - expected_dir = File.join(arduino_cmd._lib_dir, fake_lib) - expect(arduino_cmd.library_path(fake_lib)).to eq(expected_dir) - expect(arduino_cmd.library_present?(fake_lib)).to be false - end - end - context "set_pref" do it "Sets key to what it was before" do From fded01d770f6ec7959b180e2c5aa2d09d9f85d32 Mon Sep 17 00:00:00 2001 From: Ian Date: Tue, 11 Sep 2018 10:19:25 -0400 Subject: [PATCH 6/6] Revert "Explicitly check for Arduino platforms in build script" This reverts commit 08930e546cf584eb6b550d991289fb08e8006165. --- CHANGELOG.md | 1 - exe/arduino_ci_remote.rb | 16 +++------------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5272c0c3..241253e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added -- Explicit checks that the requested test platforms are defined in YML ### Changed - Refactored documentation diff --git a/exe/arduino_ci_remote.rb b/exe/arduino_ci_remote.rb index 57503817..75269382 100755 --- a/exe/arduino_ci_remote.rb +++ b/exe/arduino_ci_remote.rb @@ -55,16 +55,7 @@ def attempt_multiline(message, &block) # Make a nice status for something that kills the script immediately on failure def assure(message, &block) - perform_action(message, false, "This may indicate a problem with ArduinoCI, or your configuration", true, &block) -end - -# Assure that a platform exists and return its definition -def assured_platform(purpose, name, config) - platform_definition = config.platform_definition(name) - assure("Requested #{purpose} platform '#{name}' is defined in 'platforms' YML") do - !platform_definition.nil? - end - platform_definition + perform_action(message, false, "This may indicate a problem with ArduinoCI!", true, &block) end # initialize command and config @@ -94,11 +85,10 @@ def assured_platform(purpose, name, config) # while we're doing that, get the aux libraries as well all_platforms = {} aux_libraries = Set.new(config.aux_libraries_for_unittest + config.aux_libraries_for_build) -# while collecting the platforms, ensure they're defined -config.platforms_to_unittest.each { |p| all_platforms[p] = assured_platform("unittest", p, config) } +config.platforms_to_unittest.each { |p| all_platforms[p] = config.platform_definition(p) } library_examples.each do |path| ovr_config = config.from_example(path) - ovr_config.platforms_to_build.each { |p| all_platforms[p] = assured_platform("library example", p, config) } + ovr_config.platforms_to_build.each { |p| all_platforms[p] = config.platform_definition(p) } aux_libraries.merge(ovr_config.aux_libraries_for_build) end