File: add_version

package info (click to toggle)
perl-tk 1:804.033-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 34,724 kB
  • ctags: 37,174
  • sloc: ansic: 349,541; perl: 52,192; sh: 17,904; makefile: 5,732; asm: 3,565; ada: 1,681; pascal: 1,089; cpp: 1,006; yacc: 883; cs: 879
file content (160 lines) | stat: -rwxr-xr-x 2,865 bytes parent folder | download | duplicates (7)
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
#!/usr/local/bin/perl -w
use strict;
use File::Find;
use Getopt::Std;
use Cwd;
my %opt = ('p' => '4');
getopts('oqeap:',\%opt);
my $path = getcwd();
chdir($path);
$path = getcwd();
my $dep;
my $rel;
my ($wh) = `p4 where ./...`;

if ($wh =~ m#^\s*(.*)/\.\.\.\s+(.*)/\.\.\.\s*$#)
 {
  $dep  = $1;
  $rel  = $2;
 }
else
 {
  die $wh;
 }

if ($opt{'o'})
 {
  foreach (`p4 opened $path/...`)
   {
    unless (/\(kx?text\)/)
     {
      warn "Not ktext : $_";
      next;
     }
    chomp;
    s/#\d+\s+-.*$//;
    $_ = `p4 have $_`;
    s/^.*#\d+\s+-\s+//;
    chomp;
    print "'$_'\n";
    push(@ARGV,$_);
   }
 }
elsif ($opt{'a'})
 {
  find(sub
       {
        $File::Find::prune = 1 if (/^blib$/);
        push(@ARGV,$File::Find::name) if (/\.pm$/)
       },'.');
 }

@ARGV = grep(!m#(Tk|Config)\.pm$#,@ARGV);

unless (@ARGV)
 {
  warn "No files specified\n";
  exit;
 }

my @undo = ();

sub VERSION
{
 my $have = `p4 have $ARGV`;
 my ($path,$need)  = $have =~ /^(.*#(\d+))\s+-/;
 $need++ if (-w $ARGV);
 return ($need,sprintf "\$VERSION = sprintf '%d.%%03d', q\$Revision: #%d\$ =~ /\\D(\\d+)\\s*\$/;\n",$opt{'p'},$need);
}


$^I = ".old" if $opt{'e'};
my $seen = 0;
my $edit = 0;
while (<>)
 {
  $edit |= s/\r//g;
  s/ +$//;
  if (/^\s*\$VERSION\s*=\s*'(\d+)\.0*(\d+)'\s*;\s*#\s*\$Id[:\s]+(.*)\$\s*(?:\+(\d+))?.*$/)
   {
    $seen = 1;
    my $have = $2;
    my ($want,$str) = VERSION();
    if ($opt{q} && $have ne $want)
     {
      warn "!$ARGV:$have ne $want\n";
      warn "-$ARGV:$_";
      $_ = $str;
      warn "+$ARGV:$_";
      $edit = 1;
     }
   }
  elsif (/^\s*(our\s+)?\$VERSION\s*=[^#]*\$Revision[:\s]+#(\d+)\s*\$/)
   {
    $seen = 1;
    my $have = $2;
    my ($want,$str) = VERSION();
    if ($have ne $want)
     {
      warn "-$ARGV:$_";
      $_ = $str;
      warn "+$ARGV:$_";
      $edit = 1;
     }
   }
  elsif (/\$[\w:]*\bVERSION\s*=/)
   {
    if ($seen == 1)
     {
      warn "DUPLICATE $ARGV already had $_";
     }
   }
  elsif (/\$(Id|Revision):/ || m#//depot#)
   {
    warn "Did not match:$_";
   }
  elsif (!$seen && /^\s*(\@ISA|bootstrap|use\s+(Tk)|sub)/)
   {
    warn "$ARGV:$.:insert before\n$_\n";
    print "\nuse vars qw(\$VERSION);\n";
    my ($want,$str) = VERSION();
    print  $str;
    $seen = $edit = 1;
   }
  print if $opt{'e'};;
  if (!$seen && (eof || /__END__/))
   {
    warn "No insert point found in $ARGV\n";
    $seen = 1;
   }
  if (eof)
   {
    if ($opt{'e'})
     {
      if ($edit && $opt{'e'})
       {
        system('p4','edit','-t','ktext',$ARGV) unless -w $ARGV;
       }
      else
       {
        push(@undo,$ARGV);
       }
     }
    else
     {
      if ($edit)
       {
        warn "$ARGV needs changing?\n";
       }
     }
    $seen = $edit = 0;
    $.    = 0;
   }
 }

foreach my $file (@undo)
 {
  chmod(0666,$file) unless -w $file;
  unlink($file);
  rename("$file$^I",$file);
 }