build/unix/abs2rel.pl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/unix/abs2rel.pl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,35 @@
     1.4 +#!env perl
     1.5 +
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +use File::Spec::Unix;
    1.11 +use strict;
    1.12 +
    1.13 +print "Usage: $0 dest_path start_path\n" if ($#ARGV+1 != 2);
    1.14 +my $finish = my_canonpath(shift);
    1.15 +my $start = my_canonpath(shift);
    1.16 +
    1.17 +my $res = File::Spec::Unix->abs2rel($finish, $start);
    1.18 +
    1.19 +#print STDERR "abs2rel($finish,$start) = $res\n";
    1.20 +print "$res\n";
    1.21 +
    1.22 +sub my_canonpath($) {
    1.23 +    my ($file) = @_;
    1.24 +    my (@inlist, @outlist, $dir);
    1.25 +
    1.26 +    # Do what File::Spec::Unix->no_upwards should do
    1.27 +    my @inlist = split(/\//, File::Spec::Unix->canonpath($file));
    1.28 +    foreach $dir (@inlist) {
    1.29 +	if ($dir eq '..') {
    1.30 +	    pop @outlist;
    1.31 +	} else {
    1.32 +	    push @outlist, $dir;
    1.33 +	}
    1.34 +    }
    1.35 +    $file = join '/',@outlist;
    1.36 +    return $file;
    1.37 +}
    1.38 +

mercurial