aboutsummaryrefslogtreecommitdiffstats
path: root/Tools/scripts/mark_safe.pl
blob: fa0b4ebfeb9896e4069094373b168e1d8ffac6dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#!/usr/bin/perl -w

# $FreeBSD$
#
# MAINTAINER=   pgollucci@FreeBSD.org

## core
use strict;
use warnings FATAL => 'all';
use Carp;

use File::Find ();
use Getopt::Long ();
use Pod::Usage ();

### constants
## exit codes
use constant EXIT_SUCCESS   => 0;
use constant EXIT_FAILED_INVALID_ARGS_OR_ENV => 1;

## other
use constant PROGNAME => $0;

### signal handlers
local $SIG{__DIE__}  = \&Carp::confess;
local $SIG{__WARN__} = \&Carp::cluck;

### version
our $VERSION = do { my @r = (q$FreeBSD$ =~ /\d+/g); sprintf "%d." . "%02d" x $#r, @r };

### globals
# cmdline options (standard) with defaults
my $Help      = 0;
my $Version   = 0;
my $Debug     = 0;
my $Verbose   = 0;
my $NoExec    = 0;

# cmdline options (custom) with defaults
my $Maintainer = "$ENV{USER}\@FreeBSD.org";
my $Ports = 0;
my $Safe = 1;
my $Index = 'INDEX-8';

# internals
my $PORTSDIR = $ENV{PORTSDIR} || '/usr/ports';
my %RPARTS = (
    0 => 'pkg_name',
    1 => 'dir',
    2 => 'prefix',
    3 => 'comment',
    4 => 'pkg_descr',
    5 => 'maintainer',
    6 => 'categories',
    7 => 'ldep',
    8 => 'rdep',
    9 => 'www',
);

my %PARTS = reverse %RPARTS;

### Utility Functions
sub error   { print STDERR "ERROR: $_[0]"                              }
sub debug   { print STDERR "DEBUG: $_[0]"          if $Debug           }
sub verbose { print STDOUT "VERBOSE($_[0]): $_[1]" if $Verbose > $_[0] }

### main
sub getopts_wrapper {

  my $rv =
    Getopt::Long::GetOptions(
      "debug|d"      => \$Debug,
      "verbose=i"    => \$Verbose,
      "help|h"       => \$Help,
      "version|V"    => \$Version,
      "noexec|n"     => \$NoExec,

      "maintainer|m=s" => \$Maintainer,
      "ports|p"        => \$Ports,

      "safe|s=i"       => \$Safe,
      "index|i=s"      => \$Index,
    );

  Pod::Usage::pod2usage(-verbose => 1) unless $rv;

  unless ($Help || valid_args()) {
     $rv = 0;
     Pod::Usage::pod2usage(-verbose => 1);
  }

  return $rv ? 1 : 0;
}

sub valid_args {

  my $errors = 0;

  ## NoExec implies Verbosity level 1
  $Verbose = 1 if $NoExec;

  return $errors > 0 ? 0 : 1;
}

sub work {

  my $rv = EXIT_SUCCESS;

  my $ports = ports_get();
  mark($ports);

  return $rv;
}

sub mark {
  my ($ports) = @_;

  foreach my $port_dir (@$ports) {
    my $mfile = "$port_dir/Makefile";
    print "Mfile: $mfile\n";
    open my $mk, '<', $mfile or die "Can't open [$mfile] b/c [$!]";
    my @lines = <$mk>;
    close $mk or die "Can't close [$mfile] b/c [$!]";
    
    next if grep { /MAKE_JOBS_(?:UN)?SAFE/ } @lines;

    my $i_depends = 0;
    my $i_comment = 0;
    my $i_maintainer = 0;
    my $i = 0;
    foreach my $line (@lines) {
      ## ORDER MATTERs, lowest in file is last
      $i_depends    = $i if $line =~ /DEPENDS/;
      $i_comment    = $i if $line =~ /COMMENT/;
      $i_maintainer = $i if $line =~ /MAINTAINER/;
      ++$i;
    }

    my $loc = $i_depends    > 0 ? $i_depends :
              $i_comment    > 0 ? $i_comment :
              $i_maintainer > 0 ? $i_maintainer : die "Can't find location to insert";

    my @newlines = @lines[0..$loc];
    push @newlines, "\n", "MAKE_JOBS_" . ($Safe ? "SAFE" : "UNSAFE")  . "=  yes\n";
    push @newlines, @lines[$loc+1..$#lines];

    open my $mk_o, '>', $mfile or die "Can't open [$mfile] b/c [$!]";
    foreach my $line (@newlines) {
      print $mk_o $line;
    }
    close $mk_o or die "Can't close [$mfile] b/c [$!]";
  }

  return;
}

sub ports_get {

  my @ports = ();

  if ($Ports) {
    @ports = map { "$PORTSDIR/$_" } @ARGV;
  }
  else {
    my $index = "$PORTSDIR/$Index";
    print "Index: $index\n";

    open my $fh, '<', $index or die "Can't open [$index] b/c [$!]";
    while (<$fh>) {
      my @parts = split /\|/;
      my $port_dir = $parts[$PARTS{dir}];
      $port_dir =~ s!/usr/ports!$PORTSDIR!;
      my $maintainer = $parts[$PARTS{maintainer}];
   
      push @ports, $port_dir if $maintainer =~ /^$Maintainer$/io;
    }
    close $fh or die "Can't close [$index] b/c [$!]";
  }

  @ports = grep { !/^rubygem-// } @ports;

  return \@ports;
}

sub main {

  getopts_wrapper() or return EXIT_FAILED_INVALID_ARGS_OR_ENV;

  if ($Help) {
    Pod::Usage::pod2usage(-verbose => 1);
    return EXIT_SUCCESS;
  }

  if ($Version) {
    print PROGNAME . " - v$VERSION\n\n";
    return EXIT_SUCCESS;
  }

  return work();
}

MAIN: {
  exit main();
}

__END__

=pod

=head1 NAME

mark_safe.pl - Mark a port or ports as MAKE_JOBS_(UN)SAFE=yes

=head1 SYNOPSIS

  mark_safe.pl <options>

=head1 STD OPTIONS

=over 4

=item B<--verbose=1,2,3,4,....>

Display messages while running on STDOUT. Increasing the level
will increase the amount.

DEFAULT: off/0

=item B<--debug|d>

Copious messages not useful unless you are a developer AND
debuging this script are output to STDERR

DEFAULT: off/0

=item B<--help|h>

Print this message and exit EXIT_SUCCESS

DEFAULT: off/0

=item B<--version|V>

Output the version and exit with EXIT_SUCCESS

DEFAULT: off/0

=item B<--noexec|n>

Any External commands will simply be echo'd and not run
Assume all of them suceed.

IMPLIES: --verbose=1

DEFAULT: off/0

=head1 Dependencies

=head1 EXIT CODES

Exits 0 on success
Exits > 0 <= 255 on error

  EXIT_SUCCESS                    => 0
    EXIT_FAILED_INVALID_ARGS_OR_ENV => 1

=head1 HISTORY

20009-04-22 by pgollucci:
   Created

=head1 AUTHOR

Philip M. Gollucci E<lt>pgollucci@FreeBSD.orgE<gt>

=cut

ead6b994d4b4517a143de1f180459076a'>Bump freetype's lib numberjseger1999-11-251-1/+1 * Unbreak.jmz1999-11-252-10/+0 * Unbreak for pre-gcc 2.95 systemsjmz1999-11-232-2/+8 * Mark BROKEN, this defines putenv(), which has preprocessor #ifdef's wrappedbillf1999-11-172-0/+4 * Add support for threads (use at your own risk)jmz1999-11-132-0/+22 * Turn off NO_PACKAGE for the Alpha. XFree86 is not yet providing us bitsobrien1999-11-132-0/+4 * Pickup some missing files in PLIST.steve1999-11-012-0/+24 * Now that the port is no more marked broken, there is no need to include bsd.p...jmz1999-10-112-4/+0 * Unbreak for -current.marcel1999-10-102-6/+0 * Mark BROKEN for -current (signal.h)jmz1999-10-092-0/+10 * Use @exec/@unexec pairs for symlinks to directories. This should fixjmz1999-09-212-4/+8 * Add support for tk8.2jseger1999-09-072-2/+12 * Remove an extra blank line that I introduced a couple of revs ago.steve1999-09-072-2/+0 * Restore patches from rev. 1.18: add shlib minors to libraries with minors != 0jmz1999-09-032-12/+12 * Upgrade to 3.3.5jmz1999-09-022-4/+14 * Upgrade to 3.3.5jmz1999-09-024-22/+22 * FreeBSD.ORG -> FreeBSD.orgmharo1999-08-312-2/+2 * $Id$ -> $FreeBSD$peter1999-08-3132-32/+32 * $Id$ -> $FreeBSD$peter1999-08-312-2/+2 * grep -> ${GREP}mharo1999-08-232-4/+4 * Re-enforce caps, no period. An "exceptions" file has been createdhoek1999-08-031-1/+1 * Add Doug Rabson's patches for XFree86 on the FreeBSD/Alpha with minorsteve1999-07-274-4/+58 * Fix the xtt distribution master site and clean up somecpiazza1999-07-221-6/+6 * Use ${OSVERSION} instead of uname.asami1999-07-214-4/+6 * Upgrade to 3.3.4jmz1999-07-218-64/+72 * Add WWW:. This one exceeds 80 chars in length. I'm not sure what (if any)hoek1999-07-181-7/+3 * New ports/{java,irc,x11-servers} categories, Step #4 - Adjust new Makefiles.billf1999-06-2831-62/+62 * New category x11-servers. Here's the charter:asami1999-06-272-0/+37 * #4/4 enforcing Caps, no periodhoek1999-06-2730-30/+30 * Mark `only for i386'. These have i386 assembler code.simokawa1999-06-136-6/+18 * Updated checksum.asami1999-05-313-3/+3 * Change Mr.Nakaji's Email address.sada1999-05-1714-42/+42 * Add WWW:mharo1999-05-032-0/+4 * Alpha doesn't have JoystickSupport.simokawa1999-04-291-1/+1 * Add 'ONLY_FOR_ARCHS=i386'.simokawa1999-04-1314-14/+42 * Updated to version 1.2.1taoka1999-04-0232-120/+131 * Two more patches that were not intended for commit.asami1999-03-201-3/+3 * Back out two patches that were not intended for commit.asami1999-03-204-10/+4 * Fix to make ports work with bsd.port.mk rev. 1.306.asami1999-03-085-7/+13 * Fix up MASTER_SITES:fenner1999-01-282-10/+10 * Correct pkg/PLIST, maintainer forgot to add some entry.vanilla1999-01-171-0/+3 * Oops, forgot to add this file. Please mention additions in PRs please!asami1999-01-161-0/+23 * Submitted by: maintainerasami1999-01-1533-90/+124 * Upgrade to 3.3.3.1jmz1999-01-124-4/+20 * Activate RUN_DEPENDS to mkttfdir.sada1999-01-051-2/+2 * I've forgotton a file: host.def.XF86_3DLabs .sada1999-01-041-0/+23 * Fix for 3DLabs server's build.sada1999-01-043-46/+53 * A X True Type Server for 3DLabs Graphics Boards.sada1999-01-034-0/+38 * Update to 1.1sada1999-01-0348-228/+250 * Initial import of Xfstt version 0.9.10.steve1998-12-248-0/+105 * Add missing drivers: s3_virge, newmmio mmio_928 s3_generic,jmz1998-12-192-4/+14 * Use libttf.3 of the new freetype 1.2jseger1998-12-131-2/+2 * portlint.kuriyama1998-12-051-2/+1 * A X True Type Server for X98 Graphics Cards.kuriyama1998-12-0556-0/+546 * Add PC98 support.kuriyama1998-12-0530-2/+352 * Use MASTERDIR where appropriate. Also, add FILE_DEPENDS to denoteasami1998-12-0115-31/+71 * Restore shlib minors != 0.asami1998-11-242-12/+12 * Typo (was making libX11.so symlink in two places).asami1998-11-242-4/+4 * Upgrade to 3.3.3jmz1998-11-248-128/+192 * Use bsd.port.{pre,post}.mk to move PORTOBJFORMAT to front, or changeasami1998-11-143-39/+47 * Add support for pc98 machinesjmz1998-10-272-20/+76 * Add support for pc98 machinesjmz1998-10-272-2/+10 * Unbreak for ELF.steve1998-10-223-6/+11 * Mark BROKEN for ELF:jseger1998-10-151-1/+3 * Update maintainer's Email address and update to version 1.0pl00.steve1998-10-1020-72/+148 * Prepend ${WRKDIRPREFIX} to WRKDIR definitions.asami1998-10-091-2/+2 * Fixes for Krb4.markm1998-09-232-16/+32 * Make lib*.so links in a.out case.asami1998-09-222-2/+30 * freetype (libttf) is now converted to ELF.asami1998-09-211-2/+2 * Convert to ELF. These changes are based on a recent threadsteve1998-09-216-10/+50 * PR: 7794asami1998-09-0159-297/+274 * A X True Type Font Server.kuriyama1998-08-11