#! /usr/bin/perl -w
## $Id: output-versions.pl 224 2011-08-13 20:39:45Z stuart $
##
## Author: Stuart Connolly (stuconnolly.com)
## Copyright (c) 2011 Stuart Connolly. All rights reserved.
##
## Paramters: $1 -- The file path to which the versions are to be written to.
## $2 -- The path of the 'Info.plist' file from which the versions should be extracted from.
##
## Description: Extracts the CFBundleVersion and CFBundleShortVersionString from the supplied Info.plist file and writes
## them to the supplied file path.
use strict;
my $info_plist = $ARGV[0];
my $versions_file = $ARGV[1];
open(INFO_FH
, "<$info_plist");
my $info = join("", <INFO_FH>);
my $version_string = 0;
my $bundle_version = 0;
# Version string
($info =~ m/[\t ]+<key>CFBundleShortVersionString<\/key>\n[\t ]+<string>([0-9.]+)<\/string>/) && ($version_string = $1);
# Bundle version
($info =~ m/[\t ]+<key>CFBundleVersion<\/key>\n[\t ]+<string>(\d+)<\/string>/) && ($bundle_version = $1);
# Write versions to file
open(VERSIONS_FH
, ">$versions_file");
print VERSIONS_FH
"${version_string}:${bundle_version}\n";