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, #filter_map, #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, #tally, #to_h, #uniq, #zip
Constructor Details
#initialize ⇒ List
Returns a new instance of List.
318
319
320
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 318
def initialize
@ary = []
end
|
Instance Method Details
326
327
328
329
330
331
332
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 326
def <<(gem)
unless @ary.detect {|g| g.dir == gem.dir }
@ary << gem
else
end
end
|
#check(build) ⇒ Object
429
430
431
432
433
434
435
436
437
438
439
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 429
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
338
339
340
341
342
343
344
345
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 338
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
|
322
323
324
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 322
def each(&b)
@ary.each(&b)
end
|
#empty? ⇒ Boolean
334
335
336
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 334
def empty?
@ary.empty?
end
|
#generate_gem_table(build) ⇒ Object
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
381
382
383
384
385
386
387
388
389
390
391
392
393
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 347
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 441
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
# File 'ext/enterprise_script_service/mruby/lib/mruby/gem.rb', line 395
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
|