Skip to content

Commit

Permalink
Merge branch 'main' into bhata/document_datalibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
jstone-lucasfilm authored Oct 9, 2024
2 parents 6251ac8 + 5101013 commit 4c7169a
Show file tree
Hide file tree
Showing 7 changed files with 538 additions and 35 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
fail-fast: false
matrix:
include:
- name: Linux_GCC_9_Python37
os: ubuntu-20.04
- name: Linux_GCC_10_Python37
os: ubuntu-22.04
compiler: gcc
compiler_version: "9"
compiler_version: "10"
python: 3.7
cmake_config: -DMATERIALX_BUILD_SHARED_LIBS=ON -DMATERIALX_BUILD_MONOLITHIC=ON

Expand All @@ -46,10 +46,10 @@ jobs:
coverage_analysis: ON
cmake_config: -DMATERIALX_COVERAGE_ANALYSIS=ON -DMATERIALX_BUILD_RENDER=OFF -DMATERIALX_BUILD_PYTHON=OFF

- name: Linux_Clang_10_Python37
os: ubuntu-20.04
- name: Linux_Clang_13_Python37
os: ubuntu-22.04
compiler: clang
compiler_version: "10"
compiler_version: "13"
python: 3.7
cmake_config: -DMATERIALX_BUILD_SHARED_LIBS=ON

Expand Down Expand Up @@ -351,7 +351,7 @@ jobs:

sdist:
name: Python SDist
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
if: github.repository == 'AcademySoftwareFoundation/MaterialX'
outputs:
sdist_filename: ${{ steps.generate.outputs.filename }}
Expand Down Expand Up @@ -387,7 +387,7 @@ jobs:
fail-fast: false
matrix:
python-minor: ['7', '8', '9', '10', '11', '12']
os: ['ubuntu-latest', 'windows-2022', 'macos-13']
os: ['ubuntu-22.04', 'windows-2022', 'macos-13']

steps:
- name: Sync Repository
Expand Down
31 changes: 5 additions & 26 deletions cmake/modules/AppleFrameworkBuild.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@ BUNDLE_IDENTIFIER="org.aswf.materialx"
CODESIGN_ID="@CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY@"
OLD_RC_PATH="${CMAKE_INSTALL_PREFIX}/lib"

function fix_linkage() {
readonly file=${1:?"A file path must be specified."}
readonly prepend="${FRAMEWORK_NAME}.framework/Libraries"
filename=$(basename ${file})
# First, change the install name. This corresponds to LC_ID_DYLIB.
install_name_tool -id "@rpath/${prepend}/${filename}" ${file}

parts=("${(@f)$(otool -l ${file})}")
for line in ${parts}; do
dylib_name=""
[[ $line =~ ' *name @rpath/(.*\.dylib)' ]] && dylib_name=$match[1]
if [ -n "${dylib_name}" ]; then
install_name_tool -change "@rpath/${dylib_name}" "@rpath/${prepend}/${dylib_name}" "${file}"
fi
if [[ $line == *"${OLD_RC_PATH}"* ]]; then
install_name_tool -delete_rpath ${OLD_RC_PATH} ${file}
fi
done

codesign -f -s ${CODESIGN_ID} ${file}
}

# Remove the existing directory if it exists
if [ -d ${FRAMEWORK_DIR} ]; then
echo "Removing existing framework";
Expand All @@ -53,15 +31,17 @@ echo "Creating Framework Directory: ${FRAMEWORK_DIR}"
mkdir -p ${FRAMEWORK_DIR}

if [ "$EMBEDDED_BUILD" = true ];then
FRAMEWORK_RESOURCES_DIR="${FRAMEWORK_DIR}/Resources"
FRAMEWORK_RESOURCES_DIR="${FRAMEWORK_DIR}/Assets"
FRAMEWORK_PLIST_LOCATION="${FRAMEWORK_DIR}/Info.plist"
FRAMEWORK_HEADERS_DIR="${FRAMEWORK_DIR}/Headers"
FRAMEWORK_LIB_PATH=""${FRAMEWORK_DIR}/${FRAMEWORK_NAME}""
FRAMEWORK_LINKER_PATH="@rpath/Frameworks/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
else
FRAMEWORK_RESOURCES_DIR="${FRAMEWORK_DIR}/Versions/A/Resources/"
FRAMEWORK_PLIST_LOCATION="${FRAMEWORK_DIR}/Versions/A/Resources/Info.plist"
FRAMEWORK_HEADERS_DIR="${FRAMEWORK_DIR}/Versions/A/Headers"
FRAMEWORK_LIB_PATH="${FRAMEWORK_DIR}/Versions/A/${FRAMEWORK_NAME}"
FRAMEWORK_LINKER_PATH="@rpath/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
fi

echo "Creating Resources Root: ${FRAMEWORK_RESOURCES_DIR}"
Expand Down Expand Up @@ -90,9 +70,8 @@ if [ "$EMBEDDED_BUILD" = false ];then
fi

# Fix the linkage on the primary dylib
fix_linkage "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"
install_name_tool -id "@rpath/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"
install_name_tool -change "@rpath/${FRAMEWORK_NAME}.framework/Libraries/${FRAMEWORK_NAME}" "@rpath/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"
install_name_tool -id "${FRAMEWORK_LINKER_PATH}" "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"
install_name_tool -change "@rpath/libMaterialX.@[email protected]" "${FRAMEWORK_LINKER_PATH}" "${FRAMEWORK_DIR}/${FRAMEWORK_NAME}"

# Frameworks require all includes to use the framework name as the prefix for automatic discovery
echo "Modifying headers..."
Expand Down
174 changes: 174 additions & 0 deletions source/MaterialXCore/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ const string ValueElement::UI_ADVANCED_ATTRIBUTE = "uiadvanced";
const string ValueElement::UNIT_ATTRIBUTE = "unit";
const string ValueElement::UNITTYPE_ATTRIBUTE = "unittype";
const string ValueElement::UNIFORM_ATTRIBUTE = "uniform";
const string ElementEquivalenceResult::ATTRIBUTE = "attribute";
const string ElementEquivalenceResult::ATTRIBUTE_NAMES = "attribute names";
const string ElementEquivalenceResult::CHILD_COUNT = "child count";
const string ElementEquivalenceResult::CHILD_NAME = "child name";
const string ElementEquivalenceResult::NAME = "name";
const string ElementEquivalenceResult::CATEGORY = "category";

Element::CreatorMap Element::_creatorMap;

Expand Down Expand Up @@ -334,6 +340,108 @@ bool Element::hasInheritanceCycle() const
return false;
}

bool Element::isEquivalent(ConstElementPtr rhs, const ElementEquivalenceOptions& options,
ElementEquivalenceResultVec* results) const
{
if (getName() != rhs->getName())
{
if (results)
results->push_back(ElementEquivalenceResult(getNamePath(), rhs->getNamePath(), ElementEquivalenceResult::NAME));
return false;
}
if (getCategory() != rhs->getCategory())
{
if (results)
results->push_back(ElementEquivalenceResult(getNamePath(), rhs->getNamePath(), ElementEquivalenceResult::CATEGORY));
return false;
}

// Compare attribute names.
StringVec attributeNames = getAttributeNames();
StringVec rhsAttributeNames = rhs->getAttributeNames();

// Filter out any attributes specified in the options.
const StringSet& skipAttributes = options.skipAttributes;
if (!skipAttributes.empty())
{
attributeNames.erase(std::remove_if(attributeNames.begin(), attributeNames.end(),
[&skipAttributes](const string& attr) { return skipAttributes.find(attr) != skipAttributes.end(); }),
attributeNames.end());
rhsAttributeNames.erase(std::remove_if(rhsAttributeNames.begin(), rhsAttributeNames.end(),
[&skipAttributes](const string& attr) { return skipAttributes.find(attr) != skipAttributes.end(); }),
rhsAttributeNames.end());
}

// Ignore attribute ordering by sorting names
std::sort(attributeNames.begin(), attributeNames.end());
std::sort(rhsAttributeNames.begin(), rhsAttributeNames.end());

if (attributeNames != rhsAttributeNames)
{
if (results)
results->push_back(ElementEquivalenceResult(getNamePath(), rhs->getNamePath(), ElementEquivalenceResult::ATTRIBUTE_NAMES));
return false;
}

for (const string& attr : rhsAttributeNames)
{
if (!isAttributeEquivalent(rhs, attr, options, results))
{
return false;
}
}

// Compare children.
const vector<ElementPtr>& children = getChildren();
const vector<ElementPtr>& rhsChildren = rhs->getChildren();
if (children.size() != rhsChildren.size())
{
if (results)
results->push_back(ElementEquivalenceResult(getNamePath(), rhs->getNamePath(), ElementEquivalenceResult::CHILD_COUNT));
return false;
}
for (size_t i = 0; i < children.size(); i++)
{
ElementPtr rhsElement = rhsChildren[i];
// Handle unordered children if parent is a compound graph (NodeGraph, Document).
// (Functional graphs have a "nodedef" reference and define node interfaces
// so require strict interface ordering.)
ConstGraphElementPtr graph = this->getSelf()->asA<GraphElement>();
if (graph)
{
ConstNodeGraphPtr nodeGraph = graph->asA<NodeGraph>();
ConstDocumentPtr document = graph->asA<Document>();
if (document || (nodeGraph && !nodeGraph->getNodeDef()))
{
const string& childName = children[i]->getName();
rhsElement = rhs->getChild(childName);
if (!rhsElement)
{
if (results)
results->push_back(ElementEquivalenceResult(children[i]->getNamePath(), "<NONE>",
ElementEquivalenceResult::CHILD_NAME, childName));
return false;
}
}
}
if (!children[i]->isEquivalent(rhsElement, options, results))
return false;
}
return true;
}

bool Element::isAttributeEquivalent(ConstElementPtr rhs, const string& attributeName,
const ElementEquivalenceOptions& /*options*/, ElementEquivalenceResultVec* results) const
{
if (getAttribute(attributeName) != rhs->getAttribute(attributeName))
{
if (results)
results->push_back(ElementEquivalenceResult(getNamePath(), rhs->getNamePath(), ElementEquivalenceResult::ATTRIBUTE, attributeName));
return false;
}
return true;
}

TreeIterator Element::traverseTree() const
{
return TreeIterator(getSelfNonConst());
Expand Down Expand Up @@ -534,6 +642,72 @@ const string& ValueElement::getActiveUnit() const
return EMPTY_STRING;
}

bool ValueElement::isAttributeEquivalent(ConstElementPtr rhs, const string& attributeName,
const ElementEquivalenceOptions& options, ElementEquivalenceResultVec* results) const
{
// Perform value comparisons
bool performedValueComparison = false;
if (!options.skipValueComparisons)
{
const StringSet uiAttributes =
{
ValueElement::UI_MIN_ATTRIBUTE, ValueElement::UI_MAX_ATTRIBUTE,
ValueElement::UI_SOFT_MIN_ATTRIBUTE, ValueElement::UI_SOFT_MAX_ATTRIBUTE,
ValueElement::UI_STEP_ATTRIBUTE
};

// Get precision and format options
ScopedFloatFormatting fmt(options.format, options.precision);

ConstValueElementPtr rhsValueElement = rhs->asA<ValueElement>();

// Check value equality
if (attributeName == ValueElement::VALUE_ATTRIBUTE)
{
ValuePtr thisValue = getValue();
ValuePtr rhsValue = rhsValueElement->getValue();
if (thisValue && rhsValue)
{
if (thisValue->getValueString() != rhsValue->getValueString())
{
if (results)
results->push_back(ElementEquivalenceResult(getNamePath(), rhs->getNamePath(), ElementEquivalenceResult::ATTRIBUTE, attributeName));
return false;
}
}
performedValueComparison = true;
}

// Check ui attribute value equality
else if (uiAttributes.find(attributeName) != uiAttributes.end())
{
const string& uiAttribute = getAttribute(attributeName);
const string& rhsUiAttribute = getAttribute(attributeName);
ValuePtr uiValue = !rhsUiAttribute.empty() ? Value::createValueFromStrings(uiAttribute, getType()) : nullptr;
ValuePtr rhsUiValue = !rhsUiAttribute.empty() ? Value::createValueFromStrings(rhsUiAttribute, getType()) : nullptr;
if (uiValue && rhsUiValue)
{
if (uiValue->getValueString() != rhsUiValue->getValueString())
{
if (results)
results->push_back(ElementEquivalenceResult(getNamePath(), rhs->getNamePath(), ElementEquivalenceResult::ATTRIBUTE, attributeName));
return false;
}
}

performedValueComparison = true;
}
}

// If did not peform a value comparison, perform the default comparison
if (!performedValueComparison)
{
return Element::isAttributeEquivalent(rhs, attributeName, options, results);
}

return true;
}

bool ValueElement::validate(string* message) const
{
bool res = true;
Expand Down
Loading

0 comments on commit 4c7169a

Please sign in to comment.