arduino_ci 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81bed39a97b584fc45ff028f60c9eeb50e24e929123e3af0ca9e6db48ffc5d1a
4
- data.tar.gz: 4ee99e35584eaa5db713d80149b1ce7bead47f8e3ac74d1016e82fdb11f1b1c0
3
+ metadata.gz: 82a935a3542b8ab937b7176122e9db548ce380680c2d79705106bfe452c8e527
4
+ data.tar.gz: 5924a473a766721cf3ce2c7a3b47536c0ab57afae539e506349a3d4691d6d401
5
5
  SHA512:
6
- metadata.gz: 64286125ad20ef12fda79a938d29f44d20751db0716144149a660afb350da73f08ef0b1d0494b1d472cac6d50d2cbdc48ce1e4697736f509fbc036adbb724ac1
7
- data.tar.gz: 40620b0806a64191b00c84bdf86f546dd131a5cafdda8cc6da23e9cbd64235f88fa2b7aa9d580d5c05cb47da3f93dd0961f86a18dff344d68de7b7f428a673be
6
+ metadata.gz: 9f09f7ff8912769fe5660e519fddf7b07da5b4774e7719a04154f76ff8fb7fdb8e1ccb6732e17b49ad5b286f33fab6538e8c57f5b94e8487a1bff246d3017c89
7
+ data.tar.gz: 47ee9f776d6fcf2bf5a77de5762b949b131c0fc21fa68663743d79bf4c97bd6e4794da6251e5dbb335611879fb929afe14a69e19b8518c45e58a7496aada4397
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/arduino_ci.svg)](https://rubygems.org/gems/arduino_ci)
2
2
  [![Build Status](https://travis-ci.org/ifreecarve/arduino_ci.svg)](https://travis-ci.org/ifreecarve/arduino_ci)
3
- [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/0.1.6)
3
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/arduino_ci/0.1.7)
4
4
 
5
5
  # ArduinoCI Ruby gem (`arduino_ci`)
6
6
 
@@ -7,8 +7,8 @@
7
7
  template <typename T>
8
8
  class PinHistory : public ObservableDataStream {
9
9
  private:
10
- Queue<T> qIn;
11
- Queue<T> qOut;
10
+ ArduinoCIQueue<T> qIn;
11
+ ArduinoCIQueue<T> qOut;
12
12
 
13
13
  void clear() {
14
14
  qOut.clear();
@@ -16,7 +16,7 @@ class PinHistory : public ObservableDataStream {
16
16
  }
17
17
 
18
18
  // enqueue ascii bits
19
- void a2q(Queue<T> &q, String input, bool bigEndian, bool advertise) {
19
+ void a2q(ArduinoCIQueue<T> &q, String input, bool bigEndian, bool advertise) {
20
20
  // 8 chars at a time, form up
21
21
  for (int j = 0; j < input.length(); ++j) {
22
22
  for (int i = 0; i < 8; ++i) {
@@ -31,10 +31,10 @@ class PinHistory : public ObservableDataStream {
31
31
 
32
32
  // convert a queue to a string as if it was serial bits
33
33
  // start from offset, consider endianness
34
- String q2a(const Queue<T> &q, unsigned int offset, bool bigEndian) const {
34
+ String q2a(const ArduinoCIQueue<T> &q, unsigned int offset, bool bigEndian) const {
35
35
  String ret = "";
36
36
 
37
- Queue<T> q2(q);
37
+ ArduinoCIQueue<T> q2(q);
38
38
 
39
39
  while (offset) {
40
40
  q2.pop();
@@ -135,7 +135,7 @@ class PinHistory : public ObservableDataStream {
135
135
  // copy elements to an array, up to a given length
136
136
  // return the number of elements moved
137
137
  int toArray (T* arr, unsigned int length) const {
138
- Queue<T> q2(qOut);
138
+ ArduinoCIQueue<T> q2(qOut);
139
139
 
140
140
  int ret = 0;
141
141
  for (int i = 0; i < length && q2.size(); ++i) {
@@ -149,7 +149,7 @@ class PinHistory : public ObservableDataStream {
149
149
  // see if the array matches the elements in the queue
150
150
  bool hasElements (T const * const arr, unsigned int length) const {
151
151
  int i;
152
- Queue<T> q2(qOut);
152
+ ArduinoCIQueue<T> q2(qOut);
153
153
  for (i = 0; i < length && q2.size(); ++i) {
154
154
  if (q2.front() != arr[i]) return false;
155
155
  q2.pop();
@@ -25,7 +25,7 @@
25
25
  class DeviceUsingBytes : public DataStreamObserver {
26
26
  public:
27
27
  String mMessage;
28
- Table<String, String> mResponses;
28
+ ArduinoCITable<String, String> mResponses;
29
29
  GodmodeState* state;
30
30
 
31
31
 
@@ -72,7 +72,7 @@ class DataStreamObserver {
72
72
  class ObservableDataStream
73
73
  {
74
74
  private:
75
- Table<String, DataStreamObserver*> mObservers;
75
+ ArduinoCITable<String, DataStreamObserver*> mObservers;
76
76
  bool mAdvertisingBit;
77
77
  unsigned char mAdvertisingByte;
78
78
 
@@ -1,7 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  template <typename T>
4
- class Queue {
4
+ class ArduinoCIQueue {
5
5
  private:
6
6
  struct Node {
7
7
  T data;
@@ -19,9 +19,9 @@ class Queue {
19
19
  }
20
20
 
21
21
  public:
22
- Queue(): mNil() { init(); }
22
+ ArduinoCIQueue(): mNil() { init(); }
23
23
 
24
- Queue(const Queue<T>& q) {
24
+ ArduinoCIQueue(const ArduinoCIQueue<T>& q) {
25
25
  init();
26
26
  for (Node* n = q.mFront; n; n = n->next) push(n->data);
27
27
  }
@@ -69,5 +69,5 @@ class Queue {
69
69
 
70
70
  void clear() { while (!empty()) pop(); }
71
71
 
72
- ~Queue() { clear(); }
72
+ ~ArduinoCIQueue() { clear(); }
73
73
  };
@@ -5,7 +5,7 @@
5
5
  // this is this stupidest table implementation ever but it's
6
6
  // an MVP for unit testing. O(n).
7
7
  template <typename K, typename V>
8
- class Table {
8
+ class ArduinoCITable {
9
9
  private:
10
10
  struct Node {
11
11
  K key;
@@ -25,7 +25,7 @@ class Table {
25
25
  }
26
26
 
27
27
  public:
28
- Table() : mNilK(), mNilV() { init(); }
28
+ ArduinoCITable() : mNilK(), mNilV() { init(); }
29
29
 
30
30
  // number of things in the table
31
31
  inline unsigned long size() const { return mSize; }
@@ -121,5 +121,5 @@ class Table {
121
121
  }
122
122
  }
123
123
 
124
- ~Table() { clear(); }
124
+ ~ArduinoCITable() { clear(); }
125
125
  };
@@ -1,3 +1,3 @@
1
1
  module ArduinoCI
2
- VERSION = "0.1.6".freeze
2
+ VERSION = "0.1.7".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arduino_ci
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Katz
@@ -103,7 +103,6 @@ files:
103
103
  - cpp/arduino/Stream.h
104
104
  - cpp/arduino/WCharacter.h
105
105
  - cpp/arduino/WString.h
106
- - cpp/arduino/WString.h.orig
107
106
  - cpp/arduino/avr/README.md
108
107
  - cpp/arduino/avr/common.h
109
108
  - cpp/arduino/avr/fuse.h
@@ -376,7 +375,6 @@ files:
376
375
  - cpp/arduino/avr/iox8e5.h
377
376
  - cpp/arduino/avr/lock.h
378
377
  - cpp/arduino/avr/pgmspace.h
379
- - cpp/arduino/avr/pgmspace.h.orig
380
378
  - cpp/arduino/avr/portpins.h
381
379
  - cpp/arduino/avr/version.h
382
380
  - cpp/arduino/avr/xmega.h
@@ -399,7 +397,6 @@ files:
399
397
  - lib/arduino_ci/arduino_installation.rb
400
398
  - lib/arduino_ci/ci_config.rb
401
399
  - lib/arduino_ci/cpp_library.rb
402
- - lib/arduino_ci/cpp_library.rb.orig
403
400
  - lib/arduino_ci/display_manager.rb
404
401
  - lib/arduino_ci/host.rb
405
402
  - lib/arduino_ci/version.rb
@@ -1,172 +0,0 @@
1
- #pragma once
2
-
3
- #include <stdlib.h>
4
- #include <string>
5
- #include <algorithm>
6
- #include <iostream>
7
- #include "AvrMath.h"
8
- #include "WCharacter.h"
9
-
10
- typedef std::string string;
11
-
12
- typedef char __FlashStringHelper;
13
- <<<<<<< Updated upstream
14
-
15
- #define F(string_literal) (string_literal)
16
- =======
17
- //class __FlashStringHelper;
18
- #define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
19
- >>>>>>> Stashed changes
20
-
21
- // Compatibility with string class
22
- class String: public string
23
- {
24
- public:
25
-
26
- // allow "string s; if (s) {}"
27
- // http://www.artima.com/cppsource/safebool.html
28
- typedef void (String::*TTDNSCstring)() const;
29
- void ttdnsc() const {}
30
- operator TTDNSCstring() const { return &String::ttdnsc; }
31
-
32
- private:
33
- static const char* digit(int val) {
34
- static const char* bank = "0123456789ABCDEF";
35
- return bank + val;
36
- }
37
-
38
- static string mytoa(unsigned long val, int base) {
39
- int n = val % base;
40
- string place = string(digit(n), 1);
41
- if (val < base) return place;
42
- return mytoa(val / base, base) + place;
43
- }
44
-
45
- static string mytoas(long val, int base) {
46
- string ret = mytoa(abs(val), base);
47
- return 0 <= val ? ret : string("-") + ret;
48
- }
49
-
50
- static string dtoas(double val, int decimalPlaces) {
51
- double r = 0.5 * pow(0.1, decimalPlaces); // make sure that integer truncation will properly round
52
- if (::isnan(val)) return "nan";
53
- if (::isinf(val)) return "inf";
54
- val += val > 0 ? r : -r;
55
- if (val > 4294967040.0) return "ovf";
56
- if (val <-4294967040.0) return "ovf";
57
- return mytoas(val, 10) + "." + mytoa(abs(val - (long)val) * pow(10, decimalPlaces), 10);
58
- }
59
-
60
- public:
61
- ~String(void) {}
62
- String(const char *cstr = ""): string(cstr) {}
63
- String(const string &str): string(str) {}
64
- String(const String &str): string(str) {}
65
- explicit String(char c): string(1, c) {}
66
-
67
- explicit String(unsigned char val, unsigned char base=10): string(mytoa(val, base)) {}
68
- explicit String(int val, unsigned char base=10): string(mytoas(val, base)) {}
69
- explicit String(unsigned int val , unsigned char base=10): string(mytoa(val, base)) {}
70
- explicit String(long val, unsigned char base=10): string(mytoas(val, base)) {}
71
- explicit String(unsigned long val, unsigned char base=10): string(mytoa(val, base)) {}
72
-
73
- explicit String(float val, unsigned char decimalPlaces=2): string(dtoas(val, decimalPlaces)) {}
74
- explicit String(double val, unsigned char decimalPlaces=2): string(dtoas(val, decimalPlaces)) {}
75
-
76
- String & operator = (const String &rhs) { assign(rhs); return *this; }
77
- String & operator = (const string &rhs) { assign(rhs); return *this; }
78
- String & operator = (const char *cstr) { assign(cstr); return *this; }
79
- String & operator = (const char c) { assign(1, c); return *this; }
80
-
81
- unsigned char concat(const String &str) { append(str); return 1; }
82
- unsigned char concat(const char *cstr) { append(cstr); return 1; }
83
- unsigned char concat(char c) { append(1, c); return 1; }
84
- unsigned char concat(unsigned char c) { append(1, c); return 1; }
85
- unsigned char concat(int num) { append(String(num)); return 1; }
86
- unsigned char concat(unsigned int num) { append(String(num)); return 1; }
87
- unsigned char concat(long num) { append(String(num)); return 1; }
88
- unsigned char concat(unsigned long num) { append(String(num)); return 1; }
89
- unsigned char concat(float num) { append(String(num)); return 1; }
90
- unsigned char concat(double num) { append(String(num)); return 1; }
91
-
92
- String & operator += (const String &rhs) { concat(rhs); return *this; }
93
- String & operator += (const char *cstr) { concat(cstr); return *this; }
94
- String & operator += (char c) { concat(c); return *this; }
95
- String & operator += (unsigned char num) { concat(num); return *this; }
96
- String & operator += (int num) { concat(num); return *this; }
97
- String & operator += (unsigned int num) { concat(num); return *this; }
98
- String & operator += (long num) { concat(num); return *this; }
99
- String & operator += (unsigned long num) { concat(num); return *this; }
100
- String & operator += (float num) { concat(num); return *this; }
101
- String & operator += (double num) { concat(num); return *this; }
102
-
103
-
104
- int compareTo(const String &s) const { return compare(s); }
105
- unsigned char equals(const String &s) const { return compareTo(s) == 0; }
106
- unsigned char equals(const char *cstr) const { return compareTo(String(cstr)) == 0; }
107
- unsigned char equal(const String &s) const { return equals(s); }
108
- unsigned char equal(const char *cstr) const { return equals(cstr); }
109
- unsigned char equalsIgnoreCase(const String &s) const {
110
- String a = String(*this);
111
- String b = String(s);
112
- a.toUpperCase();
113
- b.toUpperCase();
114
- return a.compare(b) == 0;
115
- }
116
-
117
- unsigned char startsWith(const String &prefix) const { return find(prefix) == 0; }
118
- unsigned char startsWith(const String &prefix, unsigned int offset) const { return find(prefix, offset) == offset; }
119
- unsigned char endsWith(const String &suffix) const { return rfind(suffix) == length() - suffix.length(); }
120
-
121
- char charAt(unsigned int index) const { return operator[](index); }
122
- void setCharAt(unsigned int index, char c) { (*this)[index] = c; }
123
-
124
- void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const { copy((char*)buf, bufsize, index); }
125
- void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
126
- { getBytes((unsigned char *)buf, bufsize, index); }
127
-
128
- int indexOf( char ch ) const { return find(ch); }
129
- int indexOf( char ch, unsigned int fromIndex ) const { return find(ch, fromIndex); }
130
- int indexOf( const String &str ) const { return find(str); }
131
- int indexOf( const String &str, unsigned int fromIndex ) const { return find(str, fromIndex); }
132
- int lastIndexOf( char ch ) const { return rfind(ch); }
133
- int lastIndexOf( char ch, unsigned int fromIndex ) const { return rfind(ch, fromIndex); }
134
- int lastIndexOf( const String &str ) const { return rfind(str); }
135
- int lastIndexOf( const String &str, unsigned int fromIndex ) const { return rfind(str, fromIndex); }
136
- String substring( unsigned int beginIndex ) const { return String(substr(beginIndex)); }
137
- String substring( unsigned int beginIndex, unsigned int endIndex ) const { return String(substr(beginIndex, endIndex)); }
138
-
139
- void replace(const String& target, const String& repl) {
140
- int i = 0;
141
- while ((i = find(target, i)) != npos) {
142
- assign(substr(0, i) + repl + substr(i + target.length()));
143
- i += repl.length();
144
- }
145
- }
146
- void replace(char target, char repl) {
147
- replace(String(target), String(repl));
148
- }
149
- void remove(unsigned int index) { assign(substr(0, index)); }
150
- void remove(unsigned int index, unsigned int count) { assign(substr(0, index) + substr(min(length(), index + count), count)); }
151
- void toLowerCase(void) { std::transform(begin(), end(), begin(), ::tolower); }
152
- void toUpperCase(void) { std::transform(begin(), end(), begin(), ::toupper); }
153
-
154
- void trim(void) {
155
- int b;
156
- int e;
157
- for (b = 0; b < length() && isSpace(charAt(b)); ++b);
158
- for (e = length() - 1; e > b && isSpace(charAt(e)); --e);
159
- assign(substr(b, e - b + 1));
160
- }
161
-
162
- long toInt(void) const { return std::stol(*this); }
163
- float toFloat(void) const { return std::stof(*this); }
164
- double toDouble(void) const { return std::stod(*this); }
165
-
166
- };
167
-
168
- inline std::ostream& operator << ( std::ostream& out, const String& bs ) {
169
- out << bs.c_str();
170
- return out;
171
- }
172
-
@@ -1,95 +0,0 @@
1
- #pragma once
2
-
3
-
4
- /*
5
- def d(var_raw)
6
- var = var_raw.split("_")[0]
7
- out = "#define #{var}_P(...) ::#{var}(__VA_ARGS__)\n"
8
- IO.popen('pbcopy', 'w') { |f| f << out }
9
- out
10
- end
11
-
12
- text = File.open("arduino-1.8.5/hardware/tools/avr/avr/include/avr/pgmspace.h").read
13
- externs = text.split("\n").select {|l| l.start_with? "extern"}
14
- out = externs.map {|l| l.split("(")[0].split(" ")[-1].gsub("*", "") }.uniq
15
- out.each { |l| puts d(l) }
16
- */
17
-
18
- #include <avr/io.h>
19
- #include <string>
20
-
21
- #define PROGMEM
22
-
23
- #ifndef PGM_P
24
- #define PGM_P const char *
25
- #endif
26
-
27
- #ifndef PGM_VOID_P
28
- #define PGM_VOID_P const void *
29
- #endif
30
-
31
- // everything's a no-op
32
- #define PSTR(s) ((const char *)(s))
33
- #define pgm_read_byte_near(x) (x)
34
- #define pgm_read_word_near(x) (x)
35
- #define pgm_read_dword_near(x) (x)
36
- #define pgm_read_float_near(x) (x)
37
- #define pgm_read_ptr_near(x) (x)
38
-
39
- #define pgm_read_byte_far(x) (x)
40
- #define pgm_read_word_far(x) (x)
41
- #define pgm_read_dword_far(x) (x)
42
- #define pgm_read_float_far(x) (x)
43
- #define pgm_read_ptr_far(x) (x)
44
-
45
-
46
- #define pgm_read_byte(x) (x)
47
- #define pgm_read_word(x) (x)
48
- #define pgm_read_dword(x) (x)
49
- #define pgm_read_float(x) (x)
50
- #define pgm_read_ptr(x) (x)
51
- #define pgm_get_far_address(x) (x)
52
-
53
- #define memchr_P(...) ::memchr(__VA_ARGS__)
54
- #define memcmp_P(...) ::memcmp(__VA_ARGS__)
55
- #define memccpy_P(...) ::memccpy(__VA_ARGS__)
56
- #define memcpy_P(...) ::memcpy(__VA_ARGS__)
57
- #define memmem_P(...) ::memmem(__VA_ARGS__)
58
- #define memrchr_P(...) ::memrchr(__VA_ARGS__)
59
- #define strcat_P(...) ::strcat(__VA_ARGS__)
60
- #define strchr_P(...) ::strchr(__VA_ARGS__)
61
- #define strchrnul_P(...) ::strchrnul(__VA_ARGS__)
62
- #define strcmp_P(...) ::strcmp(__VA_ARGS__)
63
- #define strcpy_P(...) ::strcpy(__VA_ARGS__)
64
- #define strcasecmp_P(...) ::strcasecmp(__VA_ARGS__)
65
- #define strcasestr_P(...) ::strcasestr(__VA_ARGS__)
66
- #define strcspn_P(...) ::strcspn(__VA_ARGS__)
67
- #define strlcat_P(...) ::strlcat(__VA_ARGS__)
68
- #define strlcpy_P(...) ::strlcpy(__VA_ARGS__)
69
- #define strnlen_P(...) ::strnlen(__VA_ARGS__)
70
- #define strncmp_P(...) ::strncmp(__VA_ARGS__)
71
- #define strncasecmp_P(...) ::strncasecmp(__VA_ARGS__)
72
- #define strncat_P(...) ::strncat(__VA_ARGS__)
73
- #define strncpy_P(...) ::strncpy(__VA_ARGS__)
74
- #define strpbrk_P(...) ::strpbrk(__VA_ARGS__)
75
- #define strrchr_P(...) ::strrchr(__VA_ARGS__)
76
- #define strsep_P(...) ::strsep(__VA_ARGS__)
77
- #define strspn_P(...) ::strspn(__VA_ARGS__)
78
- #define strstr_P(...) ::strstr(__VA_ARGS__)
79
- #define strtok_P(...) ::strtok(__VA_ARGS__)
80
- #define strtok_P(...) ::strtok(__VA_ARGS__)
81
- #define strlen_P(...) ::strlen(__VA_ARGS__)
82
- #define strnlen_P(...) ::strnlen(__VA_ARGS__)
83
- #define memcpy_P(...) ::memcpy(__VA_ARGS__)
84
- #define strcpy_P(...) ::strcpy(__VA_ARGS__)
85
- #define strncpy_P(...) ::strncpy(__VA_ARGS__)
86
- #define strcat_P(...) ::strcat(__VA_ARGS__)
87
- #define strlcat_P(...) ::strlcat(__VA_ARGS__)
88
- #define strncat_P(...) ::strncat(__VA_ARGS__)
89
- #define strcmp_P(...) ::strcmp(__VA_ARGS__)
90
- #define strncmp_P(...) ::strncmp(__VA_ARGS__)
91
- #define strcasecmp_P(...) ::strcasecmp(__VA_ARGS__)
92
- #define strncasecmp_P(...) ::strncasecmp(__VA_ARGS__)
93
- #define strstr_P(...) ::strstr(__VA_ARGS__)
94
- #define strlcpy_P(...) ::strlcpy(__VA_ARGS__)
95
- #define memcmp_P(...) ::memcmp(__VA_ARGS__)
@@ -1,215 +0,0 @@
1
- require 'find'
2
- require "arduino_ci/host"
3
-
4
- HPP_EXTENSIONS = [".hpp", ".hh", ".h", ".hxx", ".h++"].freeze
5
- CPP_EXTENSIONS = [".cpp", ".cc", ".c", ".cxx", ".c++"].freeze
6
- ARDUINO_HEADER_DIR = File.expand_path("../../../cpp/arduino", __FILE__)
7
- UNITTEST_HEADER_DIR = File.expand_path("../../../cpp/unittest", __FILE__)
8
-
9
- module ArduinoCI
10
-
11
- # Information about an Arduino CPP library, specifically for compilation purposes
12
- class CppLibrary
13
-
14
- # @return [String] The path to the library being tested
15
- attr_reader :base_dir
16
-
17
- # @return [Array<String>] The set of artifacts created by this class (note: incomplete!)
18
- attr_reader :artifacts
19
-
20
- # @return [String] STDERR from the last command
21
- attr_reader :last_err
22
-
23
- # @return [String] STDOUT from the last command
24
- attr_reader :last_out
25
-
26
- # @return [String] the last command
27
- attr_reader :last_cmd
28
-
29
- # @param base_dir [String] The path to the library being tested
30
- def initialize(base_dir)
31
- @base_dir = File.expand_path(base_dir)
32
- @artifacts = []
33
- @last_err = ""
34
- @last_out = ""
35
- @last_msg = ""
36
- end
37
-
38
- # Guess whether a file is part of the vendor bundle (indicating we should ignore it).
39
- #
40
- # This assumes the vendor bundle will be at `vendor/bundle` and not some other location
41
- # @param path [String] The path to check
42
- # @return [Array<String>] The paths of the found files
43
- def vendor_bundle?(path)
44
- # TODO: look for Gemfile, look for .bundle/config and get BUNDLE_PATH from there?
45
- base = File.join(@base_dir, "vendor")
46
- real = File.join(File.realpath(@base_dir), "vendor")
47
- return true if path.start_with?(base)
48
- return true if path.start_with?(real)
49
- false
50
- end
51
-
52
- # Get a list of all CPP source files in a directory and its subdirectories
53
- # @param some_dir [String] The directory in which to begin the search
54
- # @return [Array<String>] The paths of the found files
55
- def cpp_files_in(some_dir)
56
- return [] unless File.exist?(some_dir)
57
- real = File.realpath(some_dir)
58
- files = Find.find(real).reject { |path| File.directory?(path) }
59
- ret = files.select { |path| CPP_EXTENSIONS.include?(File.extname(path)) }
60
- ret
61
- end
62
-
63
- # CPP files that are part of the project library under test
64
- # @return [Array<String>]
65
- def cpp_files
66
- real_tests_dir = File.realpath(tests_dir)
67
- cpp_files_in(@base_dir).reject do |p|
68
- next true if File.dirname(p).include?(tests_dir)
69
- next true if File.dirname(p).include?(real_tests_dir)
70
- next true if vendor_bundle?(p)
71
- end
72
- end
73
-
74
- # CPP files that are part of the arduino mock library we're providing
75
- # @return [Array<String>]
76
- def cpp_files_arduino
77
- cpp_files_in(ARDUINO_HEADER_DIR)
78
- end
79
-
80
- # CPP files that are part of the unit test library we're providing
81
- # @return [Array<String>]
82
- def cpp_files_unittest
83
- cpp_files_in(UNITTEST_HEADER_DIR)
84
- end
85
-
86
- # The directory where we expect to find unit test defintions provided by the user
87
- # @return [String]
88
- def tests_dir
89
- File.join(@base_dir, "test")
90
- end
91
-
92
- # The files provided by the user that contain unit tests
93
- # @return [Array<String>]
94
- def test_files
95
- cpp_files_in(tests_dir)
96
- end
97
-
98
- # Find all directories in the project library that include C++ header files
99
- # @return [Array<String>]
100
- def header_dirs
101
- real = File.realpath(@base_dir)
102
- all_files = Find.find(real).reject { |path| File.directory?(path) }
103
- unbundled = all_files.reject { |path| vendor_bundle?(path) }
104
- files = unbundled.select { |path| HPP_EXTENSIONS.include?(File.extname(path)) }
105
- ret = files.map { |path| File.dirname(path) }.uniq
106
- ret
107
- end
108
-
109
- # wrapper for the GCC command
110
- def run_gcc(*args, **kwargs)
111
- full_args = ["g++-4.9"] + args
112
- @last_cmd = " $ #{full_args.join(' ')}"
113
- <<<<<<< Updated upstream
114
-
115
- =======
116
- >>>>>>> Stashed changes
117
- ret = Host.run_and_capture(*full_args, **kwargs)
118
- @last_err = ret[:err]
119
- @last_out = ret[:out]
120
- ret[:success]
121
- end
122
-
123
- # Return the GCC version
124
- # @return [String] the version reported by `gcc -v`
125
- def gcc_version
126
- return nil unless run_gcc("-v")
127
- @last_err
128
- end
129
-
130
- # GCC command line arguments for including aux libraries
131
- # @param aux_libraries [String] The external Arduino libraries required by this project
132
- # @return [Array<String>] The GCC command-line flags necessary to include those libraries
133
- def include_args(aux_libraries)
134
- places = [ARDUINO_HEADER_DIR, UNITTEST_HEADER_DIR] + header_dirs + aux_libraries
135
- places.map { |d| "-I#{d}" }
136
- end
137
-
138
- # GCC command line arguments for features (e.g. -fno-weak)
139
- # @param ci_gcc_config [Hash] The GCC config object
140
- # @return [Array<String>] GCC command-line flags
141
- def feature_args(ci_gcc_config)
142
- return [] if ci_gcc_config[:features].nil?
143
- ci_gcc_config[:features].map { |f| "-f#{f}" }
144
- end
145
-
146
- # GCC command line arguments for warning (e.g. -Wall)
147
- # @param ci_gcc_config [Hash] The GCC config object
148
- # @return [Array<String>] GCC command-line flags
149
- def warning_args(ci_gcc_config)
150
- return [] if ci_gcc_config[:warnings].nil?
151
- ci_gcc_config[:features].map { |w| "-W#{w}" }
152
- end
153
-
154
- # GCC command line arguments for defines (e.g. -Dhave_something)
155
- # @param ci_gcc_config [Hash] The GCC config object
156
- # @return [Array<String>] GCC command-line flags
157
- def define_args(ci_gcc_config)
158
- return [] if ci_gcc_config[:defines].nil?
159
- ci_gcc_config[:defines].map { |d| "-D#{d}" }
160
- end
161
-
162
- # GCC command line arguments as-is
163
- # @param ci_gcc_config [Hash] The GCC config object
164
- # @return [Array<String>] GCC command-line flags
165
- def flag_args(ci_gcc_config)
166
- return [] if ci_gcc_config[:flags].nil?
167
- ci_gcc_config[:flags]
168
- end
169
-
170
- # All GCC command line args for building any unit test
171
- # @param aux_libraries [String] The external Arduino libraries required by this project
172
- # @param ci_gcc_config [Hash] The GCC config object
173
- # @return [Array<String>] GCC command-line flags
174
- def test_args(aux_libraries, ci_gcc_config)
175
- # TODO: something with libraries?
176
- ret = include_args(aux_libraries) + cpp_files_arduino + cpp_files_unittest + cpp_files
177
- unless ci_gcc_config.nil?
178
- cgc = ci_gcc_config
179
- ret = feature_args(cgc) + warning_args(cgc) + define_args(cgc) + flag_args(cgc) + ret
180
- end
181
- ret
182
- end
183
-
184
- # build a file for running a test of the given unit test file
185
- # @param test_file [String] The path to the file containing the unit tests
186
- # @param aux_libraries [String] The external Arduino libraries required by this project
187
- # @param ci_gcc_config [Hash] The GCC config object
188
- # @return [String] path to the compiled test executable
189
- def build_for_test_with_configuration(test_file, aux_libraries, ci_gcc_config)
190
- base = File.basename(test_file)
191
- executable = File.expand_path("unittest_#{base}.bin")
192
- File.delete(executable) if File.exist?(executable)
193
- args = [
194
- ["-std=c++0x", "-o", executable, "-DARDUINO=100"],
195
- test_args(aux_libraries, ci_gcc_config),
196
- [test_file],
197
- ].flatten(1)
198
- return nil unless run_gcc(*args)
199
- artifacts << executable
200
- executable
201
- end
202
-
203
- # run a test file
204
- # @param [String] the path to the test file
205
- # @return [bool] whether all tests were successful
206
- def run_test_file(executable)
207
- @last_cmd = executable
208
- @last_out = ""
209
- @last_err = ""
210
- Host.run_and_output(executable)
211
- end
212
-
213
- end
214
-
215
- end