bump-version 2.58 KB
Newer Older
1 2 3
#! /usr/bin/env perl

use FindBin;
Robert Goldman's avatar
Robert Goldman committed
4
use Getopt::Long;
5 6
our $old;
our $new;
Robert Goldman's avatar
Robert Goldman committed
7 8 9 10 11 12 13 14 15 16 17 18
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;
}
19 20 21 22 23 24 25

our $asdf_dir = $FindBin::RealBin . "/../";
our $file = $asdf_dir . "version.lisp-expr";

our @transform_ref =
  (
   [ "version.lisp-expr", "\"", "\"" ],
26
   [ "uiop/version.lisp", "(defparameter *uiop-version* \"", "\")" ],
27 28
   [ "asdf.asd", "  :version \"", "\" ;; to be automatically updated by make bump-version" ],
   [ "header.lisp", "This is ASDF ", ": Another System Definition Facility." ],
29
   [ "upgrade.lisp", "(asdf-version \"", "\")" ],
30 31
   [ "doc/asdf.texinfo", "Manual for Version ", "" ], );

Robert Goldman's avatar
Robert Goldman committed
32 33 34 35 36
if ($#ARGV == 1) {
  $old = $ARGV[0];
  $new = $ARGV[1];
} elsif ($#ARGV == 0) {
  $new = $ARGV[0];
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
  $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";
70
    my $regex = "(" . quotemeta($entry[1]) . ")" . "((\\d+\\.)+\\d+)" . "(" . quotemeta($entry[2]) .")";
71 72
    my $filename = $asdf_dir . $file;
    my $data = read_text($filename);
73
    my $count = ($data =~ s/$regex/$1$new$4/g);
74 75 76 77
    if ($count == 0) {
      die "Unable to replace $regex with $1$new$4";
    }
    # print STDERR "Writing $data to $filename\n";
78 79 80 81
    write_text($filename, $data);

  }
}
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

# 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;
}