File: parrotbug

package info (click to toggle)
parrot 6.6.0-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,164 kB
  • ctags: 16,050
  • sloc: ansic: 110,715; perl: 94,382; yacc: 1,911; lex: 1,529; lisp: 1,163; cpp: 782; python: 646; ruby: 335; sh: 140; makefile: 129; cs: 49; asm: 30
file content (759 lines) | stat: -rwxr-xr-x 19,581 bytes parent folder | download
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
#!/usr/bin/perl
#
# Copyright (C) 2004-2011, Parrot Foundation.
#

eval 'exec perl -w -S $0 ${1+"$@"}'
    if $running_under_some_shell;

use strict;
use warnings;

use Config;
use File::Spec;
use Getopt::Long;


my $VERSION = "1.0";

my $parrotdir = File::Spec->curdir();
my ( %opts, %parrot, %report );
my ( $editor, $user, $domain, $msgid, $tmpfile );
my ( $is_linux, $is_macos, $is_mswin32, $is_os2, $is_vms );
my @categories = qw[ core docs install library utilities languages ];
my @severities = qw[ critical high medium low wishlist none ];


#------------------------------------------------------------#
#                       Main program.                        #

init();
help()    if $opts{help};
version() if $opts{version};
explain_parrotbug() unless $opts{quiet};
query_missing_info();
what_next();
unlink $tmpfile;
exit;



# Explain what C<parrotbug> is.
sub explain_parrotbug {
    print <<EOT;

This program provides an easy way to create a message reporting a bug
in parrot, and e-mail it to the parrot developers.

It is *NOT* intended for:
  - sending test messages,
  - or reporting bugs in languages targeting parrot,
  - or reporting bugs in some library bindings for parrot,
  - or simply verifying that parrot works.

It is *ONLY* a mean of reporting verifiable problems with the core
parrot distribution, and any solutions to such problems, to parrot
developers.

If you're just looking for help with parrot, subscribe to the parrot
mailing list, parrot-dev<at>lists.parrot.org.



EOT
}




#------------------------------------------------------------#
#                        Utils subs.                         #

# Generate random filename to edit report.
sub generate_filename {
    my $dir = File::Spec->tmpdir();
    my $filename = "bugrep0$$";
    $filename++ while -e File::Spec->catfile($dir, $filename);
    $filename = File::Spec->catfile($dir, $filename);
    return $filename;
}


# Check whether a summary is trivial. A summary is not considered trivial
# if it's an ok or a nok report.
# Return 1 if trivial, 0 otherwise (summary acceptable).
sub trivial_summary {
    my $summary = shift;

    return 0 if $opts{ok} || $opts{nok};
    if ( $summary =~
         /^(y(es)?|no?|help|parrot( (bug|problem))?|bug|problem)$/i ||
         length($summary) < 4 ||
         $summary !~ /\s/ ) {
        return 1;
    }
    else {
        return 0;
    }
}




#------------------------------------------------------------#
#                         Init subs.                         #

# Initialize the program. 
# 
# Get parrot information, process the options, create the message
# information (summary, to, body, etc.) depending on the type of report
# (ok, nok or bug report).
sub init {
    $is_linux   = lc($^O) eq 'linux';
    $is_mswin32 = $^O eq 'MSWin32';
    $is_os2     = $^O eq 'os2';
    $is_vms     = $^O eq 'VMS';

    ##
    ## Fetch Parrot information.
    ##

    # Get parrot version.
    # There will always be an up-to-date $parrot/VERSION
    my $filename = File::Spec->catfile($parrotdir, "VERSION");
    open my $VERSION, '<', $filename or die "Cannot open '$filename': $!";
    $parrot{version} = <$VERSION>;
    chomp $parrot{version};
    close $VERSION or die "Cannot close '$filename': $!";

    # Get parrot configuration, stored in $parrot/myconfig
    $filename = File::Spec->catfile($parrotdir, "myconfig");
    open my $MYCONFIG, '<', $filename or die "Cannot open '$filename': $!";
    {
        local $/;
        $parrot{myconfig} = <$MYCONFIG>;
    }
    close $MYCONFIG or die "Cannot close '$filename': $!";


    ##
    ## Process options.
    ##
    Getopt::Long::Configure("no_bundling", "no_ignore_case", "auto_abbrev");
    help() unless GetOptions
      ( \%opts,
        "help|h", "version|V",
        "dump", "save",
        "from|f=s", "to|test|t=s", "editor|e=s",
        "summary|s=s", "category|C=s", "severity|S=s",
        "input|input-file|i=s", "output|output-file|o=s",
        "ok", "nok", "ack!", "quiet|q!" );

    ##
    ## Report to be sent.
    ##
  sw: {
      ok_report: {
            last ok_report unless defined $opts{ok};

            # This is an ok report, woohoo!
            $report{summary} = "OK: parrot $parrot{version} "
              . "on $Config{archname} $Config{osvers}";
            $report{body} = "Parrot reported to build OK on this system.\n";
            $report{category} = "install";
            $report{severity} = "none";
            $report{body} = "";
            last sw;
        };

        # Ok reports do not need body, but nok and bug reports do need
        # a body.
        if ( $opts{input} ) {
            # Report was pre-written, slurp it.
            open my $BODY, '<', $opts{input} or die "Can't open '$opts{input}': $!";
            local $/;
            $report{body} = <$BODY>;
            close $BODY or  die "Can't close '$opts{input}': $!";
        }
        else {
            # No file provided...
            $report{body} = "";
        }

      nok_report: {
            last nok_report unless defined $opts{nok};

            # This a nok report, how sad... :-(
            $report{summary} = "Not OK: parrot $parrot{version} "
              . "on $Config{archname} $Config{osvers}";
            $report{category} = "install";
            $report{severity} = "none";
            last sw;
        };

        # Neither an ok nor a nok.
        $report{summary}  = $opts{summary}  || "";
        $report{category} = $opts{category} || "";
        $report{severity} = $opts{severity} || "";
    };

    # Test message, shortcutting recipient.
    $report{to} = $opts{to} if $opts{to};

    ## 
    ## User information.
    ## 

    # Username.
    $user = $is_mswin32 ? $ENV{USERNAME}
	    : $is_os2   ? $ENV{USER} || $ENV{LOGNAME}
	    : $is_macos ? $ENV{USER}
	    : eval { getpwuid($<) };	# May be missing

    # User address, used in message
    $report{from} = $opts{from} || "";

   # Editor
    $editor = $ENV{VISUAL} || $ENV{EDITOR} || $ENV{EDIT}
      || ( $is_vms && "edit/tpu" )
      || ( $is_mswin32 && "notepad" )
      || ( $is_macos && "" )
      || "vi";

}



#------------------------------------------------------------#
#                       Querying subs.                       #

# Query missing information in order to have a complete report.
sub query_missing_info {
    $report{summary} = "" if trivial_summary( $report{summary} );
    $report{summary}  = ask_for_summary()     unless $report{summary};
    $report{category} = ask_for_alternative( "category", \@categories)
      unless $report{category};
    $report{severity} = ask_for_alternative( "severity", \@severities)
      unless $report{severity};
    $report{from} = ask_for_return_address()  unless $report{from};
    $report{body} = ask_for_body()            unless $report{body};
}


# Prompt for alternatives from a set of choices.
# 
# The arguments are: the name of alternative, the choices (as an array
# ref), and the default answer. (first element if undef)
# 
# Return the lowercased alternative chosen.
# 
# Die if more than 5 wrong answers.
sub ask_for_alternative {
    my ( $what, $choices, $default ) = @_;

    print <<EOT unless $opts{quiet};
Please pick a $what from the following:
  @{$choices}

EOT

    $default ||= $choices->[0];
    my $alt;
    my $err = 0;
    do {
        die "Invalid $alt: aborting.\n" if $err++ > 5;
        print "Please enter a $what [$default]: ";
        $alt = <STDIN>;
        chomp $alt;
        $alt = $default if $alt =~ /^\s*$/;
    } until ( ($alt) = grep /^$alt/i, @$choices );

    print "\n\n\n";
    return lc $alt;
}


# Prompt for a body, through an external editor.
sub ask_for_body {
    unless ( $opts{quiet} ) {
        print <<EOT;
Now you need to supply the bug report. Try to make the report concise
but descriptive. Include any relevant detail. If you are reporting
something that does not work as you think it should, please try to
include example of both the actual result, and what you expected.

Some information about your local parrot configuration will
automatically be included at the end of the report. If you are using
any unusual version of parrot, please try and confirm exactly which
versions are relevant.

EOT

        print "Press 'Enter' to continue...\n";
        scalar <STDIN>;
    }

    # Prompt for editor to use if none supplied.
    if ( $opts{editor} ) {
        $editor = $opts{editor};

    }
    else {
        ask_for_editor($opts{quiet} ? "" : <<EOT);
You will probably want to use an editor to enter the report. If the
default editor proposed below is the editor you want to use, then just
press the 'Enter' key, otherwise type in the name of the editor you
would like to use.
EOT
    }

    # Launch editor.
    $tmpfile = generate_filename();
    my $body = "";
    my $err = 0;
    do {
        edit_bug_report( $tmpfile );
        # Slurp bug report.
        open BODY, "<$tmpfile" or die "Can't open '$tmpfile': $!";
        {
            local $/;
            $body = <BODY>;
        }
        close BODY or die "Can't close '$tmpfile': $!";
        unless ( $body ) {
            print "\nYou provided an empty bug report!\n";
            print "Press 'Enter' to continue...\n";
            scalar <STDIN>;
        }
        die "Aborting.\n" if $err++ == 5;
    } until ( $body );

    return $body;
}


# Prompt for editor to use.
sub ask_for_editor {
    print shift() . "Editor [$editor]: ";
    my $entry = <STDIN>;
    chomp $entry;
    $editor = $entry if $entry ne "";
    $opts{editor} = $editor;
}


# Prompt for return address, return it.
sub ask_for_return_address {
    print <<EOT unless $opts{quiet};
Your e-mail address will be useful if you need to be contacted. If the
default shown below is not your full internet e-mail address, please
correct it.
EOT
    
    # Try and guess return address
    my ($from, $guess);
    $guess = $ENV{'REPLY-TO'} || $ENV{REPLYTO} || "";

    if ( ! $guess ) {
        # Use $domain if we can.
        if ( $domain ) {
            $guess = $is_vms && !$Config{d_socket} ?
              "$domain\:\:$user" : "$user\@$domain";
        }
    }

    # Verify our guess.
    print "Your address [$guess]: ";
    $from = <STDIN>;
    chomp $from;
    $from = $guess if $from eq "";
    print "\n\n\n";
    return $from;
}


# Prompt for summary of message.
#
# Return the summary chosen.
# 
# Die if more than 5 wrong summaries.
sub ask_for_summary {
    print <<EOT unless $opts{quiet};
First of all, please provide a summary for the message. It should be a
concise description of the bug or problem. "parrot bug" or "parrot
problem" is not a concise description.

EOT

    my $summary;
    my $err = 0;
    do {
        $err and print "\nThat doesn't look like a good summary. "
          . "Please be more verbose.\n";
        print "Summary: ";
        $summary = <STDIN>;
        $summary = q{} unless defined $summary;
        chomp $summary;
        die "Aborting.\n" if $err++ == 5;
    } while ( trivial_summary($summary) );
    print "\n\n\n";
    return $summary;
}


# Launch an editor in which to edit the bug report.
sub edit_bug_report {
    my $filename = shift;

    # Launch editor.
    my $retval;
    $retval = system($editor, $filename);

    # Check whether editor run was successful.
    die <<EOT if $retval;
The editor you chose ('$editor') could apparently not be run! Did you
mistype the name of your editor?

EOT

}



#------------------------------------------------------------#
#                        Action subs.                        #


# Display everything collected.
sub dump_report { 
    print "==> Dumping message...\n";
    my $report = format_message();

    if ( defined($ENV{PAGER}) ) {
        open(my $ofh, '|-', $ENV{PAGER});
        print {$ofh} $report;
        close $ofh;
    }
    else {
        print $report;
    }

}


# Last chance to edit report.
sub edit_report {
    # Prompt for editor to use if none supplied.
    unless ( $opts{editor} ) {
        ask_for_editor(<<EOT);
You will probably want to use an editor to modify the report. If the
default editor proposed below is the editor you want to use, then just
press the 'Enter' key, otherwise type in the name of the editor you
would like to use.
EOT
    }

    $tmpfile ||= $opts{input};
    my $err = 0;
    my $body;
    do {
        edit_bug_report( $tmpfile );
        # Slurp bug report.
        open my $BODY, '<', $tmpfile or die "Can't open '$tmpfile': $!";
        {
            local $/;
            $body = <$BODY>;
        }
        close $BODY or die "Can't close '$tmpfile': $!";
        unless ( $body ) {
            print "\nYou provided an empty bug report!\n";
            print "Press 'Enter' to continue...\n";
            scalar <STDIN>;
        }
        die "Aborting.\n" if $err++ == 5;
    } until ( $body );

    $report{body} = $body;
}

# Format the message with everything collected and return it.
sub format_message {
    my $report = "";

    # ... summary ...
    $report .= "Summary: $report{summary}\n";

    # ... sender ...
    $report .= "Reported by: $report{from}\n";

    # ... bug report ...
    $report .= "---\n$report{body}\n";

    # OS, arch, compiler...
    $report .= <<EOT;

---
osname= $Config{osname}
osvers= $Config{osvers}
arch=   $Config{archname}
EOT

    my $cc = $Config{cc};
    #$report .= "cc=     $cc $Config{${cc}.'version'}\n";
    $report .= "cc=     $cc\n";


    # ... flags...
    $report .= <<EOT;
---
Flags:
    category=$report{category}
    severity=$report{severity}
EOT
    $report .= "    ack=no\n" if ! $opts{ack};

    # ... myconfig ...
    $report .= "---\n$parrot{myconfig}\n---\n";

    # ... and environment.
    $report .= "Environment:\n";
    my @env = qw[ PATH LD_LIBRARY_PATH LANG SHELL HOME LOGDIR LANGUAGE ];
    push @env, $Config{ldlibpthname} if $Config{ldlibpthname} ne '';
    push @env, grep /^(?:PERL|LC_|LANG|CYGWIN)/, keys %ENV;
    my %env; 
    @env{@env} = @env;
    for my $env (sort keys %env) {
        my $env_value = exists $ENV{$env} ? "=$ENV{$env}\n" : " (unset)\n";
	$report .= "    $env $env_value";
    }

    return $report;
}


# Print synopsis + help message and exit.
sub help {
    print <<EOT;

A program to help generate bug reports about parrot, and mail them.
It is designed to be used interactively. Normally no arguments will
be needed.

Simplest usage:  run '$0', and follow the prompts.
Usage:           $0 [OPTIONS] [ACTIONS]

Options:
  --ok                   Report successful build on this system to parrot
                         developers. Only use --ok if *everything* was ok:
                         if there were *any* problems at all, use --nok.
  --nok                  Report unsuccessful build on this system.
  --summary <summary>    Summary to include with the message.
  --category <category>  Category of the bug report.
  --severity <severity>  Severity of the bug report.
  --from <address>       Your email address.
  --editor <editor>      Editor to use for editing the bug report.
  --ack, --noack         Don't send a bug received acknowledgement.
  --input-file           File containing the body of the report. Use this
                         to quickly send a prepared message.
  --output-file          File where parrotbug will save its bug report.

  Note: you will be prompted if the program miss some information.

Actions:
  --dump           Dump message.
  --save           Save message.
  --help           Print this help message and exit.
  --version        Print version information and exit.

EOT
    exit;
}

# Save message to file.
sub save_report {
    print "\n==> Saving message to file...\n";
    if ( ! $opts{output} ) {
        print "Enter filename to save bug report: ";
        chomp($opts{output} = <STDIN>);
    }

    open my $OUTPUT, ">", $opts{output}
        or die "Cannot open '$opts{output}': $!";
    print $OUTPUT format_message();
    close $OUTPUT or die "Cannot close '$opts{output}': $!";

    print <<TRAC;
Message saved. Please go to
  https://github.com/parrot/parrot/issues
  and paste content of saved file into 'Description'
TRAC
}



# Print version information (of the parrotbug program) and exit.
sub version {
    print <<"EOT";

This is $0, version $VERSION.

EOT
    exit;
}


# Check whether actions have been provided on comand-line, otherwise
# prompt for what to do with bug report.
sub what_next {
    dump_report() if $opts{dump};
    save_report() if $opts{save};
    return if $opts{dump} || $opts{save};

    # No actions provided on command-line, prompt for action.
    print describe_actions();

    my $action;
    do {
        print "Action (display,edit,save,quit): ";
        $action = <STDIN>;
       sw: for ($action) {
             dump_report(), last sw if /^d/i;
             edit_report(), last sw if /^e/i;
             save_report(), last sw if /^sa/i;
             print "Uh?\n" unless /^q/i;
         };
    } until ( $action =~ /^q/i );
}

sub describe_actions {
    my $str = <<ACTION;

Please choose among the following Actions:

display:
  Displays on STDOUT your bug report summary, bug description, 
  operating system information, bug report flags, summary of 
  your Parrot configuration and environment.  Returns you to 
  a new Action prompt.

edit:
  Opens your editor and permits you to edit the bug description.
  Returns you to a new Action prompt.

save:
  Prompts you to enter a filename to save the bug report.  Once
  the file has been saved, displays filing instructions, then
  returns you to a new Action prompt.

quit:
  Quits; returns you to your terminal's command prompt.

ACTION
    return $str;
}
__END__

=head1 NAME

Parrot Bug Reporter

=head1 SYNOPSIS

    % ./parrotbug [options] [actions]

=head1 DESCRIPTION

A program to help generate bug reports about parrot, and mail them.
It is designed to be used interactively. Normally no arguments will
be needed.


=head1 COMMAND-LINE SWITCHES


=head2 Options

Note: you will be prompted if the program miss some information.

=over 4

=item B<--nok>

Report unsuccessful build on this system to parrot developers.

=item B<--ok>

Report successful build on this system to parrot developers Only use
C<--ok> if B<everything> was ok; if there were B<any> problems at all,
use C<--nok>.

=item B<--summary>

Summary of the report. You will be prompted if you don't supply one on
the command-line.

=item B<--category>

Category of the bug report. You will be prompted if you don't supply
one on the command-line.

=item B<--severity>

Severity of the bug report. You will be prompted if you don't supply
one on the command-line.

=item B<--address>

Your email address. The program will try to guess one if you don't
provide one, but you'll still need to validate it.

=item B<--editor>

Editor to use for editing the bug report.

=item B<--output-file>

File where parrotbug will save its bug report, if you ask it to do so.

=back


=head2 Actions

You can provide more than one action on the command-line. If none is
supplied, then you will be prompted for what to do.

=over 4

=item B<--dump>

Dump formatted report on standard output.

=item B<--save>

Save message to a file, in order for you to send it later from your
own. See C<--output> flag.

=item B<--help>

Print a short synopsis and exit.

=item B<--version>

Print version information and exit.

=back


=head1 SEE ALSO

perlbug(1), parrot(1), diff(1), patch(1)

=cut

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4: