arduino_sketch_builder 0.0.7 → 0.1.0

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: a1be6df6bc58e73cc36b048ab1e084d9d357d72e
4
- data.tar.gz: 0e977b8e24e0c2036b362704299bfeb7b9e03262
3
+ metadata.gz: f82dae0085b54f68c8289afb826a1ecf04358f17
4
+ data.tar.gz: 9cbfff32a488a0ed397f049b5b384eb7f5136477
5
5
  SHA512:
6
- metadata.gz: d3f0f52a4c5d167183e770dcec3dd8a92db989fd099b0b8a74c16ad538bd25764cfbc1fd4eb27910c05f99d399cd5ae958e91f63c3f5c664939e855be79bfade
7
- data.tar.gz: 70133a5475284e60f81737ef32f1a9ccb1de3262f996e16b47e020177347d2ffd7f72454dadc279f5847bef49dcbcba3d0df38d08791d460e2b0b27dbe8f6338
6
+ metadata.gz: 1f3efede1b98b9a2ec323f85366ce9fc25bc2550851f6601126c7f7267c0c1d9345193df1572852e9af724dfa2e57ae5f80e46ad899f1b3659d6166683574f3f
7
+ data.tar.gz: 4d160df5b0a6cb8a1b045d1865452a43d8010a879d82a179dbf73431d8d602613396b42ca14bddacdd5860eacec2b12cbd325afa99b8fa258b921a020996e8e6
data/README.md CHANGED
@@ -82,21 +82,44 @@ The default board ID: uno
82
82
 
83
83
  The default port: /dev/tty.usbmodem411
84
84
 
85
- You can specify them through ArduinoSketchBuilder::Setup.new.setup method (See "Code example" section below).
85
+ You can specify them through ArduinoSketchBuilder::Base.new (See "Simple code example" section below).
86
86
 
87
87
  You can also change them by setting ARDUINO_DEFAULT_BOARD and ARDUINO_DEFAULT_PORT environment variables at runtime.
88
88
 
89
- ### Code example
89
+ ### Simple code example (following the default directory structure above)
90
+
91
+ require "arduino_sketch_builder"
92
+
93
+ # Configuring ArduinoSketchBuilder (copies cmake directory under the specified root_directory):
94
+ root_directory = File.expand_path('~/.arduino_sketches')
95
+
96
+ # Setting up the directory structure - like the one above under cmake directory
97
+ ArduinoSketchBuilder::Setup.configure(root_directory)
98
+
99
+ # Path to the sketch to be put under the directory structure:
100
+ arduino_sketch_file_path = File.expand_path('~/temp/BlinkCustomized.ino')
101
+
102
+ arduino_sketch_builder = ArduinoSketchBuilder::Base.new(root_directory, arduino_sketch_file_path, board_type: "diecimila", board_port: "/dev/cu.usbmodem411")
103
+
104
+ # Setting up the sketch specific directory structure and files - like the one above under (name of Arduino sketch underlined) directory
105
+ arduino_sketch_builder.setup_sketch
106
+
107
+ # Build and upload
108
+ # raises error if state at the point of execution is not :initial (i.e. precondition: state == :initial)
109
+ # Success: state == :complete
110
+ # Failure: state == :cmake_incomplete, :make_incomplete, or :make_upload_incomplete depending on the step at the time of the failure
111
+ # arduino_sketch_builder.message gives message such as error message in case of failure.
112
+ state = arduino_sketch_builder.build_and_upload
113
+
114
+ ### Example of code with more control
90
115
 
91
116
  #### Setting up the directory structure - like the one above under cmake directory
92
117
 
93
118
  require "arduino_sketch_builder"
94
119
 
95
- setup = ArduinoSketchBuilder::Setup.new
96
-
97
120
  # Configuring ArduinoSketchBuilder (copies cmake directory under the specified root_directory):
98
121
  root_directory = File.expand_path('~/.arduino_sketches')
99
- setup.configure(root_directory)
122
+ ArduinoSketchBuilder::Setup.configure(root_directory)
100
123
 
101
124
  #### Setting up the sketch specific directory structure and files - like the one above under (name of Arduino sketch underlined) directory
102
125
 
@@ -122,24 +145,7 @@ If Arduino board type and port are different from the default,
122
145
  arduino_sketch_file_path = File.expand_path('~/temp/BlinkCustomized.ino')
123
146
  setup.setup(root_directory, arduino_sketch_file_path, board_type: "diecimila", board_port: "/dev/cu.usbmodem411")
124
147
 
125
- #### Building and uploading the sketch
126
-
127
- require "arduino_sketch_builder"
128
-
129
- main_directory = File.expand_path('~/.arduino_sketches/blink_customized')
130
- build_directory = File.join(main_directory, "build")
131
-
132
- # Instantiate ArduinoCmakeBuild with state == :initial (It's a state machine):
133
- arduino_cmake_build = ArduinoSketchBuilder::ArduinoCmakeBuild.new(main_directory, build_directory)
134
-
135
- # Build and upload
136
- # raises error if state at the point of execution is not :initial (i.e. precondition: state == :initial)
137
- # Success: state == :make_upload_complete
138
- # Failure: state == :cmake_incomplete, :make_incomplete, or :make_upload_incomplete depending on the step at the time of the failure
139
- # arduino_cmake_build.message gives message such as error message in case of failure.
140
- state = arduino_cmake_build.build_and_upload
141
-
142
- #### (Optional: individual steps for "Building and uploading the sketch" above): Executing cmake commands - compile, make, and make upload
148
+ #### Executing cmake commands - compile, make, and make upload
143
149
 
144
150
  require "arduino_sketch_builder"
145
151
 
@@ -1,4 +1,5 @@
1
1
  require "open3"
2
+ require "fileutils"
2
3
 
3
4
  class ArduinoSketchBuilder::ArduinoCmakeBuild
4
5
 
@@ -8,12 +9,13 @@ class ArduinoSketchBuilder::ArduinoCmakeBuild
8
9
  CMAKE_COMPLETE = State.new(:cmake_complete, "success")
9
10
  MAKE_COMPLETE = State.new(:make_complete, "success")
10
11
  MAKE_UPLOAD_COMPLETE = State.new(:make_upload_complete, "success")
12
+ COMPLETE = State.new(:complete, "success")
11
13
 
12
- STATE_SEQUENCE = [INITIAL, CMAKE_COMPLETE, MAKE_COMPLETE, MAKE_UPLOAD_COMPLETE]
14
+ STATE_SEQUENCE = [INITIAL, CMAKE_COMPLETE, MAKE_COMPLETE, MAKE_UPLOAD_COMPLETE, COMPLETE]
13
15
 
14
16
  def initialize(main_directory, build_directory)
15
- @main_directory = main_directory
16
- @build_directory = build_directory
17
+ @main_directory = File.expand_path(main_directory)
18
+ @build_directory = File.expand_path(build_directory)
17
19
  @state = INITIAL
18
20
  end
19
21
 
@@ -27,10 +29,13 @@ class ArduinoSketchBuilder::ArduinoCmakeBuild
27
29
 
28
30
  def build_and_upload
29
31
  self.cmake
30
- return self.state unless self.state == :cmake_complete
32
+ return self.state unless @state == CMAKE_COMPLETE
31
33
  self.make
32
- return self.state unless self.state == :make_complete
34
+ return self.state unless @state == MAKE_COMPLETE
33
35
  self.make_upload
36
+ @state = COMPLETE if @state == MAKE_UPLOAD_COMPLETE
37
+
38
+ self.state
34
39
  end
35
40
 
36
41
  [:cmake, :make, :make_upload].each_with_index do |method_name, index|
@@ -59,4 +64,13 @@ class ArduinoSketchBuilder::ArduinoCmakeBuild
59
64
 
60
65
  end
61
66
 
67
+ def reset
68
+
69
+ FileUtils.rm_rf(Dir.glob("#{BUILD_DIRECTORY}/*"))
70
+ @state = INITIAL
71
+
72
+ self.state
73
+
74
+ end
75
+
62
76
  end
@@ -0,0 +1,37 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+
3
+ class ArduinoSketchBuilder::Base
4
+
5
+ def initialize(root_directory, sketch_file_path, board_type: "uno", board_port: "/dev/tty.usbmodem411")
6
+ @root_directory = File.expand_path(root_directory)
7
+ @sketch_file_path = File.expand_path(sketch_file_path)
8
+ @board_type = board_type
9
+ @board_port = board_port
10
+
11
+ main_directory_name = File.basename(@sketch_file_path).split('.').first.underscore
12
+ main_directory = File.join(@root_directory, main_directory_name)
13
+ build_directory = File.join(main_directory, "build")
14
+ @arduino_cmake_build = ArduinoSketchBuilder::ArduinoCmakeBuild.new(main_directory, build_directory)
15
+ end
16
+
17
+ def state
18
+ @arduino_cmake_build.state
19
+ end
20
+
21
+ def message
22
+ @arduino_cmake_build.message
23
+ end
24
+
25
+ def setup_sketch
26
+ ArduinoSketchBuilder::Setup.new.setup(@root_directory, @sketch_file_path, board_type: @board_type, board_port: @board_port)
27
+ end
28
+
29
+ def build_and_upload
30
+ @arduino_cmake_build.build_and_upload
31
+ end
32
+
33
+ def reset
34
+ @arduino_cmake_build.reset
35
+ end
36
+
37
+ end
@@ -6,7 +6,7 @@ class ArduinoSketchBuilder::Setup
6
6
  ARDUINO_CMAKE_DIRECTORY = File.expand_path('../../../arduino-cmake', __FILE__)
7
7
  TEMPLATES_DIRECTORY = File.expand_path('../../../templates', __FILE__)
8
8
 
9
- def configure(root_directory)
9
+ def self.configure(root_directory)
10
10
 
11
11
  FileUtils.cp_r(File.join(ARDUINO_CMAKE_DIRECTORY, 'cmake'), root_directory)
12
12
 
@@ -1,3 +1,3 @@
1
1
  module ArduinoSketchBuilder
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,6 +2,7 @@ require "arduino_sketch_builder/version"
2
2
  require "arduino_sketch_builder/arduino_cmake_build"
3
3
  require "arduino_sketch_builder/c_make_lists_file_generator"
4
4
  require "arduino_sketch_builder/setup"
5
+ require "arduino_sketch_builder/base"
5
6
 
6
7
  module ArduinoSketchBuilder
7
8
  # Your code goes here...
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe ArduinoSketchBuilder::ArduinoCmakeBuild do
4
4
 
5
- MAIN_DIRECTORY = File.expand_path('../../arduino_sketches_fixture', __FILE__)
6
- BUILD_DIRECTORY = "#{MAIN_DIRECTORY}/build"
5
+ MAIN_DIRECTORY = ARDUINO_SKETCHES_FIXTURE_DIRECTORY
6
+ BUILD_DIRECTORY = File.join(MAIN_DIRECTORY, "build")
7
7
 
8
8
  before(:each) do
9
9
  FileUtils.rm_rf(Dir.glob("#{BUILD_DIRECTORY}/*"))
@@ -110,9 +110,9 @@ describe ArduinoSketchBuilder::ArduinoCmakeBuild do
110
110
  File.exists?(File.join(BUILD_DIRECTORY, "Makefile")).should be_false
111
111
  File.exists?(File.join(BUILD_DIRECTORY, "src", "blink_customized_for_test.hex")).should be_false
112
112
 
113
- @arduino_cmake_build.build_and_upload.should == :make_upload_complete
113
+ @arduino_cmake_build.build_and_upload.should == :complete
114
114
 
115
- @arduino_cmake_build.state.should == :make_upload_complete
115
+ @arduino_cmake_build.state.should == :complete
116
116
 
117
117
  File.exists?(File.join(BUILD_DIRECTORY, "Makefile")).should be_true
118
118
  File.exists?(File.join(BUILD_DIRECTORY, "src", "blink_customized_for_test.hex")).should be_true
@@ -121,4 +121,21 @@ describe ArduinoSketchBuilder::ArduinoCmakeBuild do
121
121
 
122
122
  end
123
123
 
124
+ context "reset" do
125
+
126
+ it "should clean up build directory and reset the state to :initial" do
127
+
128
+ @arduino_cmake_build.state.should == :initial
129
+ @arduino_cmake_build.cmake.should == :cmake_complete
130
+
131
+ File.exists?(File.join(BUILD_DIRECTORY, "Makefile")).should be_true
132
+
133
+ @arduino_cmake_build.reset.should == :initial
134
+
135
+ Dir.entries(BUILD_DIRECTORY).should == [".", "..", ".gitkeep"]
136
+
137
+ end
138
+
139
+ end
140
+
124
141
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe ArduinoSketchBuilder::Base do
4
+
5
+ before(:each) do
6
+ FileUtils.rm_rf(Dir.glob("#{TEMP_DIRECTORY}/*"))
7
+
8
+ @root_directory = TEMP_DIRECTORY
9
+ ArduinoSketchBuilder::Setup.configure(@root_directory)
10
+
11
+ arduino_sketch_file_path = File.join(ARDUINO_SKETCHES_FIXTURE_DIRECTORY, 'src/BlinkCustomizedForTest/BlinkCustomizedForTest.ino')
12
+ @build_directory = File.join(TEMP_DIRECTORY, "blink_customized_for_test", "build")
13
+ @arduino_sketch_builder = ArduinoSketchBuilder::Base.new(@root_directory, arduino_sketch_file_path)
14
+ end
15
+
16
+ it "should set up, build and upload Arduino sketch" do
17
+
18
+ @arduino_sketch_builder.setup_sketch
19
+ Dir.exists?(File.join(@root_directory, "blink_customized_for_test")).should be_true
20
+
21
+ @arduino_sketch_builder.state.should == :initial
22
+ File.exists?(File.join(@build_directory, "Makefile")).should be_false
23
+ File.exists?(File.join(@build_directory, "src", "blink_customized_for_test.hex")).should be_false
24
+
25
+ @arduino_sketch_builder.build_and_upload.should == :complete
26
+
27
+ @arduino_sketch_builder.state.should == :complete
28
+
29
+ File.exists?(File.join(@build_directory, "Makefile")).should be_true
30
+ File.exists?(File.join(@build_directory, "src", "blink_customized_for_test.hex")).should be_true
31
+
32
+ end
33
+
34
+ end
@@ -3,13 +3,11 @@ require 'spec_helper'
3
3
  describe ArduinoSketchBuilder::Setup do
4
4
 
5
5
  ARDUINO_CMAKE_DIRECTORY = File.expand_path('../../../arduino-cmake', __FILE__)
6
- ARDUINO_SKETCHES_FIXTURE_DIRECTORY = File.expand_path('../../arduino_sketches_fixture', __FILE__)
7
- ARDUINO_SKETCH_FILE_PATH = File.expand_path(File.join(ARDUINO_SKETCHES_FIXTURE_DIRECTORY, 'src/BlinkCustomizedForTest/BlinkCustomizedForTest.ino'), __FILE__)
6
+ ARDUINO_SKETCH_FILE_PATH = File.join(ARDUINO_SKETCHES_FIXTURE_DIRECTORY, 'src/BlinkCustomizedForTest/BlinkCustomizedForTest.ino')
8
7
  TEMPLATES_DIRECTORY = File.expand_path('../../../templates', __FILE__)
9
8
 
10
9
  before(:each) do
11
10
  FileUtils.rm_rf(Dir.glob("#{TEMP_DIRECTORY}/*"))
12
- @setup = ArduinoSketchBuilder::Setup.new
13
11
  end
14
12
 
15
13
  context "configure" do
@@ -18,7 +16,7 @@ describe ArduinoSketchBuilder::Setup do
18
16
 
19
17
  root_directory = TEMP_DIRECTORY
20
18
 
21
- @setup.configure(root_directory)
19
+ ArduinoSketchBuilder::Setup.configure(root_directory)
22
20
 
23
21
  Dir.exists?(File.join(root_directory, "cmake")).should be_true
24
22
  File.exists?(File.join(root_directory, "cmake", "ArduinoToolchain.cmake")).should be_true
@@ -34,7 +32,7 @@ describe ArduinoSketchBuilder::Setup do
34
32
 
35
33
  root_directory = TEMP_DIRECTORY
36
34
 
37
- @setup.configure(root_directory)
35
+ ArduinoSketchBuilder::Setup.configure(root_directory)
38
36
 
39
37
  Dir.exists?(File.join(root_directory, "libraries")).should be_true
40
38
  File.exists?(File.join(root_directory, "libraries", ".gitkeep")).should be_true
@@ -45,7 +43,7 @@ describe ArduinoSketchBuilder::Setup do
45
43
 
46
44
  root_directory = TEMP_DIRECTORY
47
45
 
48
- @setup.configure(root_directory)
46
+ ArduinoSketchBuilder::Setup.configure(root_directory)
49
47
 
50
48
  File.exists?(File.join(root_directory, ".gitignore")).should be_true
51
49
  File.read(File.join(root_directory, ".gitignore")).should == File.read(File.join(TEMPLATES_DIRECTORY, "root_gitignore_template"))
@@ -56,6 +54,10 @@ describe ArduinoSketchBuilder::Setup do
56
54
 
57
55
  context "setup" do
58
56
 
57
+ before(:each) do
58
+ @setup = ArduinoSketchBuilder::Setup.new
59
+ end
60
+
59
61
  it "should create a directory structure for an Arduino sketch" do
60
62
 
61
63
  root_directory = TEMP_DIRECTORY
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'arduino_sketch_builder'
2
2
 
3
3
  FIXTURES_DIRECTORY = File.expand_path('../fixtures', __FILE__)
4
4
  TEMP_DIRECTORY = File.expand_path('../temp', __FILE__)
5
+ ARDUINO_SKETCHES_FIXTURE_DIRECTORY = File.expand_path('../arduino_sketches_fixture', __FILE__)
5
6
 
6
7
  RSpec.configure do |config|
7
8
 
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.7
4
+ version: 0.1.0
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-05 00:00:00.000000000 Z
11
+ date: 2013-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -56,6 +56,7 @@ files:
56
56
  - arduino_sketch_builder.gemspec
57
57
  - lib/arduino_sketch_builder.rb
58
58
  - lib/arduino_sketch_builder/arduino_cmake_build.rb
59
+ - lib/arduino_sketch_builder/base.rb
59
60
  - lib/arduino_sketch_builder/c_make_lists_file_generator.rb
60
61
  - lib/arduino_sketch_builder/setup.rb
61
62
  - lib/arduino_sketch_builder/version.rb
@@ -63,6 +64,7 @@ files:
63
64
  - lib/arduino_sketches/src/BlinkCustomized/BlinkCustomized.ino
64
65
  - lib/arduino_sketches/src/CMakeLists.txt
65
66
  - spec/arduino_sketch_builder/arduino_cmake_build_spec.rb
67
+ - spec/arduino_sketch_builder/base_spec.rb
66
68
  - spec/arduino_sketch_builder/c_make_lists_file_generator_spec.rb
67
69
  - spec/arduino_sketch_builder/setup_spec.rb
68
70
  - spec/arduino_sketches_fixture/CMakeLists.txt
@@ -105,6 +107,7 @@ summary: Performs calling the code to compile Arduino sketch and upload it to Ar
105
107
  by Ruby, instead of using Arduino IDE.
106
108
  test_files:
107
109
  - spec/arduino_sketch_builder/arduino_cmake_build_spec.rb
110
+ - spec/arduino_sketch_builder/base_spec.rb
108
111
  - spec/arduino_sketch_builder/c_make_lists_file_generator_spec.rb
109
112
  - spec/arduino_sketch_builder/setup_spec.rb
110
113
  - spec/arduino_sketches_fixture/CMakeLists.txt