Skip to content

Commit

Permalink
Merge branch 'master' into sbom_spdx-debian_mapping_license
Browse files Browse the repository at this point in the history
  • Loading branch information
cschneemann committed May 3, 2024
2 parents 9bc2b02 + 5c4ac4e commit 1192444
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 133 deletions.
2 changes: 0 additions & 2 deletions Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,6 @@ 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 @@ -1393,7 +1392,6 @@ 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
61 changes: 0 additions & 61 deletions Build/Mkosi.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,65 +78,4 @@ sub parse {
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;
5 changes: 3 additions & 2 deletions PBuild/BuildResult.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use Build::SimpleXML;
use PBuild::Util;
use PBuild::Verify;
use PBuild::Container;
use PBuild::Mkosi;

my @binsufs = qw{rpm deb pkg.tar.gz pkg.tar.xz pkg.tar.zst};
my $binsufsre = join('|', map {"\Q$_\E"} @binsufs);
Expand Down Expand Up @@ -130,11 +131,11 @@ sub integrate_build_result {
PBuild::Util::cp_a($result->{$file}, "$dst/$file");
next;
}
if ($file =~ /(.*)\.manifest(?:\.(?:gz|bz2|xz|zst|zstd))?$/) {
if ($p->{'buildtype'} eq 'mkosi' && $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'});
my $obsbinlnk = PBuild::Mkosi::manifest2obsbinlnk($1, $2, $prefix, $p->{'pkg'});
PBuild::Util::store("$dst/$prefix.obsbinlnk", undef, $obsbinlnk) if $obsbinlnk;
}
PBuild::Util::cp($result->{$file}, "$dst/$file");
Expand Down
4 changes: 2 additions & 2 deletions PBuild/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ sub create {
'builddir' => $builddir,
'block' => undef, # block strategy (all,never)
'rebuild' => undef, # rebuild strategy (transitive,direct,local)
'debuginfo' => 1, # create debug packages?
'debuginfo' => defined($opts->{'debuginfo'}) ? $opts->{'debuginfo'} : 1, # create debug packages?
'genmetaalgo' => $genmetaalgo,
'lastcheck' => {},
'metacache' => {},
Expand Down Expand Up @@ -728,7 +728,7 @@ sub handlecycle {
my $notready = $ctx->{'notready'};
my $pkgsrc = $ctx->{'pkgsrc'};
if (grep {$notready->{$_->{'name'} || $_->{'pkg'}}} map {$pkgsrc->{$_}} @cycp) {
$notready->{$_->{'name'} || $_->{'pkg'}} ||= 1 for @cycp;
$notready->{$_->{'name'} || $_->{'pkg'}} ||= 1 for map {$pkgsrc->{$_}} @cycp;
}
return (undef, 3);
}
Expand Down
62 changes: 0 additions & 62 deletions PBuild/Container.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,8 @@ 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 {};
}

for my $ext ("", ".raw", ".gz", ".xz", ".zst", ".zstd") {
my $fn = "$dir/$prefix$ext";
if (-e $fn) {
if (-l $fn) {
$prefix = readlink($fn);
}
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'} || '0';
# Note: release here is not the RPM release, but the distribution release (eg: Debian 10)
my @provides = ("$distribution:$release", "mkosi:$name = $version", "mkosi:$packid = $version");

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

sub containerinfo2nevra {
my ($d) = @_;
my $lnk = {};
Expand Down
96 changes: 96 additions & 0 deletions PBuild/Mkosi.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
################################################################ #
# Copyright (c) 2021 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################

package PBuild::Mkosi;

use Digest::MD5 ();
use IO::Uncompress::Gunzip ();

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;

use strict;

sub manifest2obsbinlnk {
my ($dir, $file, $prefix, $packid) = @_;
my $json_fh;
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 = eval { JSON::XS::decode_json($json_text) };
return unless $metadata && $metadata->{'config'} && ref($metadata->{'config'}) eq 'HASH';

for my $ext ("", ".raw", ".gz", ".xz", ".zst", ".zstd") {
my $fn = "$dir/$prefix$ext";
if (-e $fn) {
if (-l $fn) {
$prefix = readlink($fn);
$prefix =~ s/.*\///;
}
$image = $prefix . $ext;
last
}
}
return unless $image;
eval { PBuild::Verify::verify_filename($image) };
return undef if $@;

open(my $fh, '<', "$dir/$image") or die("Error opening $dir/$image: $!\n");
my $md5 = Digest::MD5->new;
$md5->addfile($fh);
close($fh);

my $config = $metadata->{'config'};
my $distribution = $config->{'distribution'};
my $distrelease = $config->{'release'}; # distribution release (eg: Debian 10)
my $architecture = $config->{'architecture'};
my $name = $config->{'name'};
my $version = $config->{'version'} || '0';
my $release = '0';
my @provides = ("mkosi:$distribution:$distrelease", "mkosi:$name = $version-$release");

my $lnk = {
'name' => "mkosi:$name",
'version' => $version,
'release' => $release,
'arch' => 'noarch',
'provides' => \@provides,
'source' => $packid,
};
eval { PBuild::Verify::verify_nevraquery($lnk) };
return undef if $@;

$lnk->{'hdrmd5'} = $md5->hexdigest();
$lnk->{'lnk'} = $image;
return $lnk;
}

1;
8 changes: 4 additions & 4 deletions build-vm
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,10 @@ vm_img_mkfs() {
esac

# defaults for creating the filesystem
vm_img_mkfs_ext4_options='-O ^has_journal,^huge_file,^resize_inode,sparse_super,^metadata_csum'
vm_img_mkfs_ext4_extra='-E lazy_itable_init,discard'
vm_img_mkfs_ext4_options='-O ^has_journal,^huge_file,^resize_inode,sparse_super,^metadata_csum -E nodiscard'
vm_img_mkfs_ext4_extra='-E lazy_itable_init,nodiscard' # overwrites -E from _options by default
vm_img_mkfs_ext4="mkfs.ext4 -m 0 -q -F $vm_img_mkfs_ext4_options"
vm_img_mkfs_ext3='mkfs.ext3 -m 0 -q -F'
vm_img_mkfs_ext3='mkfs.ext3 -m 0 -q -F -E nodiscard'
vm_img_mkfs_ext2='mkfs.ext2 -m 0 -q -F'
vm_img_mkfs_reiserfs='mkreiserfs -q -f'
vm_img_mkfs_btrfs='mkfs.btrfs'
Expand Down Expand Up @@ -569,7 +569,7 @@ vm_set_personality_syscall() {
alpha*) PERSONALITY_SYSCALL=324 ;;
sparc*) PERSONALITY_SYSCALL=191 ;;
ia64*) PERSONALITY_SYSCALL=1140 ;;
aarch64*) PERSONALITY_SYSCALL=92 ;;
aarch64*|loongarch*) PERSONALITY_SYSCALL=92 ;;
i?86*|ppc*|arm*|sh4|cris|m68k*|s390*|unicore32|microblaze|riscv*) PERSONALITY_SYSCALL=136 ;;
*) cleanup_and_exit 1 "Unknown architecture personality: '$archname'" ;;
esac
Expand Down
3 changes: 3 additions & 0 deletions configs/sl15.6.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
%define gcc_version 7

RepoURL: https://download.opensuse.org/distribution/leap/15.6/repo/oss/
RegistryURL: https://registry.opensuse.org

BuildFlags: kvm-max-cpu-compat-power8

# create conflicts for packages installed into the target image
Expand Down

0 comments on commit 1192444

Please sign in to comment.