zeno 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 407fe6d469b4853fb6186c2ac76933f50da238fd
4
- data.tar.gz: da94174e421b64a804a373ff9003b22587008d52
3
+ metadata.gz: baf2090e5f653f8ee3d69f7b223478cda64961db
4
+ data.tar.gz: 4e7dbf27b871829743bfcdf33ca762ee986cb736
5
5
  SHA512:
6
- metadata.gz: 3ed8938ecc1d5fd96e06cebc1f1a265c45a16b7dcd9b5275c3431012d873df7300bebeee227398e2a2928fe3ada290ae6f2c65122228e3e291b42be64f08150b
7
- data.tar.gz: 1594f335c87c41bd7a2bd4d59d767c830800b703c6e59d563114d8eed9a89a73f108371b6a9c03a8d5231b26bf998766520236535a73fd2e446aed12bb3458c1
6
+ metadata.gz: 3aa5224b3afd88c8a0c7f3299f489ceb8bf24005b2c8f16755f7ba384dc666a31dce0c1e01ce81df5dc63a640dae612b2090ae619c36718905f7c7d2f7f30a43
7
+ data.tar.gz: ebe2265c32c5a565bebab406376ec56848b78d4364793ba611fae8c6cbcc24a5a066c4999b0bbaba7fc03f23c69d5ad69ab123f442fdac77bcf983266c7ff4d2
data/lib/zeno.rb CHANGED
@@ -29,6 +29,7 @@ require 'zeno/version'
29
29
  require 'zeno/application'
30
30
  require 'zeno/solution'
31
31
  require 'zeno/applicationalreadyexistserror'
32
+ require 'zeno/missingargumentexception'
32
33
 
33
34
  # Zeno base module
34
35
  module Zeno
@@ -115,8 +116,9 @@ module Zeno
115
116
  options.path = Dir.pwd
116
117
  options.libdir = nil
117
118
  options.target = nil
118
- options.version = nil
119
+ options.version = 'stable'
119
120
  options.apps = nil
121
+ options.uploader = nil
120
122
 
121
123
  parser = OptionParser.new do |opts|
122
124
  opts.banner = "Usage: zeno solution [options]"
@@ -136,14 +138,14 @@ module Zeno
136
138
 
137
139
  # Mandatory
138
140
  opts.on("-l", "--libs PATH",
139
- "Path to the ETA/OS libraries") do |path|
140
- options.libdir = File.expand_path path
141
+ "Relative path to the ETA/OS libraries") do |path|
142
+ options.libdir = path
141
143
  end
142
144
 
143
- opts.on("-a", "--apps APPS",
144
- "List of applications to generate (comma separated") do |apps|
145
- options.apps = apps.split(',')
146
- end
145
+ opts.on("-a", "--apps APP1[,APP2,APPn]",
146
+ "List of applications to generate (comma separated") do |apps|
147
+ options.apps = apps.split(',')
148
+ end
147
149
 
148
150
  # Mandatory
149
151
  opts.on("-t", "--target TARGET",
@@ -156,6 +158,16 @@ module Zeno
156
158
  options.version = ref
157
159
  end
158
160
 
161
+ opts.on("-A", "--avrupload",
162
+ "Configure the application Makefiles to use avrupload") do |u|
163
+ options.uploader = :avrupload
164
+ end
165
+
166
+ opts.on("-d", "--avrdude",
167
+ "Configure the application Makefiles to use avrdude") do |a|
168
+ options.uploader = :avrdude
169
+ end
170
+
159
171
  opts.separator ""
160
172
  opts.separator "Common options:"
161
173
 
@@ -172,16 +184,16 @@ module Zeno
172
184
 
173
185
  parser.parse!
174
186
 
175
- mandatory = [:name, :libdir, :target]
176
- missing = mandatory.select do |param|
177
- if options[param].nil? or options[param] == false
178
- param
179
- end
180
- end
187
+ mandatory = {
188
+ :name => '-n',
189
+ :libdir => '-l',
190
+ :target => '-t'
191
+ }
181
192
 
182
- unless missing.empty?
183
- puts "Missing mandatory options!"
184
- puts ""
193
+ begin
194
+ Zeno.check_missing_args!(options, mandatory)
195
+ rescue MissingArgumentException => e
196
+ puts "#{e.msg}: #{e.missing_arguments.values.join(', ')}"
185
197
  puts parser
186
198
  exit
187
199
  end
@@ -193,6 +205,7 @@ module Zeno
193
205
  opts['libs'] = options.libdir
194
206
  opts['path'] = options.path
195
207
  opts['target'] = options.target
208
+ opts['uploader'] = options.uploader
196
209
 
197
210
  solution = Zeno::Solution.new(opts)
198
211
  solution.create
@@ -207,6 +220,7 @@ module Zeno
207
220
  options.app = false
208
221
  options.libdir = nil
209
222
  options.target = nil
223
+ options.uploader = nil
210
224
 
211
225
  parser = OptionParser.new do |opts|
212
226
  opts.banner = "Usage: zeno app [options]"
@@ -215,7 +229,7 @@ module Zeno
215
229
 
216
230
  # Mandatory
217
231
  opts.on("-r", "--root PATH",
218
- "Absolute path to ETA/OS") do |path|
232
+ "Path to ETA/OS") do |path|
219
233
  options.epath = path
220
234
  end
221
235
 
@@ -227,7 +241,7 @@ module Zeno
227
241
 
228
242
  # Mandatory
229
243
  opts.on("-l", "--libs PATH",
230
- "Path to the ETA/OS libraries") do |path|
244
+ "Relative path to the ETA/OS libraries") do |path|
231
245
  options.libdir = path
232
246
  end
233
247
 
@@ -237,6 +251,16 @@ module Zeno
237
251
  options.target = target
238
252
  end
239
253
 
254
+ opts.on("-A", "--avrupload",
255
+ "Configure the application Makefiles to use avrupload") do |u|
256
+ options.uploader = :avrupload
257
+ end
258
+
259
+ opts.on("-d", "--avrdude",
260
+ "Configure the application Makefiles to use avrdude") do |a|
261
+ options.uploader = :avrdude
262
+ end
263
+
240
264
  opts.separator ""
241
265
  opts.separator "Common options:"
242
266
 
@@ -255,22 +279,26 @@ module Zeno
255
279
  options.app = true
256
280
 
257
281
  mandatory = [:app, :epath, :name, :target, :libdir]
258
- missing = mandatory.select do |param|
259
- if options[param].nil? or options[param] == false
260
- param
261
- end
262
- end
282
+ mandatory = {
283
+ :app => 'Critical failure',
284
+ :epath => '-r',
285
+ :name => '-n',
286
+ :target => '-t',
287
+ :libdir => '-l'
288
+ }
263
289
 
264
- unless missing.empty?
265
- puts "Missing mandatory arguments"
266
- puts ""
290
+ begin
291
+ Zeno.check_missing_args!(options, mandatory)
292
+ rescue MissingArgumentException => e
293
+ puts "#{e.msg}: #{e.missing_arguments.values.join(', ')}"
267
294
  puts parser
268
295
  exit
269
296
  end
270
297
 
271
298
  begin
272
299
  scaffolder = Zeno::Application.new(options.name, options.epath,
273
- options.libdir, options.target)
300
+ options.libdir, options.target,
301
+ options.uploader)
274
302
  scaffolder.create
275
303
  scaffolder.generate
276
304
  rescue ApplicationAlreadyExistsError => e
@@ -315,14 +343,11 @@ module Zeno
315
343
  ref = Zeno.parse_target(target)
316
344
  ref.strip!
317
345
  uri = URI("https://git.bietje.net/etaos/etaos/repository/archive.zip?ref=#{ref}")
318
- http = Net::HTTP.new(uri.host, uri.port)
319
- http.use_ssl = true
320
346
 
321
- request = Net::HTTP::Get.new(uri.request_uri)
322
- response = http.request(request)
347
+ response = Net::HTTP.get(uri)
323
348
  zip = Tempfile.new("etaos-#{ref}.zip", Dir.tmpdir, 'wb+')
324
349
  zip.binmode
325
- zip.write(response.body)
350
+ zip.write(response)
326
351
  path = zip.path
327
352
  zip.close
328
353
 
@@ -344,6 +369,20 @@ module Zeno
344
369
  f_path_new = File.join(out, "etaos-#{ref}")
345
370
  FileUtils.mv f_path, f_path_new
346
371
  end
347
- end
348
- end
349
372
 
373
+ # Check if any arguments are missing.
374
+ # @param options [OpenStruct] Structure of the complete argument set.
375
+ # @param mandatory Hash of mandatory arguments
376
+ # @return nil
377
+ def check_missing_args!(options, mandatory = {})
378
+ return nil if mandatory.empty?
379
+
380
+ missing = mandatory.select do |param, value|
381
+ options[param].nil? or options[param] == false
382
+ end
383
+
384
+ raise Zeno::MissingArgumentException.new(missing) unless missing.empty?
385
+ nil
386
+ end
387
+ end # class
388
+ end # module Zeno
@@ -20,13 +20,14 @@ require 'zeno/makefile'
20
20
 
21
21
  module Zeno
22
22
  class Application
23
- attr_reader :dirname, :etaos_path, :arch, :libdir
23
+ attr_reader :dirname, :etaos_path, :arch, :libdir, :uploader
24
24
 
25
- def initialize(name, path, libdir, arch)
25
+ def initialize(name, path, libdir, arch, upload = nil)
26
26
  @dirname = name
27
27
  @etaos_path = "../#{path}"
28
- @libdir = libdir
28
+ @libdir = "#{libdir}/etaos"
29
29
  @arch = arch
30
+ @uploader = upload
30
31
  end
31
32
 
32
33
  def create
@@ -42,12 +43,37 @@ module Zeno
42
43
  private
43
44
 
44
45
  def generate_mkfile
45
- target_rule = "@$(MAKE) -C $(ETAOS) A=#{Dir.pwd}/#{@dirname} ARCH=#{@arch} CROSS_COMPILE=#{@arch}-"
46
+ target_rule = "@$(MAKE) -C $(ETAOS) A=`pwd` ARCH=#{@arch} CROSS_COMPILE=#{@arch}-"
46
47
  file = "#{@dirname}/Makefile"
47
48
  mkfile = Zeno::Makefile.new file
48
49
  mkfile.add_var('ETAOS', @etaos_path)
50
+ mkfile.add_var('MAKEFLAGS', '-rR --no-print-directory', '+=')
51
+ mkfile.add_var('OBJCOPY', "#{@arch}-objcopy")
52
+ mkfile.add_var('MCU', "# TODO: add MCU")
53
+ mkfile.add_var('BAUD', "115200")
54
+ mkfile.add_var('PROGRAMMER', "# TODO: set programmer")
55
+ mkfile.add_var('PORT', "# TODO: set port")
56
+ mkfile.add_var('AVRDUDE', "avrdude")
57
+ mkfile.add_var('AVRUPLOAD', "avrupload")
49
58
  mkfile.add_target('all', target_rule + " app")
50
59
  mkfile.add_target('clean', target_rule + " clean")
60
+
61
+ hex_rule = "@$(OBJCOPY) -R .eeprom -O ihex #{@dirname}.img #{@dirname}.hex"
62
+ avrdude_rule = "@$(AVRDUDE) -D -q -V -p $(MCU) -c $(PROGRAMMER) -b $(BAUD) -P $(PORT) "
63
+ avrdude_rule << "-C /etc/avrdude.conf -U flash:w:#{@dirname}.hex:i"
64
+
65
+ avrupload_rule = "@$(AVRUPLOAD) -fH test-app.hex -m $(MCU) -p $(PROGRAMMER) -P $(PORT) "
66
+ avrupload_rule << "-b $(BAUD) -c /etc/avrdude.conf"
67
+
68
+ case @uploader
69
+ when :avrdude
70
+ mkfile.add_target('hex', hex_rule)
71
+ mkfile.add_target('upload', avrdude_rule)
72
+ when :avrupload
73
+ mkfile.add_target('hex', hex_rule)
74
+ mkfile.add_target('upload', avrupload_rule)
75
+ end
76
+
51
77
  mkfile.generate
52
78
  end
53
79
 
data/lib/zeno/makefile.rb CHANGED
@@ -58,4 +58,3 @@ module Zeno
58
58
  end
59
59
  end
60
60
  end
61
-
@@ -0,0 +1,35 @@
1
+ #
2
+ # MissingArgumentException class
3
+ # Copyright (C) 2017 Michel Megens <dev@bietje.net>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Zeno
20
+ class MissingArgumentException < StandardError
21
+ attr_reader :msg, :missing_arguments
22
+
23
+ @msg = nil
24
+ @missing_arguments = nil
25
+
26
+ def initialize(missing, msg = nil)
27
+ @msg = msg || "Mandatory arguments are missing!"
28
+ @missing_arguments = missing
29
+ end
30
+
31
+ def message
32
+ @msg
33
+ end
34
+ end # class MissingArgumentException
35
+ end # module Zeno
data/lib/zeno/solution.rb CHANGED
@@ -27,6 +27,7 @@ module Zeno
27
27
  @libs = nil
28
28
  @apps = nil
29
29
  @target = nil
30
+ @uploader = nil
30
31
 
31
32
  def initialize(opts)
32
33
  @name = opts['name']
@@ -36,25 +37,25 @@ module Zeno
36
37
  @path = "#{@basepath}/#{@name}"
37
38
  @apps = opts['apps']
38
39
  @target = opts['target']
40
+ @uploader = opts['uploader']
39
41
 
40
42
  raise Zeno::ApplicationAlreadyExistsError if File.directory? @path
41
43
  end
42
44
 
43
- def create()
45
+ def create
44
46
  FileUtils.mkdir_p @path unless File.directory? @path
45
47
  Dir.chdir @path
46
48
 
47
49
  version = Zeno.parse_target(@ref)
48
50
  etaos_path = "etaos-#{version}"
49
- Zeno.download(@path, @ref)
51
+ Zeno.download(Dir.pwd, @ref)
50
52
 
51
53
  # Create applications
52
54
  @apps.each do |app|
53
- application = Zeno::Application.new(app, etaos_path, @libs, @target)
54
- application.create
55
- application.generate
55
+ application = Zeno::Application.new(app, etaos_path, @libs, @target, @uploader)
56
+ application.create
57
+ application.generate
56
58
  end
57
59
  end
58
60
  end
59
61
  end
60
-
data/lib/zeno/version.rb CHANGED
@@ -17,5 +17,5 @@
17
17
  #
18
18
 
19
19
  module Zeno
20
- VERSION = '0.1.3'
20
+ VERSION = '0.2.0'
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeno
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Megens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-29 00:00:00.000000000 Z
11
+ date: 2017-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,22 +56,22 @@ dependencies:
56
56
  name: rubyzip
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
59
  - - ">="
63
60
  - !ruby/object:Gem::Version
64
61
  version: 1.0.0
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: 1.0.0
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - "~>"
70
- - !ruby/object:Gem::Version
71
- version: '1.0'
72
69
  - - ">="
73
70
  - !ruby/object:Gem::Version
74
71
  version: 1.0.0
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 1.0.0
75
75
  description: Zeno generates ETA/OS applications with a single command.
76
76
  email:
77
77
  - dev@bietje.net
@@ -86,6 +86,7 @@ files:
86
86
  - lib/zeno/applicationalreadyexistserror.rb
87
87
  - lib/zeno/filegenerator.rb
88
88
  - lib/zeno/makefile.rb
89
+ - lib/zeno/missingargumentexception.rb
89
90
  - lib/zeno/solution.rb
90
91
  - lib/zeno/version.rb
91
92
  homepage: http://bietje.net/zeno