diff --git a/cmake/macros/Private.cmake b/cmake/macros/Private.cmake index ff389a1a66..791d450bde 100644 --- a/cmake/macros/Private.cmake +++ b/cmake/macros/Private.cmake @@ -98,6 +98,23 @@ function(_plugInfo_subst libTarget pluginToLibraryPath plugInfoPath) ) endfunction() # _plugInfo_subst +function(_replaceSublayer_schema NAME schemaSource) + set(infile "${CMAKE_CURRENT_SOURCE_DIR}/${schemaSource}") + set(outfile "${CMAKE_CURRENT_BINARY_DIR}/${schemaSource}") + add_custom_target(${NAME}_replaceSublayerSchema + COMMAND + "${PYTHON_EXECUTABLE}" + "${PROJECT_SOURCE_DIR}/cmake/macros/replaceSublayerSchemas.py" + "${infile}" + "${outfile}" + SOURCES "${infile}" + COMMENT "Replacing sublayer schemas ${f} ..." + ) + + # Make sure the sublayers are generated before the library. + add_dependencies(${NAME} ${NAME}_replaceSublayerSchema) +endfunction() + # Generate a doxygen config file function(_pxrDoxyConfig_subst) configure_file(${CMAKE_SOURCE_DIR}/pxr/usd/lib/usd/Doxyfile.in @@ -196,6 +213,11 @@ function(_install_resource_files NAME pluginInstallPrefix pluginToLibraryPath) if (${resourceFile} STREQUAL "plugInfo.json") _plugInfo_subst(${NAME} "${pluginToLibraryPath}" ${resourceFile}) list(APPEND resourceFiles "${CMAKE_CURRENT_BINARY_DIR}/${resourceFile}") + # Schema files from the source tree need their sublayers substituted + # so 3rd party plugins will have an easier time working with the installed schemas. + elseif (${resourceFile} STREQUAL "schema.usda") + _replaceSublayer_schema(${NAME} ${resourceFile}) + list(APPEND resourceFiles "${CMAKE_CURRENT_BINARY_DIR}/${resourceFile}") else() list(APPEND resourceFiles ${resourceFile}) endif() diff --git a/cmake/macros/replaceSublayerSchemas.py b/cmake/macros/replaceSublayerSchemas.py new file mode 100644 index 0000000000..3d6e6d069e --- /dev/null +++ b/cmake/macros/replaceSublayerSchemas.py @@ -0,0 +1,50 @@ +# +# Copyright 2017 Pixar +# +# Licensed under the Apache License, Version 2.0 (the "Apache License") +# with the following modification; you may not use this file except in +# compliance with the Apache License and the following modification to it: +# Section 6. Trademarks. is deleted and replaced with: +# +# 6. Trademarks. This License does not grant permission to use the trade +# names, trademarks, service marks, or product names of the Licensor +# and its affiliates, except as required to comply with Section 4(c) of +# the License and to reproduce the content of the NOTICE file. +# +# You may obtain a copy of the Apache License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the Apache License with the above modification is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the Apache License for the specific +# language governing permissions and limitations under the Apache License. +# +# +# Usage: +# replaceSublayerSchemas source.py dest.py +# +# The command replaces the sublayer schema references so they will point +# to the proper location once installed. We are not using the python bindings +# on purpose, otherwise the script would require the libs that are just being built. +# +# Each sublayer of the format ../module_name/schema.usda is to be replaced with +# module_name/resources/schema.usda . + +import sys + +if len(sys.argv) != 3: + print "Usage: %s {source.py dest.py}" % sys.argv[0] + sys.exit(1) + +with open(sys.argv[1], 'r') as s: + with open(sys.argv[2], 'w') as d: + import re + pattern = re.compile(r"@.*\/([^\/]*)\/schema.usda@") + for line in s: + m = pattern.search(line) + if m: + d.write(line.replace(m.group(0), "@%s/resources/schema.usda@" % m.group(1))) + else: + d.write(line) diff --git a/pxr/base/lib/plug/registry.cpp b/pxr/base/lib/plug/registry.cpp index b0e7034b1f..771724767e 100644 --- a/pxr/base/lib/plug/registry.cpp +++ b/pxr/base/lib/plug/registry.cpp @@ -250,6 +250,12 @@ Plug_GetPaths() } +std::vector +PlugRegistry::GetAllRegisteredPluginPaths() const { + PlugPlugin::_RegisterAllPlugins(); + return Plug_GetPaths(); +} + void Plug_SetPaths(const std::vector& paths) { diff --git a/pxr/base/lib/plug/registry.h b/pxr/base/lib/plug/registry.h index 19539885f6..ee7c6b419a 100644 --- a/pxr/base/lib/plug/registry.h +++ b/pxr/base/lib/plug/registry.h @@ -435,6 +435,9 @@ class PlugRegistry : public TfWeakBase, boost::noncopyable { JsValue GetDataFromPluginMetaData(TfType type, const std::string &key) const; + /// Returns all the registered plugin paths. + PLUG_API + std::vector GetAllRegisteredPluginPaths() const; private: // Private ctor and dtor since this is a constructed as a singleton. PLUG_LOCAL diff --git a/pxr/base/lib/plug/wrapRegistry.cpp b/pxr/base/lib/plug/wrapRegistry.cpp index 35aaec26b0..1a9356b460 100644 --- a/pxr/base/lib/plug/wrapRegistry.cpp +++ b/pxr/base/lib/plug/wrapRegistry.cpp @@ -214,6 +214,8 @@ void wrapRegistry() .def("GetPluginForType", &_GetPluginForType) .def("GetAllPlugins", &This::GetAllPlugins, return_value_policy()) + .def("GetAllRegisteredPluginPaths", &This::GetAllRegisteredPluginPaths, + return_value_policy()) .def("FindTypeByName", This::FindTypeByName, return_value_policy()) diff --git a/pxr/usd/lib/usd/CMakeLists.txt b/pxr/usd/lib/usd/CMakeLists.txt index 209cca17e5..368dee32d3 100644 --- a/pxr/usd/lib/usd/CMakeLists.txt +++ b/pxr/usd/lib/usd/CMakeLists.txt @@ -120,6 +120,7 @@ pxr_library(usd RESOURCE_FILES plugInfo.json generatedSchema.usda + schema.usda ) if (NOT JINJA2_FOUND) diff --git a/pxr/usd/lib/usd/usdGenSchema.py b/pxr/usd/lib/usd/usdGenSchema.py index d52adaef53..ecbe6ea6e5 100644 --- a/pxr/usd/lib/usd/usdGenSchema.py +++ b/pxr/usd/lib/usd/usdGenSchema.py @@ -43,7 +43,7 @@ from jinja2 import Environment, FileSystemLoader from jinja2.exceptions import TemplateSyntaxError -from pxr import Sdf, Usd, Tf +from pxr import Sdf, Usd, Tf, Plug, Ar #------------------------------------------------------------------------------# # Parsed Objects # @@ -700,7 +700,7 @@ def demangle(typeName): def GenerateRegistry(codeGenPath, filePath, classes, validate, env): - + # Get the flattened layer to work with. flatLayer = _MakeFlattenedRegistryLayer(filePath) @@ -813,6 +813,9 @@ def GenerateRegistry(codeGenPath, filePath, classes, validate, env): sys.exit(1) try: + # Setting up the default search path for plugins + os.environ['PXR_AR_DEFAULT_SEARCH_PATH'] = os.pathsep.join( + Plug.Registry().GetAllRegisteredPluginPaths() + [os.getenv('PXR_AR_DEFAULT_SEARCH_PATH', '')]) # # Gather Schema Class information diff --git a/pxr/usd/lib/usdGeom/CMakeLists.txt b/pxr/usd/lib/usdGeom/CMakeLists.txt index e54b24dfe1..db6001aaea 100644 --- a/pxr/usd/lib/usdGeom/CMakeLists.txt +++ b/pxr/usd/lib/usdGeom/CMakeLists.txt @@ -97,6 +97,7 @@ pxr_library(usdGeom RESOURCE_FILES plugInfo.json generatedSchema.usda + schema.usda ) pxr_test_scripts( diff --git a/pxr/usd/lib/usdHydra/CMakeLists.txt b/pxr/usd/lib/usdHydra/CMakeLists.txt index 9570ebbd55..51aa7fd662 100644 --- a/pxr/usd/lib/usdHydra/CMakeLists.txt +++ b/pxr/usd/lib/usdHydra/CMakeLists.txt @@ -38,5 +38,7 @@ pxr_library(usdHydra RESOURCE_FILES plugInfo.json + generatedSchema.usda + schema.usda ) diff --git a/pxr/usd/lib/usdLux/CMakeLists.txt b/pxr/usd/lib/usdLux/CMakeLists.txt index 100bb76c63..502db91730 100644 --- a/pxr/usd/lib/usdLux/CMakeLists.txt +++ b/pxr/usd/lib/usdLux/CMakeLists.txt @@ -55,5 +55,6 @@ pxr_library(usdLux RESOURCE_FILES plugInfo.json generatedSchema.usda + schema.usda ) diff --git a/pxr/usd/lib/usdRi/CMakeLists.txt b/pxr/usd/lib/usdRi/CMakeLists.txt index 1a96f869ce..f8a1670093 100644 --- a/pxr/usd/lib/usdRi/CMakeLists.txt +++ b/pxr/usd/lib/usdRi/CMakeLists.txt @@ -77,6 +77,7 @@ pxr_library(usdRi RESOURCE_FILES plugInfo.json generatedSchema.usda + schema.usda ) pxr_test_scripts( diff --git a/pxr/usd/lib/usdShade/CMakeLists.txt b/pxr/usd/lib/usdShade/CMakeLists.txt index 863e6f9c33..215008f153 100644 --- a/pxr/usd/lib/usdShade/CMakeLists.txt +++ b/pxr/usd/lib/usdShade/CMakeLists.txt @@ -48,6 +48,7 @@ pxr_library(usdShade RESOURCE_FILES plugInfo.json generatedSchema.usda + schema.usda ) pxr_test_scripts( diff --git a/pxr/usd/lib/usdUI/CMakeLists.txt b/pxr/usd/lib/usdUI/CMakeLists.txt index 4dab7a0898..bfdc55695f 100644 --- a/pxr/usd/lib/usdUI/CMakeLists.txt +++ b/pxr/usd/lib/usdUI/CMakeLists.txt @@ -33,6 +33,7 @@ pxr_library(usdUI RESOURCE_FILES plugInfo.json generatedSchema.usda + schema.usda ) pxr_test_scripts( diff --git a/third_party/katana/lib/usdKatana/CMakeLists.txt b/third_party/katana/lib/usdKatana/CMakeLists.txt index 991772b194..6f2ac0893c 100644 --- a/third_party/katana/lib/usdKatana/CMakeLists.txt +++ b/third_party/katana/lib/usdKatana/CMakeLists.txt @@ -68,5 +68,6 @@ pxr_shared_library(${PXR_PACKAGE} RESOURCE_FILES plugInfo.json generatedSchema.usda + schema.usda )