class Archlinux::Devtools

Attributes

config[RW]
opts[RW]

Public Class Methods

create(v) click to toggle source
# File lib/aur/devtools.rb, line 95
def self.create(v)
        v.is_a?(self) ? v : self.new(v)
end
new(config: Archlinux.config, **opts) click to toggle source
# File lib/aur/devtools.rb, line 101
def initialize(config: Archlinux.config, **opts)
        @config=config
        @opts=@config.opts.merge(opts)
        # %i(pacman_conf makepkg_conf).each do |key|
        #    @opts[key]=@opts[key].tempfile.file if @opts[key].respond_to?(:tempfile)
        # end
        root=@opts.dig(:chroot, :root) and @opts[:chroot][:root]=Pathname.new(root)
        add_binds
end

Public Instance Methods

add_binds() click to toggle source
# File lib/aur/devtools.rb, line 111
def add_binds
        require 'uri'
        if (conf=@opts[:pacman_conf]).is_a?(PacmanConf)
                conf[:repos].each do |_name, opts|
                        opts[:Server].each do |server|
                                server.match(%r!file://(.*)!) do |m|
                                        @opts[:bind_ro]||=[]
                                        @opts[:bind_ro] << URI.decode_www_form_component(m[1])
                                end
                        end
                end
        end
end
files() { |key, file| ... } click to toggle source
# File lib/aur/devtools.rb, line 125
def files
        %i(pacman_conf makepkg_conf).each do |key|
                if @opts[key]
                        file=@opts[key]
                        file=file.tempfile.file if file.respond_to?(:tempfile)
                        yield key, file
                end
        end
end
makechrootpkg(*args, default_opts: [], **opts, &b) click to toggle source
# File lib/aur/devtools.rb, line 205
def makechrootpkg(*args, default_opts: [], **opts, &b)
        default_opts+=['-r', @opts.dig(:chroot, :root)]
        if (binds_ro=@opts[:bind_ro])
                binds_ro.each do |b|
                        default_opts += ["-D", b]
                end
        end
        if (binds_rw=@opts[:bind_rw])
                binds_rw.each do |b|
                        default_opts += ["-d", b]
                end
        end
        opts[:method]||=:sh

        #makechrootpkg calls itself with sudo --preserve-env=SOURCE_DATE_EPOCH,GNUPGHOME so it does not keep PKGDEST..., work around this by providing our own sudo
        #@config.launch(:makechrootpkg, *args, default_opts: default_opts, sudo: @config.sudo('sudo --preserve-env=GNUPGHOME,PKGDEST,SOURCE_DATE_EPOCH'), **opts, &b)
        ## Update: this has been fixed in devtools-20190329
        @config.launch(:makechrootpkg, *args, default_opts: default_opts, **opts, &b)
end
makepkg(*args, run: :sh, default_opts: [], **opts, &b) click to toggle source
# File lib/aur/devtools.rb, line 147
def makepkg(*args, run: :sh, default_opts: [], **opts, &b)
        files do |key, file|
                # trick to pass options to pacman
                args << "PACMAN_OPTS+=--config=#{file.shellescape}"
                default_opts += ["--config", file] if key==:makepkg_conf
        end
        opts[:method]||=run
        @config.launch(:makepkg, *args, default_opts: default_opts, **opts, &b)
end
mkarchroot(*args, nspawn: @opts.dig(:chroot, :update), default_opts: [], root: @opts.dig(:chroot, :root), **opts, &b) click to toggle source

this takes the same options as nspawn

> this creates or update a chroot

# File lib/aur/devtools.rb, line 181
def mkarchroot(*args, nspawn: @opts.dig(:chroot, :update), default_opts: [], root: @opts.dig(:chroot, :root), **opts, &b)
        files do |key, file|
                default_opts += ["-C", file] if key==:pacman_conf
                default_opts += ["-M", file] if key==:makepkg_conf
        end
        root.sudo_mkpath unless root.directory?
        root=root+'root'
        opts[:method]||=:sh
        if (root+'.arch-chroot').file?
                # Note that if nspawn is not called (and the chroot does not
                # exist), then the passed pacman.conf will not be replace the one
                # in the chroot. And when makechrootpkg calls nspawn, it does not
                # transmit the -C/-M options. So even if we don't want to update,
                # we should call a dummy bin like 'true'
                if nspawn
                        return nspawn.call(root) if nspawn.is_a?(Proc)
                        nspawn=nspawn.shellsplit if nspawn.is_a?(String)
                        self.nspawn(*nspawn, root: root, **opts, &b)
                end
        else
                @config.launch(:mkarchroot, root, *args, default_opts: default_opts, sudo: @config.sudo, **opts,&b)
        end
end
nspawn(*args, root: @opts.dig(:chroot,:root)+'root', default_opts: [], **opts, &b) click to toggle source
# File lib/aur/devtools.rb, line 158
def nspawn(*args, root: @opts.dig(:chroot,:root)+'root', default_opts: [], **opts, &b)
        files do |key, file|
                default_opts += ["-C", file] if key==:pacman_conf
                default_opts += ["-M", file] if key==:makepkg_conf
        end
        if (binds_ro=@opts[:bind_ro])
                binds_ro.each do |b|
                        args.unshift("--bind-ro=#{b}")
                end
        end
        if (binds_rw=@opts[:bind_rw])
                binds_rw.each do |b|
                        args.unshift("--bind=#{b}")
                end
        end
        args.unshift root

        opts[:method]||=:sh
        @config.launch(:'arch-nspawn', *args, default_opts: default_opts, **opts, &b)
end
pacman(*args, default_opts: [], **opts, &b) click to toggle source
# File lib/aur/devtools.rb, line 139
def pacman(*args, default_opts: [], **opts, &b)
        files do |key, file|
                default_opts += ["--config", file] if key==:pacman_conf
        end
        opts[:method]||=:sh
        @config.launch(:pacman, *args, default_opts: default_opts, **opts, &b)
end
pacman_config() click to toggle source
# File lib/aur/devtools.rb, line 135
def pacman_config
        Pacman.create(@opts[:pacman_conf])
end
sync_db(*names, install: [], **pacman_opts) { |pacman, file| ... } click to toggle source
# File lib/aur/devtools.rb, line 235
def sync_db(*names, install: [], **pacman_opts)
        conf=PacmanConf.create(@opts[:pacman_conf])
        new_conf={options: conf[:options], repos: {}}
        repos=conf[:repos]
        names.each do |name|
                if repos[name]
                        new_conf[:repos][name]=repos[name]
                else
                        SH.logger.warn "sync_db: unknown repo #{name}"
                end
        end
        tmp_pacman(new_conf) do |pacman, file|
                if block_given?
                        return yield(pacman, file)
                else
                        args=['-Syu']
                        args+=install
                        return pacman[*args, sudo: @config.sudo, **pacman_opts]
                end
        end
end
tmp_pacman(conf, **opts) { |pacman, file| ... } click to toggle source
# File lib/aur/devtools.rb, line 225
def tmp_pacman(conf, **opts)
        PacmanConf.create(conf).tempfile.create(true) do |file|
                pacman=lambda do |*args, **pac_opts, &b|
                        pac_opts[:method]||=:sh
                        @config.launch(:pacman, *args, default_opts: ["--config", file], **opts.merge(pac_opts), &b)
                end
                yield pacman, file
        end
end