summaryrefslogtreecommitdiff
path: root/usr.sbin/pkg_add/OpenBSD
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgCreate.pm114
1 files changed, 76 insertions, 38 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm b/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm
index 27108cad94c..75e5a300067 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgCreate.pm
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgCreate.pm,v 1.101 2014/02/02 15:35:52 espie Exp $
+# $OpenBSD: PkgCreate.pm,v 1.102 2014/03/05 22:32:32 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -790,49 +790,32 @@ sub really_solve_dependency
return $v;
}
-my $cache = {};
-sub solve_from_ports
+sub diskcachename
{
- my ($self, $state, $dep, $package) = @_;
+ my ($self, $dep) = @_;
- my $portsdir = $state->defines('PORTSDIR');
- return undef unless defined $portsdir;
- my $pkgname;
- if (defined $cache->{$dep->{pkgpath}}) {
- $pkgname = $cache->{$dep->{pkgpath}};
+ if ($ENV{_DEPENDS_CACHE}) {
+ my $diskcache = $dep->{pkgpath};
+ $diskcache =~ s/\//--/g;
+ return $ENV{_DEPENDS_CACHE}."/pkgcreate-".$diskcache;
} else {
- my ($plist, $diskcache);
- if ($ENV{_DEPENDS_CACHE}) {
- $diskcache = $dep->{pkgpath};
- $diskcache =~ s/\//--/g;
- $diskcache = $ENV{_DEPENDS_CACHE}."/pkgcreate-".
- $diskcache;
- }
- if (defined $diskcache && -f $diskcache) {
- $plist = OpenBSD::PackingList->fromfile($diskcache);
- } else {
- $plist = $self->ask_tree($state, $dep, $portsdir,
- 'print-plist-libs-with-depends',
- 'wantlib_args=no-wantlib-args');
- if ($? != 0 || !defined $plist->pkgname) {
- $state->error("Can't obtain dependency #1 from ports tree",
- $dep->{pattern});
- return undef;
- }
- $plist->tofile($diskcache) if defined $diskcache;
- }
- OpenBSD::SharedLibs::add_libs_from_plist($plist, $state);
- $self->add_dep($plist);
- $pkgname = $plist->pkgname;
- $cache->{$dep->{pkgpath}} = $pkgname;
- }
- if ($dep->spec->filter($pkgname) == 0) {
- $state->error("Dependency #1 doesn't match FULLPKGNAME: #2",
- $dep->{pattern}, $pkgname);
return undef;
}
+}
- return $pkgname;
+sub to_cache
+{
+ my ($self, $plist, $final) = @_;
+ # try to cache atomically.
+ # no error if it doesn't work
+ require OpenBSD::MkTemp;
+ my ($fh, $tmp) = OpenBSD::MkTemp::mkstemp(
+ "$ENV{_DEPENDS_CACHE}/my.XXXXXXXXXXX") or return;
+ chmod 0644, $fh;
+ $plist->write($fh);
+ close($fh);
+ rename($tmp, $final);
+ unlink($tmp);
}
sub ask_tree
@@ -860,6 +843,61 @@ sub ask_tree
return $plist;
}
+sub really_solve_from_ports
+{
+ my ($self, $state, $dep, $portsdir) = @_;
+
+ my $diskcache = $self->diskcachename($dep);
+ my $plist;
+
+ if (defined $diskcache && -f $diskcache) {
+ $plist = OpenBSD::PackingList->fromfile($diskcache);
+ } else {
+ $plist = $self->ask_tree($state, $dep, $portsdir,
+ 'print-plist-libs-with-depends',
+ 'wantlib_args=no-wantlib-args');
+ if ($? != 0 || !defined $plist->pkgname) {
+ return undef;
+ }
+ if (defined $diskcache) {
+ $self->to_cache($plist, $diskcache);
+ }
+ }
+ OpenBSD::SharedLibs::add_libs_from_plist($plist, $state);
+ $self->add_dep($plist);
+ return $plist->pkgname;
+}
+
+my $cache = {};
+
+sub solve_from_ports
+{
+ my ($self, $state, $dep, $package) = @_;
+
+ my $portsdir = $state->defines('PORTSDIR');
+ return undef unless defined $portsdir;
+ my $pkgname;
+ if (defined $cache->{$dep->{pkgpath}}) {
+ $pkgname = $cache->{$dep->{pkgpath}};
+ } else {
+ $pkgname = $self->really_solve_from_ports($state, $dep,
+ $portsdir);
+ $cache->{$dep->{pkgpath}} = $pkgname;
+ }
+ if (!defined $pkgname) {
+ $state->error("Can't obtain dependency #1 from ports tree",
+ $dep->{pattern});
+ return undef;
+ }
+ if ($dep->spec->filter($pkgname) == 0) {
+ $state->error("Dependency #1 doesn't match FULLPKGNAME: #2",
+ $dep->{pattern}, $pkgname);
+ return undef;
+ }
+
+ return $pkgname;
+}
+
# we don't want old libs
sub find_old_lib
{