Skip to content

Commit

Permalink
UsdUtilsExtractExternalReferences() no longer relies on mutating
Browse files Browse the repository at this point in the history
list-ops (via ModifyItemEdits) to collect layer deps.

Fixes PixarAnimationStudios#1573

(Internal change: 2180649)
  • Loading branch information
blevin authored and marktucker committed Aug 9, 2021
1 parent f5da946 commit f99c292
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
28 changes: 20 additions & 8 deletions pxr/usd/usdUtils/dependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,16 @@ _FileAnalyzer::_RemapRefOrPayload(const RefOrPayloadType &refOrPayload)
void
_FileAnalyzer::_ProcessPayloads(const SdfPrimSpecHandle &primSpec)
{
SdfPayloadsProxy payloadList = primSpec->GetPayloadList();
payloadList.ModifyItemEdits(std::bind(
&_FileAnalyzer::_RemapRefOrPayload<SdfPayload, _DepType::Payload>,
this, std::placeholders::_1));
if (_remapPathFunc) {
primSpec->GetPayloadList().ModifyItemEdits(std::bind(
&_FileAnalyzer::_RemapRefOrPayload<SdfPayload, _DepType::Payload>,
this, std::placeholders::_1));
} else {
for (SdfPayload const& payload:
primSpec->GetPayloadList().GetAddedOrExplicitItems()) {
_ProcessDependency(payload.GetAssetPath(), _DepType::Payload);
}
}
}

void
Expand Down Expand Up @@ -529,10 +535,16 @@ _FileAnalyzer::_ProcessMetadata(const SdfPrimSpecHandle &primSpec)
void
_FileAnalyzer::_ProcessReferences(const SdfPrimSpecHandle &primSpec)
{
SdfReferencesProxy refList = primSpec->GetReferenceList();
refList.ModifyItemEdits(std::bind(
&_FileAnalyzer::_RemapRefOrPayload<SdfReference, _DepType::Reference>,
this, std::placeholders::_1));
if (_remapPathFunc) {
primSpec->GetReferenceList().ModifyItemEdits(std::bind(
&_FileAnalyzer::_RemapRefOrPayload<SdfReference,
_DepType::Reference>, this, std::placeholders::_1));
} else {
for (SdfReference const& reference:
primSpec->GetReferenceList().GetAddedOrExplicitItems()) {
_ProcessDependency(reference.GetAssetPath(), _DepType::Reference);
}
}
}

void
Expand Down
7 changes: 6 additions & 1 deletion pxr/usd/usdUtils/testenv/testUsdUtilsDependencyExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
from __future__ import print_function
from pxr import UsdUtils
from pxr import UsdUtils, Sdf
import argparse, contextlib, sys, os

@contextlib.contextmanager
Expand Down Expand Up @@ -50,6 +50,11 @@ def presult(ostr, fileName, refType, refs):
print('Error: cannot access file {}'.format(args.infile), file=sys.stderr)
sys.exit(1)

# Open layer and turn off edit permission, to validate that the dependency
# extractor does not require modifying the layer
layer = Sdf.Layer.FindOrOpen(args.infile)
layer.SetPermissionToEdit(False)

sublayers, references, payloads = \
UsdUtils.ExtractExternalReferences(args.infile)
with stream(args.outfile, 'w') as ofp:
Expand Down

0 comments on commit f99c292

Please sign in to comment.