Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adsk Contrib - Fix environment serialization for v1 configs #1904

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/OpenColorIO/OCIOYaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4738,9 +4738,9 @@ inline void save(YAML::Emitter & out, const Config & config)
out << YAML::Newline;
out << YAML::Newline;

if (configMajorVersion >= 2)
if (configMajorVersion >= 2 || config.getNumEnvironmentVars() > 0)
{
// Print the environment even if empty.
// For v2 configs, write the environment section, even if empty.
out << YAML::Key << "environment";
out << YAML::Value << YAML::BeginMap;
for(int i = 0; i < config.getNumEnvironmentVars(); ++i)
Expand Down
49 changes: 49 additions & 0 deletions tests/cpu/Config_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,55 @@ OCIO_ADD_TEST(Config, serialize_searchpath)
}
}

OCIO_ADD_TEST(Config, serialize_environment)
{
{
OCIO::ConfigRcPtr config = OCIO::Config::Create();
config->setMajorVersion(1);
config->setMinorVersion(0);

std::ostringstream os;
config->serialize(os);
StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());

// A v1 config does not write the environment section if it's empty.
const std::string expected{ "search_path: \"\"" };
OCIO_CHECK_EQUAL(osvec[2], expected);
}
{
OCIO::ConfigRcPtr config = OCIO::Config::Create();
config->setMajorVersion(2);
config->setMinorVersion(0);

std::ostringstream os;
config->serialize(os);
StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());

// A v2 config does write the environment section, even if it's empty.
const std::string expected1{ "environment:" };
const std::string expected2{ " {}" };
OCIO_CHECK_EQUAL(osvec[2], expected1);
OCIO_CHECK_EQUAL(osvec[3], expected2);
}
{
OCIO::ConfigRcPtr config = OCIO::Config::Create();
config->setMajorVersion(1);
config->setMinorVersion(0);

config->addEnvironmentVar("SHOT", "0001");

std::ostringstream os;
config->serialize(os);
StringUtils::StringVec osvec = StringUtils::SplitByLines(os.str());

// A v1 config does write the environment section if it's not empty.
const std::string expected1{ "environment:" };
const std::string expected2{ " SHOT: 0001" };
OCIO_CHECK_EQUAL(osvec[2], expected1);
OCIO_CHECK_EQUAL(osvec[3], expected2);
}
}

OCIO_ADD_TEST(Config, validation)
{
{
Expand Down