# ========== Copyright Header Begin ==========================================
# OpenSPARC T2 Processor File: Paths.pm
# Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
# 4150 Network Circle, Santa Clara, California 95054, U.S.A.
# * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# For the avoidance of doubt, and except that if any non-GPL license
# choice is available it will apply instead, Sun elects to use only
# the General Public License version 2 (GPLv2) at this time for any
# software where a choice of GPL license versions is made
# available with the language indicating that GPLv2 or any later version
# may be used, or where a choice of which version of the GPL is applied is
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# ========== Copyright Header End ============================================
our @EXPORT = qw(cd compact_path full_path
##############################################################################
# Note this function is not at all robust. Should work on that
my $canon_dir1 = File
::Spec
->canonpath(File
::Spec
->rel2abs($dir1));
my $canon_dir2 = File
::Spec
->canonpath(File
::Spec
->rel2abs($dir2));
return ($canon_dir1 eq $canon_dir2);
##############################################################################
# ACTUALLY A CLASS METHOD
if(not are_dirs_same
($dir, getcwd
)) {
##############################################################################
# Not for public consumption
return unless defined $this->{old
};
cd
(compact_path
($this->{old
}));
##############################################################################
##############################################################################
return $$Full_paths if ref $Full_paths;
##############################################################################
foreach my $key (keys %args) {
if($key eq 'full_paths') {
$Full_paths = $args{$key};
fatal
"Midas::Paths does not recongnize configuration option ".
return ( full_paths
=> opt_full_paths
);
##############################################################################
# Converts to full or relative (to $relto or cwd) path, whichever is shorter.
# If Full_Paths is enabled, then always return full path.
##############################################################################
$relto = getcwd
unless defined $relto;
my $abs = File
::Spec
->rel2abs($path, $relto);
my $rel = File
::Spec
->abs2rel($abs, $relto);
my $compact = ((length $rel) < (length $abs)) ?
$rel : $abs;
$compact = '.' if length($compact) == 0;
return opt_full_paths
() ?
$abs : $compact;
##############################################################################
$relto = getcwd
unless defined $relto;
my $abs = File
::Spec
->rel2abs($path, $relto);
##############################################################################
$dir = File
::Spec
->rel2abs($dir);
chdir $dir or fatal
"Can't cd to $dir: $!\n", M_DIR
;
##############################################################################
# Get filename. $file argument is a full path or a path relative to
# build_dir. Second argument defines build_dir. If no second
# argument, assume build_dir is cwd. If it's a string, assume the
# string is build_dir. If it's a reference, assume it's a
# Midas::State object. Return value is the compact path to the file.
##############################################################################
my $arg = shift; # either build_dir or state object or undef for build=cwd
# Do the require at this late date so as to not mess up exports
# (this is a circular include).
$build_dir = $state->get_build_dir('-abs');
$expanded_file = File
::Spec
->rel2abs($file, $build_dir);
return compact_path
$expanded_file;
##############################################################################
##############################################################################