Class: Gel::GemspecParser

Inherits:
Object
  • Object
show all
Defined in:
lib/gel/gemspec_parser.rb

Defined Under Namespace

Modules: Context Classes: Result

Class Method Summary collapse

Class Method Details

.parse(content, filename, lineno = 1, root: File.dirname(filename), isolate: true) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/gel/gemspec_parser.rb', line 55

def self.parse(content, filename, lineno = 1, root: File.dirname(filename), isolate: true)
  filename = File.expand_path(filename)
  root = File.expand_path(root)

  if isolate
    in_read, in_write = IO.pipe
    out_read, out_write = IO.pipe

    pid = spawn({ "RUBYLIB" => Gel::Environment.modified_rubylib, "GEL_GEMFILE" => "", "GEL_LOCKFILE" => "" },
                RbConfig.ruby,
                "-r", File.expand_path("compatibility", __dir__),
                "-r", File.expand_path("gemspec_parser", __dir__),
                "-e", "puts Marshal.dump(Gel::GemspecParser.parse($stdin.read, ARGV.shift, ARGV.shift.to_i, root: ARGV.shift, isolate: false))",
                filename, lineno.to_s, root,
                in: in_read, out: out_write)

    in_read.close
    out_write.close

    write_thread = Thread.new do
      in_write.write content
      in_write.close
    end

    read_thread = Thread.new do
      out_read.read
    end

    _, status = Process.waitpid2(pid)
    raise Gel::Error::ParsedGemspecError unless status.success?

    write_thread.join
    Marshal.load read_thread.value

  else
    Dir.chdir(root) do
      Context.context.eval(content, filename, lineno)
    end
  end
end