Class: Binpkgbot::EmergeRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/binpkgbot/emerge_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(atom, *args, config:, ephemeral: true, use: [], accept_keywords: [], unmasks: [], masks: [], script: nil) ⇒ EmergeRunner

Returns a new instance of EmergeRunner.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/binpkgbot/emerge_runner.rb', line 6

def initialize(atom, *args, config:, ephemeral: true, use: [], accept_keywords: [], unmasks: [], masks: [], script: nil)
  @atom = atom
  @args = args
  @config = config
  @ephemeral = ephemeral
  @use = use
  @accept_keywords = accept_keywords
  @unmasks = unmasks
  @masks = masks
  @script = script
end

Instance Method Details

#bindsObject



18
19
20
21
22
23
# File 'lib/binpkgbot/emerge_runner.rb', line 18

def binds
  [
    {from: @config.portage_repo, to: '/usr/portage', writable: true},
    *@config.binds
  ]
end

#containerObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/binpkgbot/emerge_runner.rb', line 51

def container
  @container ||= Container.new(
    @config.stage,
    ephemeral: @ephemeral,
    binds: binds,
    copies: copies,
    env: env,
    script: script,
    config: @config,
  )
end

#copiesObject



25
26
27
28
29
# File 'lib/binpkgbot/emerge_runner.rb', line 25

def copies
  [
    {from: @config.etc_portage, to: '/etc/portage'},
  ]
end

#envObject



31
32
33
34
35
36
37
38
# File 'lib/binpkgbot/emerge_runner.rb', line 31

def env
  {
    FEATURES: "buildpkg",
    PORTAGE_ELOG_CLASSES: 'log warn error qa',
    PORTAGE_ELOG_SYSTEM: 'save save_summary',
    CONFIG_PROTECT_MASK: @config.config_protect_mask? ? @config.config_protect_mask : '/etc',
  }
end

#prepare_etc_portage_overridesObject



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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/binpkgbot/emerge_runner.rb', line 63

def prepare_etc_portage_overrides
  {masks: @masks, unmasks: @unmasks}.each do |k,v|
    file = container.workdir.join("package.#{k}")
    content = []
    [v].flatten.each do |x|
      case x
      when true
        content << @atom
      when false
        # do nothing
      when String
        content << x
      when nil
      else
        raise TypeError, "Invalid type for #{k.inspect} specification on #{@atom}, it should be true or false or string: #{x.inspect}"
      end
    end
    File.write file, "#{content.join(?\n)}\n"
  end

  begin
    file = container.workdir.join("package.accept_keywords")
    content = []
    [@accept_keywords].flatten.each do |x|
      case x
      when true
        content << "#{@atom} ~*"
      when false
        # do nothing
      when String
        if x.split(/\s+/, 2).size > 1
          content << x
        else
          content << "#{x} ~*"
        end
      when nil
      else
        raise TypeError, "Invalid type for accept_keywords specification on #{@atom}, it should be true or false or string: #{x.inspect}"
      end
    end
    File.write file, "#{content.join(?\n)}\n"
  end

  begin
    file = container.workdir.join("package.use")
    content = []
    [@use].flatten.each do |x|
      case x
      when true
        content << "#{@atom} ~*"
      when false
        # do nothing
      when String
        if x.split(/\s+/, 2).size > 1
          content << x
        else
          content << "#{@atom} #{x}"
        end
      when nil
      else
        raise TypeError, "Invalid type for :use specification on #{@atom}, it should be true or false or string: #{x.inspect}"
      end
    end
    File.write file, "#{content.join(?\n)}\n"
  end
end

#runObject



130
131
132
133
# File 'lib/binpkgbot/emerge_runner.rb', line 130

def run
  prepare_etc_portage_overrides
  container.run
end

#scriptObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/binpkgbot/emerge_runner.rb', line 40

def script
  @script || <<-EOF
set -x
/.binpkgbot.share/libexec/modify-etc-portage /.binpkgbot.work/package.use /etc/portage/package.use
/.binpkgbot.share/libexec/modify-etc-portage /.binpkgbot.work/package.accept_keywords /etc/portage/package.accept_keywords
/.binpkgbot.share/libexec/modify-etc-portage /.binpkgbot.work/package.unmasks /etc/portage/package.unmasks
/.binpkgbot.share/libexec/modify-etc-portage /.binpkgbot.work/package.masks /etc/portage/package.masks
emerge #{@config.emerge_options.shelljoin} #{@args.shelljoin} #{@atom.shellescape}
  EOF
end