Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[USD] Installing built-in schemas. #232

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmake/macros/Private.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
50 changes: 50 additions & 0 deletions cmake/macros/replaceSublayerSchemas.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions pxr/base/lib/plug/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ Plug_GetPaths()

}

std::vector<std::string>
PlugRegistry::GetAllRegisteredPluginPaths() const {
PlugPlugin::_RegisterAllPlugins();
return Plug_GetPaths();
}

void
Plug_SetPaths(const std::vector<std::string>& paths)
{
Expand Down
3 changes: 3 additions & 0 deletions pxr/base/lib/plug/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> GetAllRegisteredPluginPaths() const;
private:
// Private ctor and dtor since this is a constructed as a singleton.
PLUG_LOCAL
Expand Down
2 changes: 2 additions & 0 deletions pxr/base/lib/plug/wrapRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ void wrapRegistry()
.def("GetPluginForType", &_GetPluginForType)
.def("GetAllPlugins", &This::GetAllPlugins,
return_value_policy<TfPySequenceToList>())
.def("GetAllRegisteredPluginPaths", &This::GetAllRegisteredPluginPaths,
return_value_policy<TfPySequenceToList>())

.def("FindTypeByName", This::FindTypeByName,
return_value_policy<return_by_value>())
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/lib/usd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pxr_library(usd
RESOURCE_FILES
plugInfo.json
generatedSchema.usda
schema.usda
)

if (NOT JINJA2_FOUND)
Expand Down
7 changes: 5 additions & 2 deletions pxr/usd/lib/usd/usdGenSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down Expand Up @@ -700,7 +700,7 @@ def demangle(typeName):


def GenerateRegistry(codeGenPath, filePath, classes, validate, env):

# Get the flattened layer to work with.
flatLayer = _MakeFlattenedRegistryLayer(filePath)

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/lib/usdGeom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pxr_library(usdGeom
RESOURCE_FILES
plugInfo.json
generatedSchema.usda
schema.usda
)

pxr_test_scripts(
Expand Down
2 changes: 2 additions & 0 deletions pxr/usd/lib/usdHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ pxr_library(usdHydra

RESOURCE_FILES
plugInfo.json
generatedSchema.usda
schema.usda
)

1 change: 1 addition & 0 deletions pxr/usd/lib/usdLux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ pxr_library(usdLux
RESOURCE_FILES
plugInfo.json
generatedSchema.usda
schema.usda
)

1 change: 1 addition & 0 deletions pxr/usd/lib/usdRi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pxr_library(usdRi
RESOURCE_FILES
plugInfo.json
generatedSchema.usda
schema.usda
)

pxr_test_scripts(
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/lib/usdShade/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pxr_library(usdShade
RESOURCE_FILES
plugInfo.json
generatedSchema.usda
schema.usda
)

pxr_test_scripts(
Expand Down
1 change: 1 addition & 0 deletions pxr/usd/lib/usdUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pxr_library(usdUI
RESOURCE_FILES
plugInfo.json
generatedSchema.usda
schema.usda
)

pxr_test_scripts(
Expand Down
1 change: 1 addition & 0 deletions third_party/katana/lib/usdKatana/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ pxr_shared_library(${PXR_PACKAGE}
RESOURCE_FILES
plugInfo.json
generatedSchema.usda
schema.usda
)