-# Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
+# Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
use File::Copy;
use File::Spec::Functions qw/file_name_is_absolute curdir canonpath splitdir
- catdir catfile splitpath catpath devnull abs2rel
- rel2abs/;
+ catdir catfile splitpath catpath devnull abs2rel/;
use File::Path 2.00 qw/rmtree mkpath/;
use File::Basename;
use Cwd qw/getcwd abs_path/;
rmtree($directories{RESULTS}, { safe => 0, keep_root => 1 });
mkpath($directories{RESULTS});
+ # All directories are assumed to exist, except for SRCDATA. If that one
+ # doesn't exist, just drop it.
+ delete $directories{SRCDATA} unless -d $directories{SRCDATA};
+
push @direnv, "TOP" if $ENV{TOP};
push @direnv, "SRCTOP" if $ENV{SRCTOP};
push @direnv, "BLDTOP" if $ENV{BLDTOP};
sub __data_file {
BAIL_OUT("Must run setup() first") if (! $test_name);
+ return undef unless exists $directories{SRCDATA};
+
my $f = pop;
return catfile($directories{SRCDATA},@_,$f);
}
sub __data_dir {
BAIL_OUT("Must run setup() first") if (! $test_name);
+ return undef unless exists $directories{SRCDATA};
+
return catdir($directories{SRCDATA},@_);
}
sub __cwd {
my $dir = catdir(shift);
my %opts = @_;
- my $abscurdir = rel2abs(curdir());
- my $absdir = rel2abs($dir);
+
+ # If the directory is to be created, we must do that before using
+ # abs_path().
+ $dir = canonpath($dir);
+ if ($opts{create}) {
+ mkpath($dir);
+ }
+
+ my $abscurdir = abs_path(curdir());
+ my $absdir = abs_path($dir);
my $reverse = abs2rel($abscurdir, $absdir);
# PARANOIA: if we're not moving anywhere, we do nothing more
# In this case, we won't even clean it out, for safety's sake.
return "." if $reverse eq "";
- $dir = canonpath($dir);
- if ($opts{create}) {
- mkpath($dir);
- }
-
# We are recalculating the directories we keep track of, but need to save
# away the result for after having moved into the new directory.
my %tmp_directories = ();
my @dirtags = sort keys %directories;
foreach (@dirtags) {
if (!file_name_is_absolute($directories{$_})) {
- my $newpath = abs2rel(rel2abs($directories{$_}), rel2abs($dir));
+ my $oldpath = abs_path($directories{$_});
+ my $newpath = abs2rel($oldpath, $absdir);
+ if ($debug) {
+ print STDERR "DEBUG: [dir $_] old path: $oldpath\n";
+ print STDERR "DEBUG: [dir $_] new base: $absdir\n";
+ print STDERR "DEBUG: [dir $_] resulting new path: $newpath\n";
+ }
$tmp_directories{$_} = $newpath;
}
}
# process can use their values properly as well
foreach (@direnv) {
if (!file_name_is_absolute($ENV{$_})) {
- my $newpath = abs2rel(rel2abs($ENV{$_}), rel2abs($dir));
+ my $oldpath = abs_path($ENV{$_});
+ my $newpath = abs2rel($oldpath, $absdir);
+ if ($debug) {
+ print STDERR "DEBUG: [env $_] old path: $oldpath\n";
+ print STDERR "DEBUG: [env $_] new base: $absdir\n";
+ print STDERR "DEBUG: [env $_] resulting new path: $newpath\n";
+ }
$tmp_ENV{$_} = $newpath;
}
}
if ($debug) {
print STDERR "DEBUG: __cwd(), directories and files:\n";
- print STDERR " \$directories{BLDTEST} = \"$directories{BLDTEST}\"\n";
- print STDERR " \$directories{SRCTEST} = \"$directories{SRCTEST}\"\n";
- print STDERR " \$directories{SRCDATA} = \"$directories{SRCDATA}\"\n";
- print STDERR " \$directories{RESULTS} = \"$directories{RESULTS}\"\n";
- print STDERR " \$directories{BLDAPPS} = \"$directories{BLDAPPS}\"\n";
- print STDERR " \$directories{SRCAPPS} = \"$directories{SRCAPPS}\"\n";
- print STDERR " \$directories{SRCTOP} = \"$directories{SRCTOP}\"\n";
- print STDERR " \$directories{BLDTOP} = \"$directories{BLDTOP}\"\n";
+ print STDERR " Moving from $abscurdir\n";
+ print STDERR " Moving to $absdir\n";
+ print STDERR "\n";
+ print STDERR " \$directories{BLDTEST} = \"$directories{BLDTEST}\"\n";
+ print STDERR " \$directories{SRCTEST} = \"$directories{SRCTEST}\"\n";
+ print STDERR " \$directories{SRCDATA} = \"$directories{SRCDATA}\"\n"
+ if exists $directories{SRCDATA};
+ print STDERR " \$directories{RESULTS} = \"$directories{RESULTS}\"\n";
+ print STDERR " \$directories{BLDAPPS} = \"$directories{BLDAPPS}\"\n";
+ print STDERR " \$directories{SRCAPPS} = \"$directories{SRCAPPS}\"\n";
+ print STDERR " \$directories{SRCTOP} = \"$directories{SRCTOP}\"\n";
+ print STDERR " \$directories{BLDTOP} = \"$directories{BLDTOP}\"\n";
print STDERR "\n";
- print STDERR " current directory is \"",curdir(),"\"\n";
print STDERR " the way back is \"$reverse\"\n";
}
# In the Windows case, we run perl explicitly. We might not
# need it, but that depends on if the user has associated the
# '.pl' extension with a perl interpreter, so better be safe.
- @prefix = ( $^X, $std_wrapper );
+ @prefix = ( __fixup_prg($^X), $std_wrapper );
} else {
# Otherwise, we assume Unix semantics, and trust that the #!
# line activates perl for us.