diff --git a/pxr/usd/bin/usdcat/CMakeLists.txt b/pxr/usd/bin/usdcat/CMakeLists.txt index 5d3d216091..f2192e3c20 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 missingFile.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/testUsdCatFlattenLayerStack + 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/testUsdCatFlattenLayerStack/baseline/output.usda b/pxr/usd/bin/usdcat/testenv/testUsdCatFlattenLayerStack/baseline/output.usda new file mode 100644 index 0000000000..ddd11a6c88 --- /dev/null +++ b/pxr/usd/bin/usdcat/testenv/testUsdCatFlattenLayerStack/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/testUsdCatFlattenLayerStack/input.usda b/pxr/usd/bin/usdcat/testenv/testUsdCatFlattenLayerStack/input.usda new file mode 100644 index 0000000000..d0d7560526 --- /dev/null +++ b/pxr/usd/bin/usdcat/testenv/testUsdCatFlattenLayerStack/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/testUsdCatFlattenLayerStack/sublayer.usda b/pxr/usd/bin/usdcat/testenv/testUsdCatFlattenLayerStack/sublayer.usda new file mode 100644 index 0000000000..56e42f6516 --- /dev/null +++ b/pxr/usd/bin/usdcat/testenv/testUsdCatFlattenLayerStack/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;