Class: Rubycc::Doctor::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycc/doctor/cli.rb

Overview

rubycc doctor — tells a Ruby application developer whether rubycc can build the C extensions their app depends on.

It reads the app's Gemfile.lock (or Gemfile), and for each gem: reports it verified when the shipped build-verified database (data/verified_gems.json) already covers that name+version; otherwise fetches and builds it on the spot through the same extconf -> rmake -> rubycc path a real install takes, reporting exactly where any failure occurred. Gems with no C extension need rubycc at all and are marked as such.

The verified check is offline and instant; only unverified gems reach the network. The bottom line is an adoption verdict and an exit code (0 when every C-extension gem is verified or built, 1 otherwise).

Defined Under Namespace

Classes: Row

Constant Summary collapse

STATUS =

Per-status display: symbol + label. Ordering of keys is the report legend.

{
  verified:       ["", "verified"],
  built:          ["", "built on the spot"],
  no_ext:         ["-", "no C extension"],
  failed:         ["", "FAILED"],
  unknown:        ["?", "unknown"],
  local:          ["-", "local/vcs source (skipped)"],
  skipped_budget: ["?", "skipped (build budget reached)"]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out:, err:, verified: nil, builder: nil) ⇒ CLI

Returns a new instance of CLI.



42
43
44
45
46
47
# File 'lib/rubycc/doctor/cli.rb', line 42

def initialize(out:, err:, verified: nil, builder: nil)
  @out = out
  @err = err
  @verified = verified
  @builder = builder
end

Class Method Details

.run(argv, out: $stdout, err: $stderr, verified: nil, builder: nil) ⇒ Object



38
39
40
# File 'lib/rubycc/doctor/cli.rb', line 38

def self.run(argv, out: $stdout, err: $stderr, verified: nil, builder: nil)
  new(out: out, err: err, verified: verified, builder: builder).run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubycc/doctor/cli.rb', line 49

def run(argv)
  options = parse(argv)
  return 0 if options[:help]

  result = Gemfile.load(options[:gemfile])
  unless result
    @err.puts("rubycc doctor: no Gemfile.lock or Gemfile found at #{options[:gemfile]}")
    return 2
  end

  verified = @verified || VerifiedGems.load
  rows = evaluate(result, verified, options)
  report(result, rows)
  exit_code(rows)
rescue OptionParser::ParseError => e
  @err.puts("rubycc doctor: #{e.message}")
  2
end