Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkosi: implement obsbinlnk #872

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@ sub query {
return Build::Kiwi::queryiso($handle, %opts) if $do_kiwi && $binname =~ /\.iso$/;
return Build::Arch::query($handle, %opts) if $do_arch && $binname =~ /\.pkg\.tar(?:\.gz|\.xz|\.zst)?$/;
return Build::Arch::query($handle, %opts) if $do_arch && $binname =~ /\.arch$/;
return Build::Mkosi::queryiso($handle, %opts) if $do_mkosi && $binname =~ /\.(raw|tar|cpio|qcow2)(?:\.gz|\.xz|\.zstd)?$/;
return undef;
}

Expand All @@ -1379,6 +1380,7 @@ sub queryhdrmd5 {
my ($binname) = @_;
return Build::Rpm::queryhdrmd5(@_) if $do_rpm && $binname =~ /\.d?rpm$/;
return Build::Deb::queryhdrmd5(@_) if $do_deb && $binname =~ /\.deb$/;
return Build::Mkosi::queryhdrmd5(@_) if $do_mkosi && $binname =~ /\.(raw|tar|cpio|qcow2)(?:\.gz|\.xz|\.zstd)?$/;
return Build::Kiwi::queryhdrmd5(@_) if $do_kiwi && $binname =~ /\.iso$/;
return Build::Kiwi::queryhdrmd5(@_) if $do_kiwi && $binname =~ /\.raw$/;
return Build::Kiwi::queryhdrmd5(@_) if $do_kiwi && $binname =~ /\.raw.install$/;
Expand Down
64 changes: 64 additions & 0 deletions Build/Mkosi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,75 @@ sub parse {
if (length $cfg->val('Content', 'BuildPackages')) {
push(@packages, split /\s+/, $cfg->val('Content', 'BuildPackages'));
}
if (length $cfg->val('Partitions', 'BaseImage')) {
push(@packages, $cfg->val('Partitions', 'BaseImage'));
Copy link
Member

@lnussel lnussel Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it should add the prefix mkosi: I think

}

$ret->{'name'} = $fn;
$ret->{'deps'} = \@packages;

return $ret;
}

sub queryiso {
my ($file, %opts) = @_;
my $json_fh;
my $md5 = Digest::MD5->new;

open(my $fh, '<', $file) or die("Error opening $file: $!\n");
$md5->addfile($fh);
close($fh);
# If we also have split verity artifacts, the manifest file is the same as the main image,
# so remove the suffixes to find it
$file =~ s/(\.root|\.usr)//g;
$file = $file . ".manifest.gz";

eval { require JSON; };
*JSON::decode_json = sub {die("JSON::decode_json is not available\n")} unless defined &JSON::decode_json;

eval { require IO::Uncompress::Gunzip; };
*IO::Uncompress::Gunzip::new = sub {die("IO::Uncompress::Gunzip is not available\n")} unless defined &IO::Uncompress::Gunzip::new;

my $json_text = do {
open($json_fh, "<", $file) or die("Error opening $file: $!\n");
$json_fh = IO::Uncompress::Gunzip->new($json_fh) or die("Error opening $file: $IO::Uncompress::Gunzip::GunzipError\n");
local $/;
<$json_fh>
};

my $metadata = JSON::decode_json($json_text);
close $json_fh;

if (!$metadata || !$metadata->{'config'}) {
return {};
}

my $distribution = $metadata->{'config'}->{'distribution'};
my $release = $metadata->{'config'}->{'release'};
my $architecture = $metadata->{'config'}->{'architecture'};
my $name = $metadata->{'config'}->{'name'};
my $version = $metadata->{'config'}->{'version'};
my @provides = ("$distribution:$release");

return {
'provides' => \@provides,
'version' => $version,
'arch' => $architecture,
'name' => $name,
'source' => $name,
'hdrmd5' => $md5->hexdigest(),
};
}

sub queryhdrmd5 {
my ($bin) = @_;

open(my $fh, '<', $bin) or croak("could not open $bin");
my $md5 = Digest::MD5->new;
$md5->addfile($fh);
close($fh);

return $md5->hexdigest();
}

1;
7 changes: 7 additions & 0 deletions PBuild/BuildResult.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ sub integrate_build_result {
my $obsbinlnk = PBuild::Container::containerinfo2obsbinlnk($1, $2, $p->{'pkg'});
PBuild::Util::store("$dst/$prefix.obsbinlnk", undef, $obsbinlnk) if $obsbinlnk;
}
if ($file =~ /(.*)\.manifest(?:\.(?:gz|bz2|xz|zst|zstd))?$/) {
# create an obsbinlnk file from the mkosi manifest
my $prefix = $1;
die unless $result->{$file} =~ /^(.*)\/([^\/]+)$/;
my $obsbinlnk = PBuild::Container::manifest2obsbinlnk($1, $2, $prefix, $p->{'pkg'});
PBuild::Util::store("$dst/$prefix.obsbinlnk", undef, $obsbinlnk) if $obsbinlnk;
}
PBuild::Util::cp($result->{$file}, "$dst/$file");
}
# create new bininfo
Expand Down
58 changes: 58 additions & 0 deletions PBuild/Container.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,66 @@ use PBuild::Verify;
eval { require JSON::XS };
*JSON::XS::decode_json = sub {die("JSON::XS is not available\n")} unless defined &JSON::XS::decode_json;

eval { require IO::Uncompress::Gunzip; };
*IO::Uncompress::Gunzip::new = sub {die("IO::Uncompress::Gunzip is not available\n")} unless defined &IO::Uncompress::Gunzip::new;

use strict;

sub manifest2obsbinlnk {
my ($dir, $file, $prefix, $packid) = @_;
my $json_fh;
my $md5 = Digest::MD5->new;
my $image;
my $json_text = do {
unless (open($json_fh, "<", "$dir/$file")) {
warn("Error opening $dir/$file: $!\n");
return {};
}
if ($file =~ /\.gz$/) {
$json_fh = IO::Uncompress::Gunzip->new($json_fh) or die("Error opening $dir/$file: $IO::Uncompress::Gunzip::GunzipError\n");
}
local $/;
<$json_fh>
};

my $metadata = JSON::XS::decode_json($json_text);
if (!$metadata || !$metadata->{'config'}) {
return {};
}

foreach my $ext ("", ".gz", ".xz", ".zst", ".zstd") {
if (-e "$dir/$prefix$ext") {
open(my $fh, '<', "$dir/$prefix$ext") or die("Error opening $dir/$prefix$ext: $!\n");
$md5->addfile($fh);
close($fh);
$image = $prefix . $ext;
last;
}
}
if (!$image) {
return {};
}

my $distribution = $metadata->{'config'}->{'distribution'};
my $release = $metadata->{'config'}->{'release'};
my $architecture = $metadata->{'config'}->{'architecture'};
my $name = $metadata->{'config'}->{'name'};
my $version = $metadata->{'config'}->{'version'};
# Note: release here is not the RPM release, but the distribution release (eg: Debian 10)
my @provides = ("$distribution:$release", "$name = $version", "$packid = $version");

return {
'provides' => \@provides,
'source' => $packid,
'name' => $name,
'version' => $version,
'release' => '0',
'arch' => $architecture,
'hdrmd5' => $md5->hexdigest(),
'lnk' => $image,
};
}

sub containerinfo2nevra {
my ($d) = @_;
my $lnk = {};
Expand Down
3 changes: 2 additions & 1 deletion build-vm-qemu
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ vm_startup_qemu() {
x86_64)
qemu_bin="/usr/bin/qemu-system-x86_64"
qemu_cpu="-cpu qemu64"
qemu_device=virtio-blk
# Use defaults and fallbacks for other values
;;
#
Expand Down Expand Up @@ -213,7 +214,7 @@ vm_kill_qemu() {
vm_fixup_qemu() {
vm_fixup_kvm
case $BUILD_HOST_ARCH in
armv6l|armv7l|armv8l|aarch32|aarch64|aarch64_ilp32|ppc|ppcle|ppc64|ppc64le|riscv64|s390|s390x)
armv6l|armv7l|armv8l|aarch32|aarch64|aarch64_ilp32|ppc|ppcle|ppc64|ppc64le|riscv64|s390|s390x|x86_64)
VM_ROOTDEV=/dev/disk/by-id/virtio-0
VM_SWAPDEV=/dev/disk/by-id/virtio-1
;;
Expand Down