Skip to content

Commit

Permalink
various ebuild temp repo and fake repo updates for pkgcraft changes
Browse files Browse the repository at this point in the history
  • Loading branch information
radhermit committed Nov 17, 2024
1 parent bfa05c1 commit 6c533cb
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 188 deletions.
2 changes: 1 addition & 1 deletion lib/pkgcraft/pkg/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def eapi
end

def repo
@repo = Repos::Repo.send(:from_ptr, C.pkgcraft_pkg_repo(self), true) if @repo.nil?
@repo = Repos::Repo.send(:from_ptr, C.pkgcraft_pkg_repo(self), false) if @repo.nil?
@repo
end

Expand Down
48 changes: 22 additions & 26 deletions lib/pkgcraft/repo/ebuild_temp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,47 @@ module Pkgcraft
# FFI bindings for temporary ebuild repo related functionality
# rubocop:disable Layout/LineLength
module C
attach_function :pkgcraft_repo_ebuild_temp_create_ebuild, [:pointer, :string, :pointer, :uint64], String
attach_function :pkgcraft_repo_ebuild_temp_create_ebuild_raw, [:pointer, :string, :string], String
attach_function :pkgcraft_repo_ebuild_temp_create_pkg, [:pointer, :string, :pointer, :uint64], Pkgcraft::Pkgs::Pkg
attach_function :pkgcraft_repo_ebuild_temp_create_pkg_from_str, [:pointer, :string, :string], Pkgcraft::Pkgs::Pkg
attach_function :pkgcraft_repo_ebuild_temp_free, [:pointer], :void
attach_function :pkgcraft_repo_ebuild_temp_new, [:string, :pointer], :pointer
attach_function :pkgcraft_repo_ebuild_temp_new, [:string, :pointer, :int], :pointer
attach_function :pkgcraft_repo_ebuild_temp_path, [:pointer], :string
attach_function :pkgcraft_repo_ebuild_temp_repo, [:pointer], :repo
end
# rubocop:enable Layout/LineLength

module Repos
# Temporary ebuild package repo.
class EbuildTemp < Ebuild
class EbuildTemp
include Eapis

def initialize(id: "test", eapi: EAPI_LATEST_OFFICIAL, priority: 0)
eapi = Eapi.from_obj(eapi)
ptr = C.pkgcraft_repo_ebuild_temp_new(id, eapi)
ptr = C.pkgcraft_repo_ebuild_temp_new(id, eapi, priority)
raise Error::PkgcraftError if ptr.null?

@ptr_temp = FFI::AutoPointer.new(ptr, C.method(:pkgcraft_repo_ebuild_temp_free))
path = C.pkgcraft_repo_ebuild_temp_path(@ptr_temp)
super(path, id, priority)
@path = C.pkgcraft_repo_ebuild_temp_path(@ptr_temp)
end

def create_ebuild(cpv, *keys, data: nil)
c_keys, length = C.string_iter_to_ptr(keys)
path = C.pkgcraft_repo_ebuild_temp_create_ebuild(@ptr_temp, cpv, c_keys, length)
raise Error::PkgcraftError if path.nil?

unless data.nil?
File.open(path, "a") do |f|
f.write(data)
end
end

Pathname.new(path)
def repo
ptr = C.pkgcraft_repo_ebuild_temp_repo(@ptr_temp)
Repo.send(:from_ptr, ptr, false)
end

def create_ebuild_raw(cpv, data)
path = C.pkgcraft_repo_ebuild_temp_create_ebuild_raw(@ptr_temp, cpv, data)
raise Error::PkgcraftError if path.nil?
def create_pkg(cpv, *keys)
c_keys, length = C.string_iter_to_ptr(keys)
pkg = C.pkgcraft_repo_ebuild_temp_create_pkg(@ptr_temp, cpv, c_keys, length)
raise Error::PkgcraftError if pkg.nil?

Pathname.new(path)
pkg
end

def create_pkg(cpv, *keys, data: nil)
create_ebuild(cpv, *keys, data:)
iter(cpv).first
def create_pkg_from_str(cpv, data)
pkg = C.pkgcraft_repo_ebuild_temp_create_pkg_from_str(@ptr_temp, cpv, data)
raise Error::PkgcraftError if pkg.nil?

pkg
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/dep/test_cpv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def test_intersects
refute(dep.intersects(cpv2))

# packages
repo = EbuildTemp.new
pkg = repo.create_pkg("cat/pkg-1")
temp = EbuildTemp.new
pkg = temp.create_pkg("cat/pkg-1")
assert(cpv1.intersects(pkg))
refute(cpv2.intersects(pkg))

Expand Down
4 changes: 2 additions & 2 deletions test/dep/test_pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def test_intersects
refute(cpv.intersects(dep2))

# packages
repo = EbuildTemp.new
pkg = repo.create_pkg("cat/pkg-1")
temp = EbuildTemp.new
pkg = temp.create_pkg("cat/pkg-1")
assert(dep1.intersects(pkg))
refute(dep2.intersects(pkg))

Expand Down
Loading

0 comments on commit 6c533cb

Please sign in to comment.