Rebuild.pm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # ex:ts=8 sw=4:
  2. # $OpenBSD: Rebuild.pm,v 1.2 2013/10/06 13:33:38 espie Exp $
  3. #
  4. # Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
  5. #
  6. # Permission to use, copy, modify, and distribute this software for any
  7. # purpose with or without fee is hereby granted, provided that the above
  8. # copyright notice and this permission notice appear in all copies.
  9. #
  10. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. use strict;
  18. use warnings;
  19. package DPB::PortBuilder::Rebuild;
  20. our @ISA = qw(DPB::PortBuilder);
  21. sub init
  22. {
  23. my $self = shift;
  24. $self->SUPER::init;
  25. require OpenBSD::PackageRepository;
  26. $self->{repository} = OpenBSD::PackageRepository->new(
  27. "file:/$self->{fullrepo}");
  28. # this is just a dummy core, for running quick pipes
  29. $self->{core} = DPB::Core->new_noreg('localhost');
  30. }
  31. my $uptodate = {};
  32. sub equal_signatures
  33. {
  34. my ($self, $core, $v) = @_;
  35. my $p = $self->{repository}->find($v->fullpkgname.".tgz");
  36. my $plist = $p->plist(\&OpenBSD::PackingList::UpdateInfoOnly);
  37. my $pkgsig = $plist->signature->string;
  38. # and the port
  39. my $portsig = $self->{state}->grabber->grab_signature($core,
  40. $v->fullpkgpath);
  41. return $portsig eq $pkgsig;
  42. }
  43. sub check_signature
  44. {
  45. my ($self, $core, $v) = @_;
  46. my $okay = 1;
  47. for my $w ($v->build_path_list) {
  48. my $name = $w->fullpkgname;
  49. if (!-f "$self->{fullrepo}/$name.tgz") {
  50. print "$name: absent\n";
  51. $okay = 0;
  52. next;
  53. }
  54. next if $uptodate->{$name};
  55. if ($self->equal_signatures($core, $w)) {
  56. $uptodate->{$name} = 1;
  57. print "$name: uptodate\n";
  58. next;
  59. }
  60. print "$name: rebuild\n";
  61. $self->{state}->grabber->clean_packages($core,
  62. $w->fullpkgpath);
  63. $okay = 0;
  64. }
  65. return $okay;
  66. }
  67. # this is due to the fact check_signature is within a child
  68. sub register_package
  69. {
  70. my ($self, $v) = @_;
  71. $uptodate->{$v->fullpkgname} = 1;
  72. }
  73. sub end_check
  74. {
  75. my ($self, $v) = @_;
  76. return 0 unless $self->SUPER::end_check($v);
  77. $self->register_package($v);
  78. return 1;
  79. }
  80. sub check
  81. {
  82. my ($self, $v) = @_;
  83. return 0 unless $self->SUPER::check($v);
  84. return $uptodate->{$v->fullpkgname};
  85. }
  86. sub register_updates
  87. {
  88. my ($self, $v) = @_;
  89. for my $w ($v->build_path_list) {
  90. $self->end_check($w);
  91. }
  92. }
  93. sub checks_rebuild
  94. {
  95. my ($self, $v) = @_;
  96. return 1 unless $uptodate->{$v->fullpkgname};
  97. }
  98. 1;