Insert Subversion revision number in Xcode

后端 未结 7 1621
花落未央
花落未央 2020-11-30 18:29

I would like to insert the current Subversion revision number (as reported by svnversion) into my Xcode project. I managed to insert the revision number into th

7条回答
  •  粉色の甜心
    2020-11-30 19:05

    # Xcode auto-versioning script for Subversion
    # by Axel Andersson, modified by Daniel Jalkut to add
    # "--revision HEAD" to the svn info line, which allows
    # the latest revision to always be used.
    #
    # modified by JM Marino to change only [BUILD] motif
    # into CFBundleGetInfoString key.
    #
    # HOW TO USE IT: just add [BUILD] motif to your Info.plist key :
    #       CFBundleVersion
    #
    # EXAMPLE: version 1.3.0 copyright 2003-2009 by JM Marino
    # with [BUILD] into CFBundleVersion key
    
    use strict;
    
    die "$0: Must be run from Xcode" unless $ENV{"BUILT_PRODUCTS_DIR"};
    
    # Get the current subversion revision number and use it to set the CFBundleVersion value
    #my $REV = `/usr/local/bin/svnversion -n ./`;
    my $REV = `/usr/bin/svnversion -n ./`;
    my $INFO = "$ENV{BUILT_PRODUCTS_DIR}/$ENV{WRAPPER_NAME}/Contents/Info.plist";
    
    my $version = $REV;
    
    # (Match the last group of digits without optional letter M | S):
    ($version =~ m/(\d+)[MS]*$/) && ($version = "" . $1);
    
    die "$0: No Subversion revision found" unless $version;
    
    open(FH, "$INFO") or die "$0: $INFO: $!";
    my $info = join("", );
    close(FH);
    
    #$info =~ s/([\t ]+CFBundleVersion<\/key>\n[\t ]+.+)\[BUILD\](<\/string>)/$1$version$2/;
    $info =~ s/([\t ]+CFBundleVersion<\/key>\n[\t ]+)\[BUILD\](<\/string>)/$1$version$2/;
    
    open(FH, ">$INFO") or die "$0: $INFO: $!";
    print FH $info;
    close(FH);
    

提交回复
热议问题