You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2014/08/13 04:03:04 UTC

[5/6] git commit: Adapt Lucy's update_version tool for Clownfish.

Adapt Lucy's update_version tool for Clownfish.


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/4f91b05c
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/4f91b05c
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/4f91b05c

Branch: refs/heads/prep_0.4.0
Commit: 4f91b05c60e0c137206e9c81e9e8f99a5937f12e
Parents: 1bf6b4e
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Aug 12 18:19:09 2014 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Aug 12 19:01:21 2014 -0700

----------------------------------------------------------------------
 devel/bin/update_version | 182 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 182 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/4f91b05c/devel/bin/update_version
----------------------------------------------------------------------
diff --git a/devel/bin/update_version b/devel/bin/update_version
new file mode 100755
index 0000000..6df87b6
--- /dev/null
+++ b/devel/bin/update_version
@@ -0,0 +1,182 @@
+#!/usr/bin/env perl
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use strict;
+use warnings;
+use FindBin qw( $Bin );
+use File::Find;
+
+# make sure we are at the top-level dir
+chdir("$Bin/../../");
+
+my $usage = "$0 version\n";
+my $version = shift(@ARGV) or die $usage;
+
+# standardize version strings
+my ( $x, $y, $z );
+if ( $version =~ m/^(\d+)\.(\d+)\.(\d+)$/ ) {
+    ( $x, $y, $z ) = ( $1, $2, $3 );
+}
+elsif ( $version =~ m/^(\d+)\.(\d\d\d)(\d\d\d)$/ ) {
+    ( $x, $y, $z ) = ( int($1), int($2), int($3) );
+}
+else {
+    die "Unknown version syntax. Try X.Y.Z or X.YYYZZZ\n";
+}
+my $x_y_z_version    = sprintf( "%d.%d.%d",    $x, $y, $z );
+my $x_yyyzzz_version = sprintf( "%d.%03d%03d", $x, $y, $z );
+
+print "Using version: $x_y_z_version ( $x_yyyzzz_version )\n";
+
+my $buf;
+
+# Update charmonizer.
+for my $path ('runtime/common/charmonizer.c', 'runtime/common/charmonizer.main') {
+    $buf = read_file($path);
+    $buf =~ s/(cfish_version\[\]\s+=\s+)"[\d.]+"/$1"$x_y_z_version"/
+        or die "no match";
+    $buf =~ s/(cfish_major_version\[\]\s+=\s+)"[\d.]+"/$1"$x_y_z_version"/
+        or die "no match";
+    write_file($path, $buf);
+}
+
+# Update CFC.pm.
+$buf = read_file('compiler/perl/lib/Clownfish/CFC.pm');
+$buf =~ s/(our \$VERSION\ +=\ +)'.+?'/$1'$x_yyyzzz_version'/g
+    or die "no match";
+$buf =~ s/XSLoader::load\( 'Clownfish::CFC', '(.+?)'/XSLoader::load\( 'Clownfish::CFC', '$x_y_z_version'/
+    or die "no match";
+write_file( 'compiler/perl/lib/Clownfish/CFC.pm', $buf );
+
+# Update Clownfish.pm.
+$buf = read_file('runtime/perl/lib/Clownfish.pm');
+$buf =~ s/(our \$VERSION\ +=\ +)'.+?'/$1'$x_yyyzzz_version'/g
+    or die "no match";
+$buf =~ s/(bootstrap Clownfish ')(.+?)'/$1$x_y_z_version'/
+    or die "no match";
+$buf =~ s/^\d+\.\d+\.\d+\b$/$x_y_z_version/m
+    or die "no match";
+write_file( 'runtime/perl/lib/Clownfish.pm', $buf );
+
+# Update Clownfish.pod.
+$buf = read_file('runtime/perl/lib/Clownfish.pod');
+$buf =~ s/(^=head1\s+VERSION\s+)([\d.]+)/$1$x_y_z_version/m
+    or die "no match";
+write_file( 'runtime/perl/lib/Clownfish.pod', $buf );
+
+# Update runtime Build.PL
+$buf = read_file('runtime/perl/Build.PL');
+$buf =~ s/(dist_version\ +=>\ +)'.+?'/$1'$x_y_z_version'/
+    or die "no match";
+$buf =~ s/(Clownfish::CFC::Perl::Build'\s*=>\s*)(.*?),/$1$x_yyyzzz_version,/g
+    or die "no match";
+$buf =~ s/(Clownfish::CFC'\s*=>\s*)(.*?),/$1$x_yyyzzz_version,/g
+    or die "no match";
+write_file( 'runtime/perl/Build.PL', $buf );
+
+# Update runtime/c/install.sh
+$buf = read_file('runtime/c/install.sh');
+$buf =~ s/\bversion=[\d.]+/version=$x_y_z_version/
+    or die "no match";
+$buf =~ s/\bmajor_version=[\d.]+/major_version=$x.$y/
+    or die "no match";
+write_file( 'runtime/c/install.sh', $buf );
+
+# Update compiler/python/setup.py
+$buf = read_file('compiler/python/setup.py');
+$buf =~ s/(\bversion\s+=\s+)'[\d.]+'/$1'$x_y_z_version/
+    or die "no match";
+write_file( 'compiler/python/setup.py', $buf );
+
+# Update POD in compiler/perl/lib/Clownfish/CFC/Perl/Build.pm
+$buf = read_file('compiler/perl/lib/Clownfish/CFC/Perl/Build.pm');
+$buf =~ s/(Clownfish::CFC::Perl::Build'\s*=>\s*)(.*?),/$1$x_yyyzzz_version,/g
+    or die "no match";
+write_file( 'compiler/perl/lib/Clownfish/CFC/Perl/Build.pm', $buf );
+
+# Update Clownfish.cfp.
+$buf = read_file('runtime/core/Clownfish.cfp');
+$buf =~ s/("version":\s+)"v\d+\.\d+\.\d+"/$1"v$x_y_z_version"/
+    or die "no match";
+write_file( 'runtime/core/Clownfish.cfp', $buf );
+
+# Update runtime/core/TestClownfish.cfp
+$buf = read_file('runtime/core/TestClownfish.cfp');
+$buf =~ s/("version":\s+)"v\d+\.\d+\.\d+"/$1"v$x_y_z_version"/
+    or die "no match";
+$buf =~ s/("Clownfish":\s+)"v\d+\.\d+\.\d+"/$1"v$x_y_z_version"/
+    or die "no match";
+write_file( 'runtime/core/TestClownfish.cfp', $buf );
+
+# Update all other Perl modules.
+find(\&update_pm_file, 'compiler/perl');
+find(\&update_pm_file, 'runtime/perl');
+
+sub update_pm_file {
+    return unless /[.]pm$/;
+    my $name = $_;
+    return if $name eq 'Clownfish.pm';
+    return if $name eq 'CFC.pm';
+    my $buf = read_file($name);
+    $buf =~ s/(our \$VERSION\ +=\ +)'.+?'/$1'$x_yyyzzz_version'/g
+        or die "no match in $File::Find::name";
+    write_file($name, $buf);
+}
+
+# utility functions
+sub read_file {
+    my ($file) = @_;
+    local $/;
+    open( F, "< $file" ) or die "Cannot read $file: $!\n";
+    my $buf = <F>;
+    close(F) or die "Cannot close $file: $!\n";
+    return $buf;
+}
+
+sub write_file {
+    my ( $file, $buf ) = @_;
+    open( F, "> $file" ) or die "Cannot write $file: $!\n";
+    print F $buf;
+    close(F) or die "Cannot close $file: $!\n";
+}
+
+print "Done.  Consider running git grep for the old version.\n";
+exit();
+
+__END__
+
+=head1 NAME
+
+update_version - update Clownfish version strings in source files
+
+=head1 SYNOPSIS
+
+ perl devel/bin/update_version version
+
+=head1 DESCRIPTION
+
+Updates key source files with I<version>, using correct syntax
+depending on the file format and type.
+
+I<version> may be specified in either format:
+
+ X.Y.Z
+ X.YYYZZZ
+
+and update_version will convert the specified string into the 
+correct format for each relevant file.
+
+=cut