summaryrefslogtreecommitdiff
path: root/modules/CMakeWorkspaceCreator.pm
diff options
context:
space:
mode:
authorChad Elliott <elliottc@objectcomputing.com>2022-11-17 07:55:25 -0600
committerChad Elliott <elliottc@objectcomputing.com>2022-11-17 07:55:25 -0600
commitf6915f51c2244fe7303d38ddc747055d64b72820 (patch)
treea4a3c28bf3d1f46d6b63a16197bffd86cce6d738 /modules/CMakeWorkspaceCreator.pm
parent1d04f7001338262563dd1e527015366a6bf2fa23 (diff)
downloadMPC-f6915f51c2244fe7303d38ddc747055d64b72820.tar.gz
Corrected problems with generation of CMake workspaces with directories above or outside of the directory of the workspace.
Diffstat (limited to 'modules/CMakeWorkspaceCreator.pm')
-rw-r--r--modules/CMakeWorkspaceCreator.pm40
1 files changed, 25 insertions, 15 deletions
diff --git a/modules/CMakeWorkspaceCreator.pm b/modules/CMakeWorkspaceCreator.pm
index 6a9d994a..ceca1cbe 100644
--- a/modules/CMakeWorkspaceCreator.pm
+++ b/modules/CMakeWorkspaceCreator.pm
@@ -51,24 +51,34 @@ sub pre_workspace {
'# ', $self->create_command_line_string($0, @ARGV), $crlf);
}
+## Get the top level directory in the path. If the path does not contain
+## a directory, the path will be returned unmodified.
sub get_top_directory {
my($self, $path) = @_;
- ## Get the top level directory in the path. If the path does not contain
- ## a directory, the path will be returned unmodified.
- my $dir = $path;
- my $done = 0;
- do {
- ## Go up one directory. If we were already at the top directory,
- ## we're finished.
- my $next = $self->mpc_dirname($dir);
- if ($next eq '.') {
- $done = 1;
- }
- else {
- $dir = $next;
- }
- } while(!$done);
+ ## First, convert the path to a relative path based on the current working
+ ## directory.
+ my $dir = $self->path_to_relative($self->getcwd(), $path);
+ if ($dir =~ /^\.\.\// || !$self->path_is_relative($dir)) {
+ ## If the directory is above the current directory or not relative to
+ ## the current working directory, we need to give the directory portion
+ ## back and call it a day.
+ return $self->mpc_dirname($dir);
+ }
+ else {
+ my $done = 0;
+ do {
+ ## Go up one directory. If we were already at the top directory,
+ ## we're finished.
+ my $next = $self->mpc_dirname($dir);
+ if ($next eq '.') {
+ $done = 1;
+ }
+ else {
+ $dir = $next;
+ }
+ } while(!$done);
+ }
return $dir;
}