class Archlinux::Makepkg

Attributes

asdeps[RW]
base[RW]
config[RW]
dir[RW]
env[RW]
get_pkg[W]

Public Class Methods

new(dir, config: Archlinux.config, env: {}, asdeps: false) click to toggle source
# File lib/aur/makepkg.rb, line 106
def initialize(dir, config: Archlinux.config, env: {}, asdeps: false)
        @dir=Pathname.new(dir)
        @base=@dir.basename #the corresponding pkgbase
        @config=config
        @env=env
        @asdeps=asdeps
        db=@config.db
        @env['PKGDEST']=db.dir.to_s if db
end

Public Instance Methods

build(*makepkg_args, mkarchroot: false, chroot: @config.dig(:chroot, :active), **opts) click to toggle source
# File lib/aur/makepkg.rb, line 284
def build(*makepkg_args, mkarchroot: false, chroot: @config.dig(:chroot, :active), **opts)
        force_sign = opts.delete(:rebuild) #when rebuilding we need to regenerate the signature
        SH.logger.important "=> Building #{@dir}"
        if chroot
                self.mkarchroot if mkarchroot
                success, _r=makechroot(*makepkg_args, **opts)
        else
                success, _r=make(*makepkg_args, **opts)
        end
        if success and (db=@config.db)
                success=add_to_db(db, force_sign: force_sign)
                if !chroot #sync db so that the new versions are available
                        tools=@config.local_devtools
                        tools.sync_db(db.repo_name)
                end
        end
        if success
                packages.l.keys #return the list of built package
                # TODO better handling of split dirs
        else
                success
        end
end
call(*args, **opts) click to toggle source
# File lib/aur/makepkg.rb, line 148
def call(*args, **opts)
        tools=@config.local_devtools #this set up pacman and makepkg config files
        env=opts.delete(:env) || {}
        opts[:method]||=:run_simple
        @dir.chdir do
                tools.makepkg(*args, env: @env.merge(env), **opts)
        end
end
edit() click to toggle source

shortcut

# File lib/aur/makepkg.rb, line 231
def edit
        get(view: true, update: false, clone: true, pkgver: false)
end
edit_pkgbuild() click to toggle source
# File lib/aur/makepkg.rb, line 234
def edit_pkgbuild
        get(view: false, update: false, clone: true, pkgver: false)
        #TODO: @config.view_file/view_dir?
        @config.view(@dir+"PKGBUILD")
end
exist?() click to toggle source
# File lib/aur/makepkg.rb, line 131
def exist?
        pkgbuild.exist?
end
get(logdir: nil, view: false, update: true, clone: true, pkgver: false) click to toggle source
# File lib/aur/makepkg.rb, line 205
def get(logdir: nil, view: false, update: true, clone: true, pkgver: false)
        if logdir
                logdir=Pathname.new(logdir)
                logdir.mkpath
        end
        get_pkg=self.get_pkg

        if @dir.exist? and update
                get_pkg.update(logdir: logdir)
        elsif !@dir.exist? and clone
                get_pkg.clone(logdir: logdir)
        end
        if view #view before calling pkgver
                r=@config.view(@dir)
                get_pkg.done_view if r and get_pkg.respond_to?(:done_view)
        else
                r=true
        end
        if r and pkgver and pkgver?
                get_source
        else
                return r #abort pkgver
        end
end
get_pkg() click to toggle source

should respond to clone, update and optionally done_view, done_build

# File lib/aur/makepkg.rb, line 118
def get_pkg
        #@get_pkg||=@config[:default_get_class].new(@dir, url: name, config: @config)
        @get_pkg ||= Archlinux.create_class(@config[:default_get_class], @dir, url: name, config: @config)
end
get_source() click to toggle source
# File lib/aur/makepkg.rb, line 244
def get_source
        success, _r=call('--nodeps', '--nobuild', method: :sh)
        success
end
info(get: false) click to toggle source
# File lib/aur/makepkg.rb, line 157
def info(get: false)
        if get
                get_options={}
                get_options=get if get.is_a?(Hash)
                self.get(**get_options)
        end
        stdin=call("--printsrcinfo", chomp: :lines)
        mode=nil; r={}; current={}; pkgname=nil
        stdin.each do |l|
                key, value=l.split(/\s*=\s*/,2)
                next if key.nil?
                if key=="pkgbase"
                        mode=:pkgbase
                        current[:pkgbase]=value
                        current[:repo]=@dir
                elsif key=="pkgname"
                        if mode==:pkgbase
                                r=current
                                r[:pkgs]={}
                        else
                                r[:pkgs][pkgname]=current
                        end
                        current={}; mode=:pkgname; pkgname=value
                else
                        key=key.strip.to_sym
                        Archlinux.add_to_hash(current, key, value)
                end
        end
        r[:pkgs][pkgname]=current #don't forget to update the last one
        r
end
install(*args, view: true, **opts) click to toggle source
# File lib/aur/makepkg.rb, line 308
def install(*args, view: true, **opts)
        r=get(view: view)
        if r
                build(*args, **opts)
        else
                r
        end
end
list(**opts) click to toggle source
# File lib/aur/makepkg.rb, line 317
def list(**opts)
        call("--packagelist", chomp: :lines, err: "/dev/null", **opts).map {|f| Pathname.new(f)}
end
make(*args, sign: config&.use_sign?(:package), default_opts: [], force: false, asdeps: @asdeps, **opts) click to toggle source
# File lib/aur/makepkg.rb, line 249
def make(*args, sign: config&.use_sign?(:package), default_opts: [], force: false, asdeps: @asdeps, **opts)
        default_opts << "--sign" if sign
        default_opts << "--key=#{sign}" if sign.is_a?(String)
        default_opts << "--force" if force
        default_opts << "--asdeps" if asdeps
        default_opts+=@config[:makepkg][:build_args]

        # error=13 means the package is already built, we consider that a success
        success, _r=call(*args, method: :sh, default_opts: default_opts, env: @env, expected: 13, **opts)
        get_pkg.done_build if success and get_pkg.respond_to?(:done_build)
        success
end
makechroot(*args, sign: @config&.use_sign?(:package), force: false, **opts) click to toggle source
# File lib/aur/makepkg.rb, line 267
def makechroot(*args, sign: @config&.use_sign?(:package), force: false, **opts)
        unless force
                if list.all? {|f| f.exist?}
                        SH.logger.info "Skipping #{@dir} since it is already built (use force=true to override)"
                        return true #consider this a success build
                end
        end
        devtools=@config.chroot_devtools
        success=false
        @dir.chdir do
                success=devtools.makechrootpkg(*args, env: @env, **opts)
        end
        ## signing should be done by 'build'
        # self.sign(sign_name: sign) if sign and success
        success
end
makepkg(*args, **opts) click to toggle source

raw call to makepkg

# File lib/aur/makepkg.rb, line 144
def makepkg(*args, **opts)
        raw_call(*args, method: :sh, **opts)
end
mkarchroot() click to toggle source
# File lib/aur/makepkg.rb, line 262
def mkarchroot
        args=@config.dig(:chroot, :packages) || ["base-devel"]
        @config.chroot_devtools.mkarchroot(*args)
end
name() click to toggle source
# File lib/aur/makepkg.rb, line 123
def name
        @base.to_s
end
packages(refresh=false, get: false) click to toggle source
# File lib/aur/makepkg.rb, line 189
def packages(refresh=false, get: false)
        @packages=nil if refresh
        unless @packages
                r=info(get: get)
                pkgs=r.delete(:pkgs)
                # r[:pkgbase]
                base=Package.new(r)
                list=pkgs.map do |name, pkg|
                        pkg[:name]=name
                        Package.new(pkg).merge(base)
                end
                @packages=@config.to_packages(list)
        end
        @packages
end
pkgbuild() click to toggle source
# File lib/aur/makepkg.rb, line 127
def pkgbuild
        @dir+"PKGBUILD"
end
pkgver?() click to toggle source
# File lib/aur/makepkg.rb, line 240
def pkgver?
        exist? and pkgbuild.read.match(/^\s*pkgver()/)
end
raw_call(*args, method: :run_simple, **opts) click to toggle source
# File lib/aur/makepkg.rb, line 135
def raw_call(*args, method: :run_simple, **opts)
        @config.launch(:makepkg, *args, **opts) do |*args, **opts|
                @dir.chdir do
                        SH.public_send(method, @env, *args, **opts)
                end
        end
end
sign(sign_name: :package, **opts) click to toggle source
# File lib/aur/makepkg.rb, line 321
def sign(sign_name: :package, **opts)
        @config.sign(*list.select {|f| f.file?}, sign_name: sign_name, **opts)
end