Skip to content

Commit

Permalink
Allow files paths for include URIs
Browse files Browse the repository at this point in the history
//include/uri used to only take directories that contain a model.config
file and the sdformat file. However, allowing //include/uri to take file
names can be supported without loss of functionality.

Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Dec 23, 2020
1 parent e0e09f9 commit 3b8de07
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -961,16 +961,19 @@ bool readXml(tinyxml2::XMLElement *_xml, ElementPtr _sdf, Errors &_errors)
}
else
{
if (!sdf::filesystem::is_directory(modelPath))
if (sdf::filesystem::is_directory(modelPath))
{
_errors.push_back({ErrorCode::DIRECTORY_NONEXISTANT,
"Directory doesn't exist[" + modelPath + "]"});
continue;
// Get the model.config filename
filename = getModelFilePath(modelPath);
}
else
{
// This is a file path and since sdf::findFile returns an empty
// string if the file doesn't exist, we don't have to check for
// existence again here.
filename = modelPath;
}
}

// Get the config.xml filename
filename = getModelFilePath(modelPath);
}
else
{
Expand Down
15 changes: 14 additions & 1 deletion test/integration/includes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ TEST(IncludesTest, Includes)
EXPECT_EQ("", pointLight1->PoseRelativeTo());

// Models
EXPECT_EQ(2u, world->ModelCount());
EXPECT_EQ(3u, world->ModelCount());
EXPECT_FALSE(world->ModelNameExists(""));

// Model without overrides
Expand Down Expand Up @@ -209,6 +209,19 @@ TEST(IncludesTest, Includes)
EXPECT_EQ("", model1->PoseRelativeTo());
ASSERT_NE(nullptr, model1->Element());
EXPECT_TRUE(model1->Element()->HasElement("plugin"));

const sdf::Model *model2 = world->ModelByIndex(2);
ASSERT_NE(nullptr, model2);
EXPECT_EQ("test_model_with_file", model2->Name());
EXPECT_FALSE(model2->Static());
EXPECT_EQ(1u, model2->LinkCount());
ASSERT_FALSE(nullptr == model2->LinkByIndex(0));
ASSERT_FALSE(nullptr == model2->LinkByName("link"));
EXPECT_EQ(model2->LinkByName("link")->Name(), model2->LinkByIndex(0)->Name());
EXPECT_TRUE(nullptr == model2->LinkByIndex(1));
EXPECT_TRUE(model2->LinkNameExists("link"));
EXPECT_FALSE(model2->LinkNameExists("coconut"));
EXPECT_EQ("1.6", model2->Element()->OriginalVersion());
}

//////////////////////////////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions test/sdf/includes.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
<plugin name="plugin_name" filename="file.so"/>
</include>

<include>
<uri>test_model/model.sdf</uri>
<name>test_model_with_file</name>
</include>

<include>
<uri>test_light</uri>
</include>
Expand Down

0 comments on commit 3b8de07

Please sign in to comment.