123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- # ex:ts=8 sw=4:
- # $OpenBSD: PortInfo.pm,v 1.36 2015/06/23 08:51:53 espie Exp $
- #
- # Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
- #
- # Permission to use, copy, modify, and distribute this software for any
- # purpose with or without fee is hereby granted, provided that the above
- # copyright notice and this permission notice appear in all copies.
- #
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- use strict;
- use warnings;
- package AddInfo;
- sub add
- {
- my ($class, $var, $o, $value, $parent) = @_;
- return if $value =~ m/^[\s\-]*$/;
- $o->{$var} = $class->new($value, $o, $parent);
- }
- sub new
- {
- my ($class, $value) = @_;
- bless \$value, $class;
- }
- sub string
- {
- my $self = shift;
- return $$self;
- }
- sub quickie
- {
- return 0;
- }
- package AddIgnore;
- our @ISA = qw(AddInfo);
- sub string
- {
- my $self = shift;
- my $msg = $$self;
- $msg =~ s/\\//g;
- $msg =~ s/\"\s+\"/\; /g;
- return $msg;
- }
- package AddYesNo;
- our @ISA = qw(AddInfo);
- sub add
- {
- my ($class, $var, $o, $value, $parent) = @_;
- return if $value =~ m/^no$/i;
- $o->{$var} = $class->new($value, $o, $parent);
- }
- sub new
- {
- my ($class, $value) = @_;
- my $a = 1;
- bless \$a, $class;
- }
- # micro-optimisation: to save space and time, we only create value if
- # PERMIT_DISTFILES* is != yes.
- package AddNegative;
- our @ISA = qw(AddInfo);
- sub add
- {
- my ($class, $var, $o, $value, $parent) = @_;
- return if $value =~ m/^yes$/i;
- $o->{$var} = $class->new($value, $o, $parent);
- }
- sub new
- {
- my ($class, $value) = @_;
- my $a = 0;
- bless \$a, $class;
- }
- package AddInfoShow;
- our @ISA = qw(AddInfo);
- sub quickie
- {
- return 1;
- }
- package AddList;
- our @ISA = qw(AddInfo);
- sub make_list
- {
- my ($class, $value) = @_;
- $value =~ s/^\s+//;
- $value =~ s/\s+$//;
- return split(/\s+/, $value);
- }
- sub new
- {
- my ($class, $value) = @_;
- my %values = map {($_, 1)} $class->make_list($value);
- bless \%values, $class;
- }
- sub string
- {
- my $self = shift;
- return join(', ', keys %$self);
- }
- package AddPropertyList;
- our @ISA = (qw(AddList));
- sub new
- {
- my ($class, $value) = @_;
- my %h = ();
- for my $v ($class->make_list($value)) {
- if ($v =~ /^(tag)\:(.*)$/) {
- $h{$1} = $2;
- } else {
- $h{$v} = 1;
- }
- }
- bless \%h, $class;
- }
- sub string
- {
- my $self = shift;
- my @l = ();
- while (my ($k, $v) = each %$self) {
- if ($v eq '1') {
- push(@l, $k);
- } else {
- push(@l, "$k->$v");
- }
- }
- return join(',', @l);
- }
- package AddOrderedList;
- our @ISA = qw(AddList);
- sub new
- {
- my ($class, $value) = @_;
- bless [$class->make_list($value)], $class;
- }
- sub string
- {
- my $self = shift;
- return join(' ', @$self);
- }
- package FetchManually;
- our @ISA = qw(AddOrderedList);
- sub add
- {
- my ($class, $var, $o, $value, $parent) = @_;
- return if $value =~ /^\s*no\s*$/i;
- $class->SUPER::add($var, $o, $value, $parent);
- }
- sub make_list
- {
- my ($class, $value) = @_;
- $value =~ s/^\s*\"//;
- $value =~ s/\"\s*$//;
- return split(/\"\s*\"/, $value);
- }
- sub string
- {
- my $self = shift;
- return join("\n", @$self);
- }
- package AddDepends;
- our @ISA = qw(AddList);
- sub extra
- {
- return 'EXTRA';
- }
- sub new
- {
- my ($class, $value, $self, $parent) = @_;
- my $r = {};
- for my $d ($class->make_list($value)) {
- my $copy = $d;
- next if $d =~ m/^$/;
- $d =~ s/^\:+//;
- $d =~ s/^[^\/]*\://;
- if ($d =~ s/\:(?:patch|build|configure)$//) {
- Extra->add($class->extra, $self, $d);
- } else {
- $d =~ s/\:$//;
- if ($d =~ m/[:<>=]/) {
- DPB::Util->die("Error: invalid *DEPENDS $copy");
- } else {
- my $info = DPB::PkgPath->new($d);
- $info->{parent} //= $parent;
- $r->{$info} = $info;
- }
- }
- }
- bless $r, $class;
- }
- sub string
- {
- my $self = shift;
- return '['.join(';', map {$_->logname} (values %$self)).']';
- }
- sub quickie
- {
- return 1;
- }
- package AddTestDepends;
- our @ISA = qw(AddDepends);
- sub extra
- {
- return 'EXTRA2';
- }
- package Extra;
- our @ISA = qw(AddDepends);
- sub add
- {
- my ($class, $key, $self, $value, $parent) = @_;
- $self->{$key} //= bless {}, $class;
- my $path = DPB::PkgPath->new($value);
- $path->{parent} //= $parent;
- $self->{$key}{$path} = $path;
- return $self;
- }
- package DPB::PortInfo;
- my %adder = (
- # actual info from dump-vars
- FULLPKGNAME => "AddInfoShow",
- RUN_DEPENDS => "AddDepends",
- BUILD_DEPENDS => "AddDepends",
- LIB_DEPENDS => "AddDepends",
- SUBPACKAGE => "AddInfo",
- BUILD_PACKAGES => "AddList",
- DPB_PROPERTIES => "AddPropertyList",
- IGNORE => "AddIgnore",
- FLAVOR => "AddList",
- DISTFILES => 'AddList',
- PATCHFILES => 'AddList',
- SUPDISTFILES => 'AddList',
- DIST_SUBDIR => 'AddInfo',
- CHECKSUM_FILE => 'AddInfo',
- FETCH_MANUALLY => 'FetchManually',
- MISSING_FILES => 'AddList',
- MASTER_SITES => 'AddOrderedList',
- MASTER_SITES0 => 'AddOrderedList',
- MASTER_SITES1 => 'AddOrderedList',
- MASTER_SITES2 => 'AddOrderedList',
- MASTER_SITES3 => 'AddOrderedList',
- MASTER_SITES4 => 'AddOrderedList',
- MASTER_SITES5 => 'AddOrderedList',
- MASTER_SITES6 => 'AddOrderedList',
- MASTER_SITES7 => 'AddOrderedList',
- MASTER_SITES8 => 'AddOrderedList',
- MASTER_SITES9 => 'AddOrderedList',
- MULTI_PACKAGES => 'AddList',
- PERMIT_DISTFILES_FTP => 'AddNegative',
- PERMIT_DISTFILES_CDROM => 'AddNegative',
- # not yet used, provision for regression tests
- TEST_DEPENDS => "AddTestDepends",
- NO_TEST => "AddNegative",
- TEST_IS_INTERACTIVE => "AddYesNo",
- # extra stuff we're generating
- DEPENDS => "AddDepends", # all BUILD_DEPENDS/LIB_DEPENDS
- EXTRA => "Extra", # extract stuff and things in DEPENDS
- EXTRA2 => "Extra", # extract stuff and things in TEST_DEPENDS
- BEXTRA => "Extra", # EXTRA moved from todo to done
- BDEPENDS => "AddDepends",# DEPENDS moved from todo to done
- RDEPENDS => "AddDepends",# RUN_DEPENDS moved from todo to done
- DIST => "AddDepends", # all DISTFILES with all info
- FDEPENDS => "AddDepends",# DISTFILES too, but after DISTIGNORE,
- # and shrinking
- # DISTIGNORE should be there ?
- );
- sub wanted
- {
- my ($class, $var) = @_;
- return $adder{$var};
- }
- sub new
- {
- my ($class, $pkgpath) = @_;
- $pkgpath->{info} = bless {}, $class;
- }
- sub add
- {
- my ($self, $var, $value, $parent) = @_;
- $adder{$var}->add($var, $self, $value, $parent);
- }
- sub dump
- {
- my ($self, $fh) = @_;
- for my $k (sort keys %adder) {
- print $fh "\t $k = ", $self->{$k}->string, "\n"
- if defined $self->{$k};
- }
- }
- my $string = "ignored already";
- my $s2 = "stub_name";
- my $stub_name = bless(\$s2, "AddInfoShow");
- my $stub_info = bless { IGNORE => bless(\$string, "AddIgnore"),
- FULLPKGNAME => $stub_name}, __PACKAGE__;
- sub stub
- {
- return $stub_info;
- }
- sub stub_name
- {
- my $self = shift;
- $self->{FULLPKGNAME} = $stub_name;
- }
- sub is_stub
- {
- return shift eq $stub_info;
- }
- use Data::Dumper;
- sub quick_dump
- {
- my ($self, $fh) = @_;
- for my $k (sort keys %adder) {
- if (defined $self->{$k} and $adder{$k}->quickie) {
- print $fh "\t $k = ";
- if (ref($self->{$k}) eq 'HASH') {
- print $fh "????\n";
- } else {
- print $fh $self->{$k}->string, "\n" ;
- }
- }
- }
- }
- sub fullpkgname
- {
- my $self = shift;
- return (defined $self->{FULLPKGNAME}) ?
- $self->{FULLPKGNAME}->string : undef;
- }
- sub has_property
- {
- my ($self, $name) = @_;
- return (defined $self->{DPB_PROPERTIES}) ?
- $self->{DPB_PROPERTIES}{$name} : undef;
- }
- sub want_tests
- {
- my ($self, $name) = @_;
- if (defined $self->{NO_TEST} && $self->{NO_TEST} == 0) {
- return 1;
- } else {
- return 0;
- }
- }
- sub solve_depends
- {
- my ($self, $withtest) = @_;
- if (!defined $self->{solved}) {
- my $dep = {};
- my @todo = (qw(DEPENDS BDEPENDS));
- if ($withtest) {
- push(@todo, qw(TDEPENDS));
- }
- for my $k (@todo) {
-
- if (exists $self->{$k}) {
- for my $d (values %{$self->{$k}}) {
- $dep->{$d->fullpkgname} = 1;
- }
- }
- next unless exists $self->{BEXTRA};
- for my $two (values %{$self->{BEXTRA}}) {
- next unless exists $two->{info}{$k};
- for my $d (values %{$two->{info}{$k}}) {
- $dep->{$d->fullpkgname} = 1;
- }
- }
- }
- bless $dep, 'AddList';
- $self->{solved} = $dep;
- }
- return $self->{solved};
- }
- 1;
|