From a2a4adf877159c224571d906cd0c8f431c44a3b7 Mon Sep 17 00:00:00 2001 From: jackohoeg Date: Wed, 17 May 2023 12:01:26 -0400 Subject: [PATCH] Correct 'usdcat --flattenLayerStack' which had been outputting a flattened, unloaded stage. --- pxr/usd/bin/usdcat/CMakeLists.txt | 16 ++++++++++++++++ .../baseline/output.usda | 9 +++++++++ .../testenv/testFlattenLayerStack/input.usda | 12 ++++++++++++ .../testFlattenLayerStack/sublayer.usda | 5 +++++ pxr/usd/bin/usdcat/usdcat.cpp | 19 +++++++++++-------- 5 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/baseline/output.usda create mode 100644 pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/input.usda create mode 100644 pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/sublayer.usda diff --git a/pxr/usd/bin/usdcat/CMakeLists.txt b/pxr/usd/bin/usdcat/CMakeLists.txt index 5d3d216091..73c4606377 100644 --- a/pxr/usd/bin/usdcat/CMakeLists.txt +++ b/pxr/usd/bin/usdcat/CMakeLists.txt @@ -50,6 +50,11 @@ pxr_register_test(testUsdCatMissingOrInvalidFiles2 EXPECTED_RETURN_CODE 1 ) +pxr_register_test(testUsdCatMissingOrInvalidFiles3 + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/usdcat --flattenLayerStack foo.usda" + EXPECTED_RETURN_CODE 1 +) + pxr_install_test_dir( SRC testenv/testUsdCatMask DEST testUsdCatMask @@ -86,3 +91,14 @@ pxr_register_test(testUsdCatLayerMetadata DIFF_COMPARE output.usda EXPECTED_RETURN_CODE 0 ) + +pxr_install_test_dir( + SRC testenv/testFlattenLayerStack + DEST testUsdCatFlattenLayerStack +) + +pxr_register_test(testUsdCatFlattenLayerStack + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/usdcat --flattenLayerStack input.usda --out output.usda" + DIFF_COMPARE output.usda + EXPECTED_RETURN_CODE 0 +) diff --git a/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/baseline/output.usda b/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/baseline/output.usda new file mode 100644 index 0000000000..ddd11a6c88 --- /dev/null +++ b/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/baseline/output.usda @@ -0,0 +1,9 @@ +#usda 1.0 + +def Xform "Prim" ( + references = @reference.usda@ +) +{ + int primvars:should_be_here = 0 +} + diff --git a/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/input.usda b/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/input.usda new file mode 100644 index 0000000000..d0d7560526 --- /dev/null +++ b/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/input.usda @@ -0,0 +1,12 @@ +#usda 1.0 +( + subLayers = [ + @./sublayer.usda@ + ] +) + +over "Prim" ( + references = @reference.usda@ +) +{ +} diff --git a/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/sublayer.usda b/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/sublayer.usda new file mode 100644 index 0000000000..56e42f6516 --- /dev/null +++ b/pxr/usd/bin/usdcat/testenv/testFlattenLayerStack/sublayer.usda @@ -0,0 +1,5 @@ +#usda 1.0 + +def Xform "Prim" { + int primvars:should_be_here = 0 +} diff --git a/pxr/usd/bin/usdcat/usdcat.cpp b/pxr/usd/bin/usdcat/usdcat.cpp index 79b70693a9..21ef6c7690 100644 --- a/pxr/usd/bin/usdcat/usdcat.cpp +++ b/pxr/usd/bin/usdcat/usdcat.cpp @@ -216,7 +216,9 @@ static int UsdCat(const Args &args) { } } else if (args.flattenLayerStack) { stage = UsdStage::Open(input, UsdStage::LoadNone); - layer = UsdUtilsFlattenLayerStack(stage); + if (stage) { + layer = UsdUtilsFlattenLayerStack(stage); + } } else if (args.layerMetadata) { auto srcLayer = SdfLayer::OpenAsAnonymous( input, /* metadataOnly = */ true); @@ -263,13 +265,13 @@ static int UsdCat(const Args &args) { // Write to either stdout or the specified output file if (!args.output.empty()) { - if (stage) { + if (layer) { + layer->Export(args.output, std::string(), formatArgs); + } + else { stage->Export( args.output, !args.skipSourceFileComment, formatArgs); } - else if (layer) { - layer->Export(args.output, std::string(), formatArgs); - } if (!errMark.IsClean()) { exitCode = 1; @@ -288,11 +290,12 @@ static int UsdCat(const Args &args) { } else { std::string usdString; - if (stage) { - stage->ExportToString(&usdString); - } else { + if (layer) { layer->ExportToString(&usdString); } + else { + stage->ExportToString(&usdString); + } if (errMark.IsClean()) { std::cout << usdString;