diff --git a/src/cmd/cmdgazebo.rb.in b/src/cmd/cmdgazebo.rb.in index 3fa1ce425f..3a660a5be8 100755 --- a/src/cmd/cmdgazebo.rb.in +++ b/src/cmd/cmdgazebo.rb.in @@ -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) diff --git a/src/ign_TEST.cc b/src/ign_TEST.cc index 605badc29c..646e1b230f 100644 --- a/src/ign_TEST.cc +++ b/src/ign_TEST.cc @@ -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 /////////////////////////////////////////////////