rewrite fixPaths()
now the phonon paths are actually normalized. just relying on File::Spec for the path relativization, so the code is much shorter. Change-Id: I69d6bac73e366ed0f754e1282a375871ce5559c4 Reviewed-by: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
This commit is contained in:
parent
800aef3424
commit
c98b223567
53
bin/syncqt
53
bin/syncqt
@ -47,6 +47,7 @@
|
|||||||
# use packages -------------------------------------------------------
|
# use packages -------------------------------------------------------
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use File::Path;
|
use File::Path;
|
||||||
|
use File::Spec;
|
||||||
use Cwd;
|
use Cwd;
|
||||||
use Cwd 'abs_path';
|
use Cwd 'abs_path';
|
||||||
use Config;
|
use Config;
|
||||||
@ -391,50 +392,20 @@ sub syncHeader {
|
|||||||
# Purpose: file is made relative (if possible) of dir.
|
# Purpose: file is made relative (if possible) of dir.
|
||||||
# Returns: String with the above applied conversion.
|
# Returns: String with the above applied conversion.
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
|
sub cleanupPath {
|
||||||
|
my ($file) = @_;
|
||||||
|
normalizePath(\$file);
|
||||||
|
while ($file =~ s,/[^/]+/\.\./,/,) {}
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
|
||||||
sub fixPaths {
|
sub fixPaths {
|
||||||
my ($file, $dir) = @_;
|
my ($file, $dir) = @_;
|
||||||
normalizePath(\$file);
|
|
||||||
normalizePath(\$dir);
|
|
||||||
|
|
||||||
#setup
|
my $out = File::Spec->abs2rel(cleanupPath($file), cleanupPath($dir));
|
||||||
my $ret = $file;
|
$out =~ s,\\,/,g;
|
||||||
$ret =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
|
return $out;
|
||||||
my $file_dir = dirname($file);
|
|
||||||
if($file_dir eq ".") {
|
|
||||||
$file_dir = getcwd();
|
|
||||||
normalizePath(\$file_dir);
|
|
||||||
}
|
|
||||||
$file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
|
|
||||||
if($dir eq ".") {
|
|
||||||
$dir = getcwd();
|
|
||||||
normalizePath(\$dir);
|
|
||||||
}
|
|
||||||
$dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
|
|
||||||
return basename($file) if($file_dir eq $dir);
|
|
||||||
|
|
||||||
#guts
|
|
||||||
while ($file_dir =~ s,/[^/]+/\.\./,/,) {}
|
|
||||||
while ($dir =~ s,/[^/]+/\.\./,/,) {}
|
|
||||||
my $match_dir = 0;
|
|
||||||
for(my $i = 1; $i < length($file_dir); $i++) {
|
|
||||||
my $slash = index($file_dir, "/", $i);
|
|
||||||
last if($slash == -1);
|
|
||||||
my $tmp = substr($file_dir, 0, $slash);
|
|
||||||
last unless($dir =~ m,^\Q$tmp\E/,);
|
|
||||||
$match_dir = $tmp;
|
|
||||||
$i = $slash;
|
|
||||||
}
|
|
||||||
if($match_dir) {
|
|
||||||
my $after = substr($dir, length($match_dir));
|
|
||||||
my $count = ($after =~ tr,/,,);
|
|
||||||
my $dots = "";
|
|
||||||
for(my $i = 0; $i < $count; $i++) {
|
|
||||||
$dots .= "../";
|
|
||||||
}
|
|
||||||
$ret =~ s,^\Q$match_dir\E,$dots,;
|
|
||||||
}
|
|
||||||
$ret =~ s,/+,/,g;
|
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user