Skip to content

Commit

Permalink
pbuild: allow native builds when doing cross building
Browse files Browse the repository at this point in the history
This is currently signaled by prefixing the package name with
"native-". This is subject to change!
  • Loading branch information
mlschroe committed Apr 23, 2021
1 parent a6166cb commit a27a5a9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
26 changes: 15 additions & 11 deletions PBuild/Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,21 @@ sub prepare {
sub pkgexpand {
my ($ctx, @pkgs) = @_;
my $bconf = $ctx->{'bconf'};
if ($bconf->{'expandflags:preinstallexpand'}) {
my $err = Build::expandpreinstalls($bconf);
my $bconf_host = $ctx->{'bconf_host'};
if (($bconf_host || $bconf)->{'expandflags:preinstallexpand'}) {
my $err = Build::expandpreinstalls($bconf_host || $bconf);
die("cannot expand preinstalls: $err\n") if $err;
}
my $pkgsrc = $ctx->{'pkgsrc'};
my $subpacks = $ctx->{'subpacks'};
my $cross = $ctx->{'bconf_host'} ? 1 : 0;
my $cross = $bconf_host ? 1 : 0;
for my $pkg (@pkgs) {
PBuild::Expand::expand_deps($pkgsrc->{$pkg}, $bconf, $subpacks, $cross);
my $p = $pkgsrc->{$pkg};
if ($p->{'native'}) {
PBuild::Expand::expand_deps($p, $bconf_host, $subpacks);
} else {
PBuild::Expand::expand_deps($p, $bconf, $subpacks, $cross);
}
}
}

Expand Down Expand Up @@ -244,7 +250,7 @@ sub genmeta_image {
my @vmdeps = Build::get_vminstalls($ctx->{'bconf'});
$edeps = [ PBuild::Util::unify(@$edeps, @pdeps, @vmdeps) ];
}
my $dep2pkg = $ctx->{'dep2pkg'};
my $dep2pkg = $p->{'native'} ? $ctx->{'dep2pkg_host'} : $ctx->{'dep2pkg'};
my @new_meta;
for my $bin (@$edeps) {
my $q = $dep2pkg->{$bin};
Expand All @@ -262,7 +268,7 @@ sub genmeta {
my ($ctx, $p, $edeps, $hdeps) = @_;
my $buildtype = $p->{'buildtype'};
return genmeta_image($ctx, $p, $edeps) if $buildtype eq 'kiwi' || $buildtype eq 'docker' || $buildtype eq 'preinstallimage';
my $dep2pkg = $ctx->{'dep2pkg'};
my $dep2pkg = $p->{'native'} ? $ctx->{'dep2pkg_host'} : $ctx->{'dep2pkg'};
my $metacache = $ctx->{'metacache'};
my @new_meta;
my $builddir = $ctx->{'builddir'};
Expand Down Expand Up @@ -291,7 +297,6 @@ sub genmeta {
my $hostarch = $ctx->{'hostarch'};
for my $bin (@$hdeps) {
my $q = $dep2pkg_host->{$bin};
die("host dep $bin is local\n") if $q->{'packid'};
push @new_meta, ($q->{'hdrmd5'} || 'd0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0')." $hostarch:$bin";
}
}
Expand All @@ -305,7 +310,6 @@ sub genmeta {
#
sub check_image {
my ($ctx, $p) = @_;
my $bconf = $ctx->{'bconf'};
my $edeps = $p->{'dep_expanded'} || [];
my $notready = $ctx->{'notready'};
my $dep2src = $ctx->{'dep2src'};
Expand Down Expand Up @@ -380,7 +384,7 @@ sub check {
}
# expand host deps
my $hdeps;
if ($ctx->{'bconf_host'}) {
if ($ctx->{'bconf_host'} && !$p->{'native'}) {
my $subpacks = $ctx->{'subpacks'};
$hdeps = [ @{$p->{'dep_host'} || $p->{'dep'} || []} ];
@$hdeps = Build::get_deps($ctx->{'bconf_host'}, $subpacks->{$p->{'name'}}, @$hdeps);
Expand Down Expand Up @@ -443,7 +447,7 @@ sub check {
}
my $check = substr($mylastcheck, 32, 32); # metamd5

my $dep2pkg = $ctx->{'dep2pkg'};
my $dep2pkg = $p->{'native'} ? $ctx->{'dep2pkg_host'} : $ctx->{'dep2pkg'};
my $dep2pkg_host = $ctx->{'dep2pkg_host'};
$check .= $ctx->{'genmetaalgo'} if $ctx->{'genmetaalgo'};
$check .= $rebuildmethod;
Expand Down Expand Up @@ -646,7 +650,7 @@ sub build {
return ('unresolvable', "missing pre/vminstalls: $missing");
}
my $tdeps;
if (!$kiwimode && $ctx->{'bconf_host'}) {
if (!$kiwimode && !$p->{'native'} && $ctx->{'bconf_host'}) {
$tdeps = [ Build::get_sysroot($ctx->{'bconf'}, $ctx->{'subpacks'}->{$p->{'name'}}, @{$p->{'dep'} || []}) ];
if (!shift(@$tdeps)) {
return ('unresolvable', 'sysroot:' . join(', ', @$tdeps));
Expand Down
5 changes: 3 additions & 2 deletions PBuild/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ sub createjob {
my ($ctx, $jobname, $nbuilders, $buildroot, $p, $bdeps, $pdeps, $vmdeps, $sysdeps, $tdeps, $nounchanged) = @_;
my $opts = { %{$ctx->{'opts'}} }; # create copy so we can modify
my $hostarch = $opts->{'hostarch'};
my $arch = $p->{'native'} ? $hostarch : $ctx->{'arch'};

my $bconf = $ctx->{'bconf'};
my $helperarch = $bconf->{'hostarch'} || $ctx->{'arch'};
my $helperarch = $bconf->{'hostarch'} || $arch;
die("don't know how to build arch $helperarch\n") unless $PBuild::Cando::knownarch{$helperarch};

my $helper = '';
Expand Down Expand Up @@ -289,7 +290,7 @@ sub createjob {
push @args, '--logfile', "$buildroot/.build.log";
#push @args, '--release', "$release" if defined $release;
push @args, '--debug' if $ctx->{'debuginfo'};
push @args, "--arch=$ctx->{'arch'}";
push @args, "--arch=$arch";
push @args, '--jobs', $opts->{'jobs'} if $opts->{'jobs'};
#push @args, '--ccache' if $useccache && $oldpkgdir;
push @args, '--threads', $opts->{'threads'} if $opts->{'threads'};
Expand Down
4 changes: 2 additions & 2 deletions PBuild/LocalRepo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ sub gbininfo2full {
# get metadata of build artifacts that are to be used in subsequent builds
#
sub fetchrepo {
my ($bconf, $arch, $builddir, $pkgsrc) = @_;
my @pkgs = sort keys %$pkgsrc;
my ($bconf, $arch, $builddir, $pkgsrc, $pkgs) = @_;
my @pkgs = sort @{$pkgs || [ sort keys %$pkgsrc ] };
my $gbininfo = read_gbininfo($builddir, \@pkgs);
my $filter = PBuild::ExportFilter::calculate_exportfilter($bconf, $arch);
my %useforbuild = map {$_ => $pkgsrc->{$_}->{'useforbuildenabled'}} @pkgs;
Expand Down
3 changes: 2 additions & 1 deletion PBuild/Recipe.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sub find_recipe {
# Find and parse a recipe file
#
sub parse {
my ($bconf, $p, $buildtype, $arch, $cross) = @_;
my ($bconf, $p, $buildtype, $arch) = @_;
if ($p->{'pkg'} eq '_product') {
$p->{'error'} = 'excluded';
return;
Expand Down Expand Up @@ -140,6 +140,7 @@ sub parse {
sub split_hostdeps {
my ($p, $bconf) = @_;
return if $p->{'buildtype'} eq 'kiwi' || $p->{'buildtype'} eq 'docker' || $p->{'buildtype'} eq 'fissile';
return if $p->{'native'};
return unless @{$p->{'dep'} || []};
my %fromhost = map {$_ => 1} @{$bconf->{'fromhost'} || []};
for (@{$p->{'fromhost'} || []}) {
Expand Down
8 changes: 4 additions & 4 deletions PBuild/RepoMgr.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ sub addremoteregistry {
# Add a local repository to the manager
#
sub addlocalrepo {
my ($repos, $bconf, $myarch, $builddir, $pkgsrc) = @_;
my ($repos, $bconf, $myarch, $builddir, $pkgsrc, $pkgs) = @_;
my $id = "$myarch/local";
die("local repo already added\n") if $repos->{$id};
my $bins = PBuild::LocalRepo::fetchrepo($bconf, $myarch, $builddir, $pkgsrc);
my $bins = PBuild::LocalRepo::fetchrepo($bconf, $myarch, $builddir, $pkgsrc, $pkgs);
$_->{'repoid'} = $id for @$bins;
my $repo = { 'dir' => $builddir, 'bins' => $bins, 'arch' => $myarch, 'type' => 'local', 'repoid' => $id };
$repos->{$id} = $repo;
Expand All @@ -97,11 +97,11 @@ sub addemptyrepo {
# Update the local reposiory with new binary data
#
sub updatelocalrepo {
my ($repos, $bconf, $myarch, $builddir, $pkgsrc) = @_;
my ($repos, $bconf, $myarch, $builddir, $pkgsrc, $pkgs) = @_;
my $id = "$myarch/local";
my $repo = $repos->{$id};
die("local repo does not exist\n") unless $repo;
my $bins = PBuild::LocalRepo::fetchrepo($bconf, $myarch, $builddir, $pkgsrc);
my $bins = PBuild::LocalRepo::fetchrepo($bconf, $myarch, $builddir, $pkgsrc, $pkgs);
$_->{'repoid'} = $id for @$bins;
$repo->{'bins'} = $bins;
}
Expand Down
32 changes: 28 additions & 4 deletions pbuild
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ PBuild::Multibuild::expand_multibuilds(\%pkgsrc);

@pkgs = sort keys %pkgsrc;

# split into target/native packages
my @pkgs_target = @pkgs;
my @pkgs_native;
if ($cross) {
$pkgsrc{$_}->{'native'} = 1 for grep {/^native-/} @pkgs;
@pkgs_target = grep {!$pkgsrc{$_}->{'native'}} @pkgs;
@pkgs_native = grep {$pkgsrc{$_}->{'native'}} @pkgs;
}

# handle onlybuild/excludebuild from the build config
if (exists $bconf->{'buildflags:excludebuild'}) {
my %excludebuild;
Expand Down Expand Up @@ -272,7 +281,11 @@ my $buildtype = $bconf->{'type'} || '';
$buildtype = 'spec' if !$buildtype || $buildtype eq 'UNDEFINED';
for my $pkg (@pkgs) {
my $p = $pkgsrc{$pkg};
PBuild::Recipe::parse($bconf, $p, $buildtype, $myarch, $cross);
if ($p->{'native'}) {
PBuild::Recipe::parse($bconf_host, $p, $buildtype, $hostarch);
} else {
PBuild::Recipe::parse($bconf, $p, $buildtype, $myarch);
}
if ($p->{'buildtype'} && ($p->{'buildtype'} eq 'kiwi' || $p->{'buildtype'} eq 'docker') && !$p->{'error'}) {
my @containerdeps = grep {/^container:/} @{$p->{'dep'} || []};
next unless @containerdeps;
Expand Down Expand Up @@ -316,7 +329,8 @@ my $repomgr = PBuild::RepoMgr::create();
my @repos;
my @hostrepos;
print "fetching local repo metadata\n";
push @repos, $repomgr->addlocalrepo($bconf, $myarch, $builddir, \%pkgsrc);
push @repos, $repomgr->addlocalrepo($bconf, $myarch, $builddir, \%pkgsrc, \@pkgs_target);
push @hostrepos, $repomgr->addlocalrepo($bconf_host, $hostarch, $builddir, \%pkgsrc, \@pkgs_native) if @pkgs_native;

print "fetching remote repo metadata\n";
for my $repourl (@{$opts->{'repo'}}) {
Expand Down Expand Up @@ -393,7 +407,13 @@ while (1) {
print "expanding dependencies\n" unless $runs;
$ctx->pkgexpand(@pkgs);
print "sorting packages\n" unless $runs;
@pkgs = $ctx->pkgsort(@pkgs);
if (@pkgs_native) {
@pkgs_native = $ctx->pkgsort(@pkgs_native);
@pkgs_target = $ctx->pkgsort(@pkgs_target);
@pkgs = (@pkgs_native, @pkgs_target);
} else {
@pkgs = $ctx->pkgsort(@pkgs);
}
}
$runs++;
$ctx->{'buildconfig'} = $buildconfig;
Expand Down Expand Up @@ -436,7 +456,11 @@ while (1) {
PBuild::LocalRepo::update_gbininfo($builddir, $p->{'pkg'}, $bininfo);
if ($p->{'useforbuildenabled'}) {
# update with new local bin information
$repomgr->updatelocalrepo($bconf, $myarch, $builddir, \%pkgsrc);
if ($p->{'native'}) {
$repomgr->updatelocalrepo($bconf, $hostarch, $builddir, \%pkgsrc, \@pkgs_native);
} else {
$repomgr->updatelocalrepo($bconf, $myarch, $builddir, \%pkgsrc, \@pkgs_target);
}
# we also need a new checker
undef $ctx;
}
Expand Down

0 comments on commit a27a5a9

Please sign in to comment.