-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplease.pl
More file actions
170 lines (145 loc) · 4.18 KB
/
please.pl
File metadata and controls
170 lines (145 loc) · 4.18 KB
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
#!/usr/bin/perl
# perl compiler wrapper and release
# perl release manager
##Built on __HOST__ from __FILE__ __TIMESTAMP__ git version v1.__VER__
# replace __DATA__ __PACKAGE__ __TIMESTAMPE__ etc to actual
# put version info between @BEGING @END Lines
# call pp and pipe the replace doce there but with the same name, then pp, create binary
# copy bingary to OneDrive:xor
use File::Basename;
use Getopt::Long;
use POSIX qw(strftime);
use Sys::Hostname;
my $datm = strftime "%a %b %e %H:%M:%S %Y", localtime;
$input="";
$output="";
$compile=1;
$inext="";
$commit=0;
$verbose=0;
$usage=""; ## extract {__USAGE__ to __USAGE__}
GetOptions (
"commit" => \$commit, # commit the generated pl file.
"verbose" => \$verbose,
"input=s" => \$input, # show more info;
"output=s" => \$output # numeric
); # flag
if($input eq "" ) {
print <<FOO;
__<USAGE__
__EXE__ is for perl release management
__EXE__ -i <file>.pl
It will compile <file>.pl to <file> and update <file>.readme to <file>.readme.txt as release notes.
##Built on __HOST__ from __FILE__ __TIMESTAMP__ git version v1.__VER__
__USAGE>__
FOO
exit;
}
# __<IGNORE__ begin to ignore conversion
($ifile,$idir,$iext) = fileparse($input, qr/\.[^.]*/);
# dir="/usr/local/src/" file="perl-5.6.1.tar" ext=".gz"
if($output eq "") {
$output=$input;
if (".pl" eq $iext) {
$output=~ s/\.pl/.o.pl/; # each ext handle differently
}
}
$inbase=basename($input);
$indir=dirname($input);
$outbase=basename($output);
$outdir=dirname($output);
my $ver=qx(cd $indir; git rev-list --count --first-parent HEAD $inbase);
chomp($ver);
$host=hostname;
$gitlog=0;
Please($input, $output, $commit, $compile);
my $readme="$idir$ifile.readme";
if (-e $readme) {
print "Updating $readme.txt with logs\n";
Please("$readme", "$readme.txt", $commit, 0); #not compile for readme
}
exit;
sub Please() {
my ($input, $output, $commit, $compile) = @_;
open(IN, '<', $input) or die $!;
open(OUT,'>', $output) or die $!;
my $usagemode=0;
my $gitlog=0;
my $ignoretags=0;
my $ignore="IG"."NORE"; #make sure won't match IGNORE :-)
while(<IN>)
{
if( index($_, "__<".$ignore."__")>=0){
$ignoretags=1;
}
if( index($_, "__".$ignore.">__")>=0){
$ignoretags=0;
}
if(!$ignoretags) {
$_ =~ s/__TIMESTAMP__/$datm/g;
$_ =~ s/__FILE__/$input/g;
$_ =~ s/__SOURCE__/$idir$ifile$iext/g;
$_ =~ s/__EXE__/$idir$ifile/g;
$_ =~ s/__HOST__/$host/g;
if ($_ =~ "__VER__") {
$_ =~ s/__VER__/$ver/g;
printf "ver=$ver line=\n$_\n" if $verbose;
}
if( $_ =~ m/__<GITLOG__/ ){
$gitlog=1;
print "begin log\n" if $verbose;
#get all git logs and skip old to __GITLOGEND__
open LOG, "(cd $indir; git log --date=iso --pretty=format:\"#Log %ad : %s\" $inbase ) |";
while (<LOG>) {
print OUT $_;
}
print OUT "\n";
close LOG;
next; # don't put tag in result
}
if ($_ =~ m/__GITLOG>__/) { #end log
$gitlog=0;
print "end of log\n" if $verbose;
next; # don't put tag in result
}
if ($compile) { #process source file, to read usage
if( $_ =~ m/__<USAGE__/ && !$usagemode){
$usagemode=1;
next; #don't put tag in result
}
if( $_ =~ m/__USAGE>__/) {
$usagemode=0;
next; #don't put tag in result
}
$usage = "$usage$_" if ($usagemode); # put all usage in buffer;
} else { #in readme file
if( $_ =~ m/__<USAGE__/ && !$usagemode){
$usagemode=1;
print OUT $usage;
next; # don't put tag in result
}
if( $_ =~ m/__USAGE>__/) {
$usagemode=0;
next; # don't put tag in result
}
}
}
print OUT $_ if (!$gitlog);
}
close(IN);
close(OUT);
### The following should be kept
###Built on __HOST__ from __FILE__ __TIMESTAMP__ git version v1.__VER__
if (".pl" eq $iext && $compile) {
my $outbin= "$idir$ifile";
# $outbin =~ s/\.pl//;
printf ("compiling to $output to $outbin\n");
system("pp $output -o $outbin");
}
if ($commit) {
$cmd="cd $outdir; git add $outbase; git commit -m \"Created by Please.pl and compiled on $datm source\" $outbase";
system($cmd);
}
}
# __IGNORE>__
#Built on __HOST__ from __FILE__ __TIMESTAMP__ git version v1.__VER__