Grabber.pm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # ex:ts=8 sw=4:
  2. # $OpenBSD: Grabber.pm,v 1.37 2016/05/22 11:41:56 nigel 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. use DPB::Vars;
  20. use DPB::Util;
  21. package DPB::Grabber;
  22. sub new
  23. {
  24. my ($class, $state, $endcode) = @_;
  25. my $o = bless {
  26. loglist => DPB::Util->make_hot($state->logger->append("vars")),
  27. engine => $state->engine,
  28. builder => $state->builder,
  29. state => $state,
  30. keep_going => 1,
  31. errors => 0,
  32. endcode => $endcode
  33. }, $class;
  34. my @values = ();
  35. if ($state->{want_fetchinfo}) {
  36. require DPB::Fetch;
  37. push(@values, 'fetch');
  38. $o->{fetch} = DPB::Fetch->new($state->distdir, $state->logger,
  39. $state);
  40. } else {
  41. $o->{fetch} = DPB::FetchDummy->new;
  42. }
  43. if ($state->{test}) {
  44. push(@values, 'test');
  45. }
  46. $o->{dpb} = join(' ', @values);
  47. return $o;
  48. }
  49. sub expire_old_distfiles
  50. {
  51. my ($self, $core, $opt_e) = @_;
  52. # don't bother if dump-vars wasn't perfectly clean
  53. return 0 if $self->{errors};
  54. return $self->{fetch}->run_expire_old($core, $opt_e);
  55. }
  56. sub finish
  57. {
  58. my ($self, $h) = @_;
  59. for my $v (values %$h) {
  60. if ($v->{broken}) {
  61. $self->{engine}->add_fatal($v, $v->{broken});
  62. delete $v->{broken};
  63. } else {
  64. if ($v->{wantbuild}) {
  65. delete $v->{wantbuild};
  66. $self->{engine}->new_path($v);
  67. }
  68. if ($v->{dontjunk}) {
  69. $self->{builder}->dontjunk($v);
  70. }
  71. }
  72. }
  73. $self->{engine}->flush;
  74. $self->{keepgoing} = &{$self->{endcode}};
  75. }
  76. sub ports
  77. {
  78. my $self = shift;
  79. return $self->{state}->ports;
  80. }
  81. sub make
  82. {
  83. my $self = shift;
  84. return $self->{state}->make;
  85. }
  86. sub make_args
  87. {
  88. my $self = shift;
  89. return $self->{state}->make_args;
  90. }
  91. sub logger
  92. {
  93. my $self = shift;
  94. return $self->{state}->logger;
  95. }
  96. sub forget_cache
  97. {
  98. my $self = shift;
  99. $self->{fetch}->forget_cache;
  100. }
  101. sub grab_subdirs
  102. {
  103. my ($self, $core, $list, $skip, $ignore_errors) = @_;
  104. $core->unsquiggle;
  105. DPB::Vars->grab_list($core, $self, $list, $skip, $ignore_errors,
  106. $self->{loglist}, $self->{dpb},
  107. sub {
  108. my $h = shift;
  109. for my $v (values %$h) {
  110. $v->{wantbuild} = 1;
  111. }
  112. $self->finish($h);
  113. });
  114. }
  115. sub grab_signature
  116. {
  117. my ($self, $core, $pkgpath) = @_;
  118. return DPB::PortSignature->grab_signature($core, $self, $pkgpath);
  119. }
  120. sub clean_packages
  121. {
  122. my ($self, $core, $pkgpath) = @_;
  123. return DPB::CleanPackages->clean($core, $self, $pkgpath);
  124. }
  125. sub complete_subdirs
  126. {
  127. my ($self, $core, $skip) = @_;
  128. # more passes if necessary
  129. while ($self->{keep_going}) {
  130. my $subdirlist = {};
  131. for my $v (DPB::PkgPath->seen) {
  132. if (defined $v->{info}) {
  133. delete $v->{tried};
  134. delete $v->{wantinfo};
  135. if (defined $v->{wantbuild}) {
  136. delete $v->{wantbuild};
  137. $self->{engine}->new_path($v);
  138. }
  139. if (defined $v->{dontjunk}) {
  140. $self->{builder}->dontjunk($v);
  141. }
  142. next;
  143. }
  144. next if defined $v->{category};
  145. if (defined $v->{tried}) {
  146. $self->{engine}->add_fatal($v, "tried and didn't get it")
  147. if !defined $v->{errored};
  148. $v->{errored} = 1;
  149. $self->{errors}++;
  150. } elsif ($v->{wantinfo} || $v->{wantbuild}) {
  151. $v->add_to_subdirlist($subdirlist);
  152. $v->{tried} = 1;
  153. }
  154. }
  155. $self->{engine}->flush;
  156. last if (keys %$subdirlist) == 0;
  157. DPB::Vars->grab_list($core, $self, $subdirlist, $skip, 0,
  158. $self->{loglist}, $self->{dpb},
  159. sub {
  160. $self->finish(shift);
  161. });
  162. }
  163. }
  164. package DPB::FetchDummy;
  165. sub new
  166. {
  167. my $class = shift;
  168. bless {}, $class;
  169. }
  170. sub build_distinfo
  171. {
  172. }
  173. sub run_expire_old
  174. {
  175. return 0;
  176. }
  177. sub forget_cache
  178. {
  179. my $self = shift;
  180. $self->{cache} = {};
  181. }
  182. 1;