-
Notifications
You must be signed in to change notification settings - Fork 5
/
bump-version
executable file
·102 lines (88 loc) · 2.58 KB
/
bump-version
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
#! /usr/bin/env perl
use FindBin;
use Getopt::Long;
our $old;
our $new;
our $usage = 0;
&GetOptions("help"=>\$usage,
"usage"=>\$usage);
if ($usage) {
print "$0 [old-version] [new-version]\n";
print "\tIf only one argument, treat it as the new version argument.\n";
print "\tIf two arguments treat the first as old version number and second as new.\n";
print "\n\tBumps the version numbers in all the relevant files.\n";
exit 0;
}
our $asdf_dir = $FindBin::RealBin . "/../";
our $file = $asdf_dir . "version.lisp-expr";
our @transform_ref =
(
[ "version.lisp-expr", "\"", "\"" ],
[ "uiop/version.lisp", "(defparameter *uiop-version* \"", "\")" ],
[ "asdf.asd", " :version \"", "\" ;; to be automatically updated by make bump-version" ],
[ "header.lisp", "This is ASDF ", ": Another System Definition Facility." ],
[ "upgrade.lisp", "(asdf-version \"", "\")" ],
[ "doc/asdf.texinfo", "Manual for Version ", "" ], );
if ($#ARGV == 1) {
$old = $ARGV[0];
$new = $ARGV[1];
} elsif ($#ARGV == 0) {
$new = $ARGV[0];
$old = read_asdf_version();
} else {
$old = read_asdf_version();
$new = bump_asdf_version($old);
}
print STDERR "Bumping from $old to $new\n";
transform_files();
sub read_asdf_version {
open(FILE, $file);
my $str = <FILE>;
chomp $str;
print STDERR "Read version string $str from $file\n";
close FILE;
$str =~ s/"//g;
return $str;
}
sub bump_asdf_version {
my $oldver = shift;
my @fields = split/\./, $oldver;
$fields[$#fields]++;
return join('.', @fields);
}
sub transform_files {
foreach my $entryptr (@transform_ref) {
my @entry = @{$entryptr};
my $file = $entry[0];
print STDERR "Modifying file $file\n";
print STDERR "Prefix is $entry[1], suffix is $entry[2]\n";
my $regex = "(" . quotemeta($entry[1]) . ")" . "((\\d+\\.)+\\d+)" . "(" . quotemeta($entry[2]) .")";
my $filename = $asdf_dir . $file;
my $data = read_text($filename);
my $count = ($data =~ s/$regex/$1$new$4/g);
if ($count == 0) {
die "Unable to replace $regex with $1$new$4";
}
# print STDERR "Writing $data to $filename\n";
write_text($filename, $data);
}
}
# can't reliably find File::Slurper, or File::Slurp, so do it
# old school.
sub read_text ($) {
my $fn = shift;
local $/ = undef;
open READFILE, $fn or die "Couldn't open file: $fn";
binmode READFILE;
my $string = <READFILE>;
close READFILE;
return $string;
}
sub write_text ($$) {
my $fn = shift;
my $data = shift;
open WRITEFILE, "> $fn" or die "Couldn't open $fn for writing.";
print WRITEFILE $data;
close WRITEFILE;
return 1;
}