Class: MRuby::Gem::List
Overview
Constant Summary
Constants included
from Enumerable
Enumerable::NONE
Instance Method Summary
collapse
Methods included from Enumerable
#+, #all?, #any?, #chain, #collect, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_slice, #each_with_index, #each_with_object, #entries, #find_all, #find_index, #first, #flat_map, #grep, #group_by, #hash, #include?, #inject, #lazy, #max, #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reject, #reverse_each, #sort, #sort_by, #take, #take_while, #to_h, to_h, #uniq, #zip
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
305
306
307
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 305
def initialize
@ary = []
end
|
Instance Method Details
313
314
315
316
317
318
319
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 313
def <<(gem)
unless @ary.detect {|g| g.dir == gem.dir }
@ary << gem
else
end
end
|
#check(build) ⇒ Object
416
417
418
419
420
421
422
423
424
425
426
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 416
def check(build)
gem_table = generate_gem_table build
@ary = tsort_dependencies gem_table.keys, gem_table, true
each(&:setup_compilers)
each do |g|
import_include_paths(g)
end
end
|
#default_gem_params(dep) ⇒ Object
325
326
327
328
329
330
331
332
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 325
def default_gem_params dep
if dep[:default]; dep
elsif File.exist? "#{MRUBY_ROOT}/mrbgems/#{dep[:gem]}"
{ :gem => dep[:gem], :default => { :core => dep[:gem] } }
else
{ :gem => dep[:gem], :default => { :mgem => dep[:gem] } }
end
end
|
309
310
311
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 309
def each(&b)
@ary.each(&b)
end
|
#empty? ⇒ Boolean
321
322
323
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 321
def empty?
@ary.empty?
end
|
#generate_gem_table(build) ⇒ Object
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 334
def generate_gem_table build
gem_table = each_with_object({}) { |spec, h| h[spec.name] = spec }
default_gems = {}
each do |g|
g.dependencies.each do |dep|
default_gems[dep[:gem]] ||= default_gem_params(dep)
end
end
until default_gems.empty?
def_name, def_gem = default_gems.shift
next if gem_table[def_name]
spec = gem_table[def_name] = build.gem(def_gem[:default])
fail "Invalid gem name: #{spec.name} (Expected: #{def_name})" if spec.name != def_name
spec.setup
spec.dependencies.each do |dep|
default_gems[dep[:gem]] ||= default_gem_params(dep)
end
end
each do |g|
g.dependencies.each do |dep|
name = dep[:gem]
req_versions = dep[:requirements]
dep_g = gem_table[name]
if dep_g.nil?
fail "The GEM '#{g.name}' depends on the GEM '#{name}' but it could not be found"
end
unless dep_g.version_ok? req_versions
fail "#{name} version should be #{req_versions.join(' and ')} but was '#{dep_g.version}'"
end
end
cfls = g.conflicts.select { |c|
cfl_g = gem_table[c[:gem]]
cfl_g and cfl_g.version_ok?(c[:requirements] || ['>= 0.0.0'])
}.map { |c| "#{c[:gem]}(#{gem_table[c[:gem]].version})" }
fail "Conflicts of gem `#{g.name}` found: #{cfls.join ', '}" unless cfls.empty?
end
gem_table
end
|
#import_include_paths(g) ⇒ Object
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 428
def import_include_paths(g)
gem_table = each_with_object({}) { |spec, h| h[spec.name] = spec }
g.dependencies.each do |dep|
dep_g = gem_table[dep[:gem]]
import_include_paths(dep_g)
dep_g.export_include_paths.uniq!
g.compilers.each do |compiler|
compiler.include_paths += dep_g.export_include_paths
g.export_include_paths += dep_g.export_include_paths
compiler.include_paths.uniq!
g.export_include_paths.uniq!
end
end
end
|
#tsort_dependencies(ary, table, all_dependency_listed = false) ⇒ Object
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 382
def tsort_dependencies ary, table, all_dependency_listed = false
unless all_dependency_listed
left = ary.dup
until left.empty?
v = left.pop
table[v].dependencies.each do |dep|
left.push dep[:gem]
ary.push dep[:gem]
end
end
end
ary.uniq!
table.instance_variable_set :@root_gems, ary
class << table
include TSort
def tsort_each_node &b
@root_gems.each &b
end
def tsort_each_child(n, &b)
fetch(n).dependencies.each do |v|
b.call v[:gem]
end
end
end
begin
table.tsort.map { |v| table[v] }
rescue TSort::Cyclic => e
fail "Circular mrbgem dependency found: #{e.message}"
end
end
|