Skip to content

Commit

Permalink
Multiple resource paths separated by colon
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <louise@openrobotics.org>
  • Loading branch information
chapulina committed May 16, 2020
1 parent 7f5bd7a commit 01fc2ff
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/cmd/cmdgazebo.rb.in
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,19 @@ class Cmd
# If not, then first check the IGN_GAZEBO_RESOURCE_PATH environment
# variable, then the configuration path from the launch library.
else
configPathEnv = ENV['IGN_GAZEBO_RESOURCE_PATH']
# todo: IGN_GAZEBO_RESOURCE_PATH is colon separated.
if !configPathEnv.nil? &&
File.exists?(File.join(configPathEnv, options['file']))
path = File.join(configPathEnv, options['file'])
else
resourcePathEnv = ENV['IGN_GAZEBO_RESOURCE_PATH']
if !resourcePathEnv.nil?
resourcePaths = resourcePathEnv.split(':')
for resourcePath in resourcePaths
filePath = File.join(resourcePath, options['file'])
if File.exists?(filePath)
path = filePath
break
end
end
end

if path.nil?
Importer.extern 'char *worldInstallDir()'
path = File.join(Importer.worldInstallDir().to_s, options['file'])
if !File.exists?(path)
Expand Down
27 changes: 27 additions & 0 deletions src/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,33 @@ TEST(CmdLine, Gazebo)
<< output;
}
}

/////////////////////////////////////////////////
TEST(CmdLine, ResourcePath)
{
std::string cmd = kIgnCommand + " -s -r -v 4 --iterations 1 plugins.sdf";

// No path
std::string output = customExecStr(cmd);
EXPECT_NE(output.find("Unable to find file plugins.sdf"), std::string::npos)
<< output;

// Correct path
auto path =std::string("IGN_GAZEBO_RESOURCE_PATH=") +
PROJECT_SOURCE_PATH + "/test/worlds ";

output = customExecStr(path + cmd);
EXPECT_EQ(output.find("Unable to find file plugins.sdf"), std::string::npos)
<< output;

// Several paths
path =std::string("IGN_GAZEBO_RESOURCE_PATH=banana:") +
PROJECT_SOURCE_PATH + "/test/worlds:orange ";

output = customExecStr(path + cmd);
EXPECT_EQ(output.find("Unable to find file plugins.sdf"), std::string::npos)
<< output;
}
#endif

/////////////////////////////////////////////////
Expand Down

0 comments on commit 01fc2ff

Please sign in to comment.