arduino_sketch_builder 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: e29a1ee1ac0e35fdbb247b9acd642b26cfaf8db6
4
- data.tar.gz: 838d0585f920ca96720d2b42dab900e1d794c116
3
+ metadata.gz: 8a21314e76b1a911cc53e4b0d20fd38fff6787c4
4
+ data.tar.gz: ca1a3bc1e35042c4049d11ae3f524cf21a4838f2
5
5
  SHA512:
6
- metadata.gz: a64eb3e51947d7cf7327e961590fd1d95517531cab86e2cd7e41c46f980ff1e0d9f46260cd5d47f43e2796bde97946c557239a54f5af5ba8a57f699e31bd732e
7
- data.tar.gz: 6a2771b672a28add2eef4db65546755bf8779066822f809f45a462ddabcfb2665619aa0aa0b2c28aa3334a62bfe39dc5f3b2ba001cb29bc1cc830906e8d77fcc
6
+ metadata.gz: b3f041cbe7406472bec5fd9f3673e4d054e003c037a4fb4dd326ecfd23a6c9c28207188a3abfb567bc49d8ada66049e5677063a90b3a2ca5560b588f37e6484c
7
+ data.tar.gz: 4a79152cdcc5ac45a0b7c185b2b0c110393273b2fbd20566d026e9a16209edcbaa9900c92883be432256723b12e6ac8854b3f6c8bdb9cc960011d0bb772ea07f
data/README.md CHANGED
@@ -19,48 +19,132 @@ Or install it yourself as:
19
19
 
20
20
  ## Requirements
21
21
 
22
- Works with Ruby 1.9.3 and Ruby 2.0.0 (Tested with them).
22
+ Ruby 2.0.0 or more.
23
+
24
+ * If ARDUINO_DEFAULT_BOARD and ARDUINO_DEFAULT_PORT are used to specify the board ID (e.g uno) and the port (e.g. /dev/tty.usbmodem411) instead of passing them to the method in Ruby code, works with Ruby 1.9.3, too.
25
+ * Strongly recommended to use Ruby 2.0.0 since this gem is intended to use its benefits and Ruby 2.0.0 is compatible with Ruby 1.9.3 if you need to run other code written for Ruby 1.9.3 with this gem.
23
26
 
24
27
  Arduino SDK version 0.19 or higher.
25
28
 
26
- ## Usage
29
+ cmake - http://www.cmake.org/cmake/resources/software.html
27
30
 
28
31
  ### Arduino CMake
29
32
 
30
33
  This gem uses the code from **Arduino CMake** (https://github.com/queezythegreat/arduino-cmake).
34
+
31
35
  Originally, **Arduino CMake** was included as GIT submodule in this gem.
32
36
  But there was a problem so now the necessary **Arduino CMake** codes are copied in this gem (arduino-cmake directory).
33
37
 
38
+ ## Usage
39
+
34
40
  ### Directory structure
35
41
 
42
+ This is based on the directory structure by **Arduino CMake** with modification to make the directory structure for each Arduino sketch indepedent from each other.
43
+
44
+ It is also for not putting cmake related files in the default Arduino directory used by Arduino IDE.
45
+
46
+ This directory structure can be set up the code from this gem (See "Code example" below).
47
+
48
+ Also GIT related files (such as .gitignore and .gitkeep) are automatically added (but doesn't execute GIT commands so if GIT is not used, those files can be simply ignored).
49
+
36
50
  The default directory structure is
37
- The default directory structure is
38
- (root directory)
39
- |- cmake
40
- | |- ArduinoToolchain.cmake
41
- | |- Platform
42
- | |- Arduino.cmake
43
- |- (name of Arduino sketch underlined)
44
- |--build
45
- |--src
46
- | |--(name of Arduino sketch)
47
- | |--(Arduino sketch file)
48
- | |--CMakeLists.txt
49
- |--CMakeLists.txt
51
+
52
+ (root directory)
53
+ |- cmake
54
+ | |- ArduinoToolchain.cmake
55
+ | |- Platform
56
+ | |- Arduino.cmake
57
+ |- libraries
58
+ |- (name of Arduino sketch underlined)
59
+ |--build
60
+ |--src
61
+ | |--(name of Arduino sketch)
62
+ | |--(Arduino sketch file)
63
+ | |--CMakeLists.txt
64
+ |--CMakeLists.txt
50
65
 
51
66
  example:
52
- ~/.arduino_sketches
53
- |- cmake
54
- | |- ArduinoToolchain.cmake
55
- | |- Platform
56
- | |- Arduino.cmake
57
- |- blink_customized
58
- |--build
59
- |--src
60
- | |--BlinkCustomized
61
- | |--BlinkCustomized.ino
62
- | |--CMakeLists.txt
63
- |--CMakeLists.txt
67
+
68
+ ~/.arduino_sketches
69
+ |- cmake
70
+ | |- ArduinoToolchain.cmake
71
+ | |- Platform
72
+ | |- Arduino.cmake
73
+ |- libraries
74
+ |- blink_customized
75
+ |--build
76
+ |--src
77
+ | |--BlinkCustomized
78
+ | |--BlinkCustomized.ino
79
+ | |--CMakeLists.txt
80
+ |--CMakeLists.txt
81
+
82
+ ### Arduino board type and port to access the board
83
+
84
+ The default board ID: uno
85
+
86
+ The default port: /dev/tty.usbmodem411
87
+
88
+ You can change them by setting ARDUINO_DEFAULT_BOARD and ARDUINO_DEFAULT_PORT environment variables.
89
+
90
+ ### Code example
91
+
92
+ #### Setting up the directory structure - like the one above under cmake directory
93
+
94
+ require "arduino_sketch_builder"
95
+
96
+ setup = ArduinoSketchBuilder::Setup.new
97
+
98
+ # Configuring ArduinoSketchBuilder (copies cmake directory under the specified root_directory):
99
+ root_directory = File.expand_path('~/.arduino_sketches')
100
+ setup.configure(root_directory)
101
+
102
+ #### Setting up the sketch specific directory structure and files - like the one above under (name of Arduino sketch underlined) directory
103
+
104
+ require "arduino_sketch_builder"
105
+
106
+ setup = ArduinoSketchBuilder::Setup.new
107
+
108
+ # Configuring ArduinoSketchBuilder (copies cmake directory under the specified root_directory):
109
+ root_directory = File.expand_path('~/.arduino_sketches')
110
+ # Path to the sketch to be put under the directory structure:
111
+ arduino_sketch_file_path = File.expand_path('~/temp/BlinkCustomized.ino')
112
+ setup.setup(root_directory, arduino_sketch_file_path)
113
+
114
+ #### Executing cmake commands - compile, make, and make upload
115
+
116
+ require "arduino_sketch_builder"
117
+
118
+ main_directory = File.expand_path('~/.arduino_sketches/blink_customized')
119
+ build_directory = File.join(main_directory, "build")
120
+
121
+ # Instantiate ArduinoCmakeBuild with state == :initial (It's a state machine):
122
+ arduino_cmake_build = ArduinoSketchBuilder::ArduinoCmakeBuild.new(main_directory, build_directory)
123
+
124
+ # Execute cmake
125
+ # raises error if state at the point of execution is not :initial (i.e. precondition: state == :initial)
126
+ # Success: state == :cmake_complete
127
+ # Failure: state == :cmake_incomplete
128
+ # arduino_cmake_build.message gives message such as error message in case of failure.
129
+ state = arduino_cmake_build.cmake
130
+
131
+ # Execute make
132
+ # raises error if state at the point of execution is not :cmake_complete (i.e. precondition: state == :cmake_complete)
133
+ # Success: state == :make_complete
134
+ # Failure: state == :make_incomplete
135
+ # arduino_cmake_build.message gives message such as error message in case of failure.
136
+ state = arduino_cmake_build.make
137
+
138
+ # Execute make upload
139
+ # raises error if state at the point of execution is not :make_complete (i.e. precondition: state == :make_complete)
140
+ # Success: state == :make_upload_complete
141
+ # Failure: state == :make_upload_incomplete
142
+ # arduino_cmake_build.message gives message such as error message in case of failure.
143
+ state = arduino_cmake_build.make_upload
144
+
145
+ ## TODOS
146
+
147
+ - The library should be able to be put under (root directory)/libraries
64
148
 
65
149
  ## Contributing
66
150
 
@@ -11,7 +11,9 @@ class ArduinoSketchBuilder::ArduinoCmakeBuild
11
11
 
12
12
  STATE_SEQUENCE = [INITIAL, CMAKE_COMPLETE, MAKE_COMPLETE, MAKE_UPLOAD_COMPLETE]
13
13
 
14
- def initialize
14
+ def initialize(main_directory, build_directory)
15
+ @main_directory = main_directory
16
+ @build_directory = build_directory
15
17
  @state = INITIAL
16
18
  end
17
19
 
@@ -25,15 +27,15 @@ class ArduinoSketchBuilder::ArduinoCmakeBuild
25
27
 
26
28
  [:cmake, :make, :make_upload].each_with_index do |method_name, index|
27
29
 
28
- define_method(method_name) do |build_directory, main_directory=nil|
30
+ define_method(method_name) do
29
31
 
30
32
  unless @state == STATE_SEQUENCE[index]
31
33
  raise "Wrong state '#{self.state}': can't call #{method_name} when the state is not '#{STATE_SEQUENCE[index].value}'"
32
34
  end
33
35
 
34
- Dir.chdir(build_directory)
36
+ Dir.chdir(@build_directory)
35
37
 
36
- Open3.popen3("#{method_name.to_s.sub('_',' ')} #{main_directory ? main_directory : ''}") do |stdin, stdout, stderr, wait_thread|
38
+ Open3.popen3("#{method_name.to_s.sub('_',' ')} #{method_name == :cmake ? @main_directory : ''}") do |stdin, stdout, stderr, wait_thread|
37
39
  pid = wait_thread.pid
38
40
  exit_status = wait_thread.value
39
41
  if exit_status.success?
@@ -6,6 +6,8 @@ class ArduinoSketchBuilder::CMakeListsFileGenerator
6
6
 
7
7
  attr_reader :root_directory
8
8
  attr_reader :sketch_name
9
+ attr_reader :board_type
10
+ attr_reader :board_port
9
11
 
10
12
  def generate_main(root_directory, c_make_lists_file_directory)
11
13
 
@@ -19,9 +21,11 @@ class ArduinoSketchBuilder::CMakeListsFileGenerator
19
21
 
20
22
  end
21
23
 
22
- def generate_sketch_specific(sketch_name, c_make_lists_file_directory)
24
+ def generate_sketch_specific(sketch_name, c_make_lists_file_directory, board_type: "uno", board_port: "/dev/tty.usbmodem411")
23
25
 
24
26
  @sketch_name = sketch_name
27
+ @board_type = board_type
28
+ @board_port = board_port
25
29
 
26
30
  erb = ERB.new(File.read("#{TEMPLATES_DIRECTORY}/SourceCMakeListsTemplate.txt.erb"))
27
31
 
@@ -1,3 +1,3 @@
1
1
  module ArduinoSketchBuilder
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,7 +7,7 @@ describe ArduinoSketchBuilder::ArduinoCmakeBuild do
7
7
 
8
8
  before(:each) do
9
9
  FileUtils.rm_rf(Dir.glob("#{BUILD_DIRECTORY}/*"))
10
- @arduino_cmake_build = ArduinoSketchBuilder::ArduinoCmakeBuild.new
10
+ @arduino_cmake_build = ArduinoSketchBuilder::ArduinoCmakeBuild.new(MAIN_DIRECTORY, BUILD_DIRECTORY)
11
11
  end
12
12
 
13
13
  after(:each) do
@@ -19,19 +19,19 @@ describe ArduinoSketchBuilder::ArduinoCmakeBuild do
19
19
  @arduino_cmake_build.state.should == :initial
20
20
  File.exists?(File.join(BUILD_DIRECTORY, "Makefile")).should be_false
21
21
 
22
- @arduino_cmake_build.cmake(BUILD_DIRECTORY, MAIN_DIRECTORY).should == :cmake_complete
22
+ @arduino_cmake_build.cmake.should == :cmake_complete
23
23
 
24
24
  @arduino_cmake_build.state.should == :cmake_complete
25
25
  File.exists?(File.join(BUILD_DIRECTORY, "Makefile")).should be_true
26
26
 
27
27
  File.exists?(File.join(BUILD_DIRECTORY, "src", "blink_customized_for_test.hex")).should be_false
28
28
 
29
- @arduino_cmake_build.make(BUILD_DIRECTORY).should == :make_complete
29
+ @arduino_cmake_build.make.should == :make_complete
30
30
 
31
31
  @arduino_cmake_build.state.should == :make_complete
32
32
  File.exists?(File.join(BUILD_DIRECTORY, "src", "blink_customized_for_test.hex")).should be_true
33
33
 
34
- @arduino_cmake_build.make_upload(BUILD_DIRECTORY).should == :make_upload_complete
34
+ @arduino_cmake_build.make_upload.should == :make_upload_complete
35
35
 
36
36
  @arduino_cmake_build.state.should == :make_upload_complete
37
37
 
@@ -40,19 +40,19 @@ describe ArduinoSketchBuilder::ArduinoCmakeBuild do
40
40
  it "should execute cmake only when the state is initial" do
41
41
 
42
42
  @arduino_cmake_build.instance_eval("@state=CMAKE_COMPLETE")
43
- expect { @arduino_cmake_build.cmake(BUILD_DIRECTORY, MAIN_DIRECTORY) }
43
+ expect { @arduino_cmake_build.cmake }
44
44
  .to raise_error("Wrong state 'cmake_complete': can't call cmake when the state is not 'initial'")
45
45
 
46
46
  @arduino_cmake_build.instance_eval("@state=MAKE_COMPLETE")
47
- expect { @arduino_cmake_build.cmake(BUILD_DIRECTORY, MAIN_DIRECTORY) }
47
+ expect { @arduino_cmake_build.cmake }
48
48
  .to raise_error("Wrong state 'make_complete': can't call cmake when the state is not 'initial'")
49
49
 
50
50
  @arduino_cmake_build.instance_eval("@state=MAKE_UPLOAD_COMPLETE")
51
- expect { @arduino_cmake_build.cmake(BUILD_DIRECTORY, MAIN_DIRECTORY) }
51
+ expect { @arduino_cmake_build.cmake }
52
52
  .to raise_error("Wrong state 'make_upload_complete': can't call cmake when the state is not 'initial'")
53
53
 
54
54
  @arduino_cmake_build.instance_eval("@state=INITIAL")
55
- expect { @arduino_cmake_build.cmake(BUILD_DIRECTORY, MAIN_DIRECTORY) }
55
+ expect { @arduino_cmake_build.cmake }
56
56
  .to_not raise_error
57
57
 
58
58
  end
@@ -60,21 +60,21 @@ describe ArduinoSketchBuilder::ArduinoCmakeBuild do
60
60
  it "should execute make only when the state is cmake_complete" do
61
61
 
62
62
  @arduino_cmake_build.instance_eval("@state=INITIAL")
63
- expect { @arduino_cmake_build.make(BUILD_DIRECTORY) }
63
+ expect { @arduino_cmake_build.make }
64
64
  .to raise_error("Wrong state 'initial': can't call make when the state is not 'cmake_complete'")
65
65
 
66
66
  @arduino_cmake_build.instance_eval("@state=MAKE_COMPLETE")
67
- expect { @arduino_cmake_build.make(BUILD_DIRECTORY) }
67
+ expect { @arduino_cmake_build.make }
68
68
  .to raise_error("Wrong state 'make_complete': can't call make when the state is not 'cmake_complete'")
69
69
 
70
70
  @arduino_cmake_build.instance_eval("@state=MAKE_UPLOAD_COMPLETE")
71
- expect { @arduino_cmake_build.make(BUILD_DIRECTORY) }
71
+ expect { @arduino_cmake_build.make }
72
72
  .to raise_error("Wrong state 'make_upload_complete': can't call make when the state is not 'cmake_complete'")
73
73
 
74
74
  @arduino_cmake_build.instance_eval("@state=INITIAL")
75
- @arduino_cmake_build.cmake(BUILD_DIRECTORY, MAIN_DIRECTORY)
75
+ @arduino_cmake_build.cmake
76
76
  @arduino_cmake_build.state.should == :cmake_complete
77
- expect { @arduino_cmake_build.make(BUILD_DIRECTORY) }
77
+ expect { @arduino_cmake_build.make }
78
78
  .to_not raise_error
79
79
 
80
80
  end
@@ -82,22 +82,22 @@ describe ArduinoSketchBuilder::ArduinoCmakeBuild do
82
82
  it "should execute make_upload only when the state is make_complete" do
83
83
 
84
84
  @arduino_cmake_build.instance_eval("@state=INITIAL")
85
- expect { @arduino_cmake_build.make_upload(BUILD_DIRECTORY) }
85
+ expect { @arduino_cmake_build.make_upload }
86
86
  .to raise_error("Wrong state 'initial': can't call make_upload when the state is not 'make_complete'")
87
87
 
88
88
  @arduino_cmake_build.instance_eval("@state=CMAKE_COMPLETE")
89
- expect { @arduino_cmake_build.make_upload(BUILD_DIRECTORY) }
89
+ expect { @arduino_cmake_build.make_upload }
90
90
  .to raise_error("Wrong state 'cmake_complete': can't call make_upload when the state is not 'make_complete'")
91
91
 
92
92
  @arduino_cmake_build.instance_eval("@state=MAKE_UPLOAD_COMPLETE")
93
- expect { @arduino_cmake_build.make_upload(BUILD_DIRECTORY) }
93
+ expect { @arduino_cmake_build.make_upload }
94
94
  .to raise_error("Wrong state 'make_upload_complete': can't call make_upload when the state is not 'make_complete'")
95
95
 
96
96
  @arduino_cmake_build.instance_eval("@state=INITIAL")
97
- @arduino_cmake_build.cmake(BUILD_DIRECTORY, MAIN_DIRECTORY)
98
- @arduino_cmake_build.make(BUILD_DIRECTORY)
97
+ @arduino_cmake_build.cmake
98
+ @arduino_cmake_build.make
99
99
  @arduino_cmake_build.state.should == :make_complete
100
- expect { @arduino_cmake_build.make_upload(BUILD_DIRECTORY) }
100
+ expect { @arduino_cmake_build.make_upload }
101
101
  .to_not raise_error
102
102
 
103
103
  end
@@ -32,4 +32,31 @@ describe ArduinoSketchBuilder::CMakeListsFileGenerator do
32
32
 
33
33
  end
34
34
 
35
+ context "Arduino board type and port" do
36
+
37
+ it "should generate CMakeLists.txt file with the default board ID and port if they are not specified" do
38
+
39
+ File.exists?(File.join(TEMP_DIRECTORY, "CMakeLists.txt")).should be_false
40
+
41
+ @c_make_lists_file_generator.generate_sketch_specific("TestSketch", TEMP_DIRECTORY)
42
+
43
+ File.exists?(File.join(TEMP_DIRECTORY, "CMakeLists.txt")).should be_true
44
+ File.read(File.join(TEMP_DIRECTORY, "CMakeLists.txt")).should == File.read(File.join(FIXTURES_DIRECTORY, "CMakeListsForTestSketch.txt"))
45
+
46
+ end
47
+
48
+ it "should generate CMakeLists.txt file with the specified board ID and port" do
49
+
50
+ File.exists?(File.join(TEMP_DIRECTORY, "CMakeLists.txt")).should be_false
51
+
52
+ @c_make_lists_file_generator.generate_sketch_specific("TestSketch", TEMP_DIRECTORY, board_type: "diecimila", board_port: "/dev/cu.usbmodem411")
53
+
54
+ File.exists?(File.join(TEMP_DIRECTORY, "CMakeLists.txt")).should be_true
55
+ File.read(File.join(TEMP_DIRECTORY, "CMakeLists.txt")).should_not == File.read(File.join(FIXTURES_DIRECTORY, "CMakeListsForTestSketch.txt"))
56
+ File.read(File.join(TEMP_DIRECTORY, "CMakeLists.txt")).should == File.read(File.join(FIXTURES_DIRECTORY, "CMakeListsForTestSketch2.txt"))
57
+
58
+ end
59
+
60
+ end
61
+
35
62
  end
@@ -0,0 +1,10 @@
1
+ set(ARDUINO_DEFAULT_BOARD diecimila) # Default Board ID, when not specified
2
+ set(ARDUINO_DEFAULT_PORT /dev/cu.usbmodem411) # Default Port, when not specified
3
+
4
+ #====================================================================#
5
+ # TestSketch
6
+ #====================================================================#
7
+ generate_arduino_firmware(test_sketch
8
+ SKETCH TestSketch
9
+ PROGRAMMER arduino_sketch_builder
10
+ NO_AUTOLIBS)
@@ -1,5 +1,5 @@
1
- set(ARDUINO_DEFAULT_BOARD uno) # Default Board ID, when not specified
2
- set(ARDUINO_DEFAULT_PORT /dev/tty.usbmodem411) # Default Port, when not specified
1
+ set(ARDUINO_DEFAULT_BOARD <%= board_type %>) # Default Board ID, when not specified
2
+ set(ARDUINO_DEFAULT_PORT <%= board_port %>) # Default Port, when not specified
3
3
 
4
4
  #====================================================================#
5
5
  # <%= sketch_name %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arduino_sketch_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadatoshi Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-01 00:00:00.000000000 Z
11
+ date: 2013-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -70,6 +70,7 @@ files:
70
70
  - spec/arduino_sketches_fixture/src/BlinkCustomizedForTest/BlinkCustomizedForTest.ino
71
71
  - spec/arduino_sketches_fixture/src/CMakeLists.txt
72
72
  - spec/fixtures/CMakeListsForTestSketch.txt
73
+ - spec/fixtures/CMakeListsForTestSketch2.txt
73
74
  - spec/fixtures/MainCMakeLists.txt
74
75
  - spec/spec_helper.rb
75
76
  - spec/temp/blink_customized_for_test/src/BlinkCustomizedForTest/BlinkCustomizedForTest.ino
@@ -111,6 +112,7 @@ test_files:
111
112
  - spec/arduino_sketches_fixture/src/BlinkCustomizedForTest/BlinkCustomizedForTest.ino
112
113
  - spec/arduino_sketches_fixture/src/CMakeLists.txt
113
114
  - spec/fixtures/CMakeListsForTestSketch.txt
115
+ - spec/fixtures/CMakeListsForTestSketch2.txt
114
116
  - spec/fixtures/MainCMakeLists.txt
115
117
  - spec/spec_helper.rb
116
118
  - spec/temp/blink_customized_for_test/src/BlinkCustomizedForTest/BlinkCustomizedForTest.ino