├── .clang-format ├── .clang-tidy ├── .editorconfig ├── .gitattributes ├── .github ├── build_openassetio │ └── action.yml ├── build_openassetio_mediacreation │ └── action.yml └── workflows │ ├── code-quality.yml │ └── test.yml ├── .gitignore ├── CMakeLists.txt ├── CMakePresets.json ├── CPPLINT.cfg ├── LICENSE ├── README.md ├── cmake ├── CompilerWarnings.cmake ├── DefaultTargetProperties.cmake └── StaticAnalyzers.cmake ├── resources └── build │ └── linter-requirements.txt ├── src ├── CMakeLists.txt ├── resolver.cpp └── resources │ └── plugInfo.json └── tests ├── requirements.txt ├── resources ├── empty_shot.usda ├── integration_test_data │ ├── assetized_child_ref_non_assetized_grandchild │ │ ├── car.usd │ │ ├── floor1.usd │ │ └── parking_lot.usd │ ├── bal_library.json │ ├── bal_library_incapable.json │ ├── error_triggering_asset_ref │ │ └── parking_lot.usd │ ├── non_assetized_child_ref_assetized_grandchild │ │ ├── car.usd │ │ ├── floor1.usd │ │ └── parking_lot.usd │ ├── recursive_assetized_resolve │ │ ├── cars │ │ │ └── car.usd │ │ ├── floors │ │ │ └── floor @ 1.usd │ │ └── parking_lot.usd │ ├── resolver_has_no_effect_with_no_search_path │ │ ├── car.usd │ │ ├── floor1.usd │ │ └── parking_lot.usd │ └── resolver_has_no_effect_with_search_path │ │ ├── parking_lot.usd │ │ └── search_path_root │ │ ├── cars │ │ └── car.usd │ │ └── floors │ │ └── floor1.usd ├── openassetio_config_cpp.toml ├── openassetio_config_cpp.toml.incapable ├── openassetio_config_python.toml └── openassetio_config_python.toml.incapable └── test_resolver.py /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | Language: Cpp 3 | Standard: c++17 4 | ColumnLimit: 99 5 | IncludeBlocks: Preserve 6 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2022 Google LLC 3 | # Copyright 2013-2023 The Foundry Visionmongers Ltd 4 | 5 | # Modified from: https://raw.githubusercontent.com/googleapis/google-cloud-cpp/main/.clang-tidy 6 | # See: https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/checks/list.html 7 | --- 8 | # Configure clang-tidy for this project. 9 | 10 | # Here is an explanation for why some of the checks are disabled: 11 | # 12 | # -modernize-use-trailing-return-type: clang-tidy recommends using 13 | # `auto Foo() -> std::string { return ...; }`, we think the code is less 14 | # readable in this form. 15 | # 16 | # -modernize-return-braced-init-list: We think removing typenames and using 17 | # only braced-init can hurt readability. 18 | # 19 | # -modernize-avoid-c-arrays: We only use C arrays when they seem to be the 20 | # right tool for the job, such as `char foo[] = "hello"`. In these cases, 21 | # avoiding C arrays often makes the code less readable, and std::array is 22 | # not a drop-in replacement because it doesn't deduce the size. 23 | # 24 | # -google-runtime-references: Allow usage of non-const references as 25 | # function parameters. Otherwise we'd have to use pointers, which 26 | # cpp core guidelines recommends against unless the parameter is 27 | # nullable: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f60-prefer-t-over-t-when-no-argument-is-a-valid-option 28 | # 29 | # 30 | Checks: > 31 | -*, 32 | bugprone-*, 33 | google-*, 34 | misc-*, 35 | modernize-*, 36 | performance-*, 37 | portability-*, 38 | readability-*, 39 | -modernize-return-braced-init-list, 40 | -modernize-use-trailing-return-type, 41 | -modernize-avoid-c-arrays, 42 | # Turn all the warnings from the checks above into errors. 43 | WarningsAsErrors: "*" 44 | # Scan all (non-system) headers. 45 | HeaderFilterRegex: ".*" 46 | # Use .clang-format for fix suggestions. 47 | FormatStyle: file 48 | 49 | CheckOptions: 50 | - { key: readability-identifier-naming.NamespaceCase, value: camelBack } 51 | - { key: readability-identifier-naming.ClassCase, value: CamelCase } 52 | - { key: readability-identifier-naming.StructCase, value: CamelCase } 53 | - { 54 | key: readability-identifier-naming.TemplateParameterCase, 55 | value: CamelCase, 56 | } 57 | - { key: readability-identifier-naming.FunctionCase, value: camelBack } 58 | - { key: readability-identifier-naming.VariableCase, value: camelBack } 59 | - { 60 | key: readability-identifier-naming.VariableIgnoredRegexp, 61 | value: "^_[0-9]+$", 62 | } 63 | - { key: readability-identifier-naming.ClassMemberCase, value: camelBack } 64 | - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ } 65 | - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } 66 | - { key: readability-identifier-naming.EnumConstantCase, value: CamelCase } 67 | - { key: readability-identifier-naming.EnumConstantPrefix, value: k } 68 | - { 69 | key: readability-identifier-naming.ConstexprVariableCase, 70 | value: CamelCase, 71 | } 72 | - { key: readability-identifier-naming.ConstexprVariablePrefix, value: k } 73 | - { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase } 74 | - { key: readability-identifier-naming.GlobalConstantPrefix, value: k } 75 | - { key: readability-identifier-naming.MemberConstantCase, value: CamelCase } 76 | - { key: readability-identifier-naming.MemberConstantPrefix, value: k } 77 | - { key: readability-identifier-naming.StaticConstantCase, value: CamelCase } 78 | - { key: readability-identifier-naming.StaticConstantPrefix, value: k } 79 | - { 80 | key: readability-implicit-bool-conversion.AllowIntegerConditions, 81 | value: 1, 82 | } 83 | - { 84 | key: readability-implicit-bool-conversion.AllowPointerConditions, 85 | value: 1, 86 | } 87 | # Allow structs where (all) member variables are public, even if 88 | # the struct has member functions. 89 | - { 90 | key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic, 91 | value: 1, 92 | } 93 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | max_line_length = 99 10 | tab_width = 4 11 | trim_trailing_whitespace = true 12 | ij_continuation_indent_size = 8 13 | # For docstrings and comments. 14 | ij_visual_guides = 72 15 | 16 | [{*.h,*.hpp,*.cpp}] 17 | indent_size = 2 18 | tab_width = 2 19 | ij_continuation_indent_size = 4 20 | 21 | [*.yml] 22 | indent_size = 2 23 | 24 | [*.md] 25 | max_line_length = 72 -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Force linux style line endings. 2 | * text=auto eol=lf 3 | -------------------------------------------------------------------------------- /.github/build_openassetio/action.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2023 The Foundry Visionmongers Ltd 3 | 4 | # Composite action for reuse within other workflows. 5 | # Builds OpenAssetIO. 6 | # Should be run on a ghcr.io/openassetio/openassetio-build container. 7 | 8 | name: Build OpenAssetIO 9 | description: Builds OpenAssetIO and publishes an artifact 10 | runs: 11 | using: "composite" 12 | steps: 13 | - name: Checkout OpenAssetIO 14 | uses: actions/checkout@v3 15 | with: 16 | repository: OpenAssetIO/OpenAssetIO 17 | path: openassetio-checkout 18 | 19 | - name: Build OpenAssetIO 20 | shell: bash 21 | run: | 22 | cd openassetio-checkout 23 | mkdir build 24 | cmake -G Ninja -S . -B build -DOPENASSETIO_ENABLE_SIMPLECPPMANAGER=ON 25 | cmake --build build 26 | cmake --install build 27 | 28 | - uses: actions/upload-artifact@v4 29 | with: 30 | name: OpenAssetIO Build 31 | path: openassetio-checkout/build/dist 32 | retention-days: 1 33 | -------------------------------------------------------------------------------- /.github/build_openassetio_mediacreation/action.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2023 The Foundry Visionmongers Ltd 3 | 4 | # Composite action for reuse within other workflows. 5 | # Builds OpenAssetIO-MediaCreation. 6 | # Should be run on a ghcr.io/openassetio/openassetio-build container. 7 | 8 | name: Build OpenAssetIO-MediaCreation 9 | description: Builds OpenAssetIO-MediaCreation and publishes an artifact 10 | runs: 11 | using: "composite" 12 | steps: 13 | - name: Checkout OpenAssetIO-MediaCreation 14 | uses: actions/checkout@v3 15 | with: 16 | repository: OpenAssetIO/OpenAssetIO-MediaCreation 17 | path: openassetio-mediacreation-checkout 18 | 19 | - name: Build OpenAssetIO-MediaCreation 20 | shell: bash 21 | run: | 22 | cd openassetio-mediacreation-checkout 23 | mkdir build 24 | python -m pip install openassetio-traitgen 25 | cmake -G Ninja -S . -B build -DOPENASSETIO_MEDIACREATION_GENERATE_PYTHON=ON 26 | cmake --build build 27 | cmake --install build 28 | 29 | - uses: actions/upload-artifact@v4 30 | with: 31 | name: OpenAssetIO-MediaCreation Build 32 | path: openassetio-mediacreation-checkout/build/dist 33 | retention-days: 1 34 | -------------------------------------------------------------------------------- /.github/workflows/code-quality.yml: -------------------------------------------------------------------------------- 1 | name: Code quality 2 | on: pull_request 3 | 4 | concurrency: 5 | group: ${{ github.workflow }}-${{ github.ref }} 6 | cancel-in-progress: true 7 | 8 | jobs: 9 | pylint: 10 | name: Pylint 11 | runs-on: ubuntu-latest 12 | container: 13 | image: ghcr.io/openassetio/openassetio-build 14 | steps: 15 | - uses: actions/checkout@v3 16 | 17 | - name: Install dependencies 18 | run: | 19 | python -m pip install --upgrade pip 20 | python -m pip install -r resources/build/linter-requirements.txt 21 | python -m pip install -r tests/requirements.txt 22 | 23 | - name: Lint 24 | uses: TheFoundryVisionmongers/fn-pylint-action@v1.1 25 | with: 26 | pylint-disable: fixme # We track 'todo's through other means 27 | pylint-paths: > 28 | tests 29 | black: 30 | runs-on: ubuntu-22.04 31 | name: Python formatting 32 | steps: 33 | - uses: actions/checkout@v3 34 | 35 | - name: Set up Python 36 | uses: actions/setup-python@v4 37 | with: 38 | python-version: "3.11" 39 | 40 | - name: Install dependencies 41 | run: | 42 | python -m pip install --upgrade pip 43 | python -m pip install -r resources/build/linter-requirements.txt 44 | - name: Check Python formatting 45 | run: black tests --check . 46 | 47 | build-openassetio: 48 | name: Build OpenAssetIO 49 | runs-on: ubuntu-latest 50 | container: 51 | image: ghcr.io/openassetio/openassetio-build 52 | steps: 53 | - uses: actions/checkout@v3 54 | - name: Build 55 | uses: ./.github/build_openassetio 56 | 57 | build-openassetio-mediacreation: 58 | name: Build OpenAssetIO-MediaCreation 59 | runs-on: ubuntu-latest 60 | container: 61 | image: ghcr.io/openassetio/openassetio-build 62 | steps: 63 | - uses: actions/checkout@v3 64 | - name: Build 65 | uses: ./.github/build_openassetio_mediacreation 66 | 67 | cpp-linters: 68 | name: C++ linters 69 | runs-on: ubuntu-latest 70 | needs: build-openassetio 71 | container: 72 | image: ghcr.io/openassetio/openassetio-build 73 | steps: 74 | - uses: actions/checkout@v3 75 | 76 | - name: Install dependencies 77 | # Configure the system and install library dependencies via 78 | # conan packages. 79 | run: | 80 | python -m pip install -r resources/build/linter-requirements.txt 81 | clang-tidy --version 82 | clang-format --version 83 | cpplint --version 84 | 85 | - name: Get OpenAssetIO 86 | uses: actions/download-artifact@v4.1.7 87 | with: 88 | name: OpenAssetIO Build 89 | path: ./openassetio-build 90 | 91 | - name: Get OpenAssetIO-MediaCreation 92 | uses: actions/download-artifact@v4.1.7 93 | with: 94 | name: OpenAssetIO-MediaCreation Build 95 | path: ./openassetio-mediacreation-build 96 | 97 | - name: Configure CMake build 98 | run: > 99 | cmake -DCMAKE_PREFIX_PATH="./openassetio-build;./openassetio-mediacreation-build" 100 | -S . -B build -G Ninja 101 | --install-prefix ${{ github.workspace }}/dist 102 | --preset lint 103 | 104 | - name: Build and lint 105 | run: | 106 | cmake --build build 107 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2023-2024 The Foundry Visionmongers Ltd 3 | 4 | # Runs pytest on the matrix of supported platforms any Python versions. 5 | name: Test 6 | on: 7 | pull_request: 8 | 9 | concurrency: 10 | group: ${{ github.workflow }}-${{ github.ref }} 11 | cancel-in-progress: true 12 | 13 | jobs: 14 | build-openassetio: 15 | name: Build OpenAssetIO 16 | runs-on: ubuntu-latest 17 | container: 18 | image: ghcr.io/openassetio/openassetio-build 19 | steps: 20 | - uses: actions/checkout@v3 21 | - name: Build 22 | uses: ./.github/build_openassetio 23 | 24 | build-openassetio-mediacreation: 25 | name: Build OpenAssetIO-MediaCreation 26 | runs-on: ubuntu-latest 27 | container: 28 | image: ghcr.io/openassetio/openassetio-build 29 | steps: 30 | - uses: actions/checkout@v3 31 | - name: Build 32 | uses: ./.github/build_openassetio_mediacreation 33 | 34 | test: 35 | name: Test-Resolver 36 | runs-on: ubuntu-latest 37 | needs: build-openassetio 38 | container: 39 | image: ghcr.io/openassetio/openassetio-build 40 | steps: 41 | - uses: actions/checkout@v3 42 | 43 | - name: Get OpenAssetIO 44 | uses: actions/download-artifact@v4.1.7 45 | with: 46 | name: OpenAssetIO Build 47 | path: ./openassetio-build 48 | 49 | - name: Get OpenAssetIO-MediaCreation 50 | uses: actions/download-artifact@v4.1.7 51 | with: 52 | name: OpenAssetIO-MediaCreation Build 53 | path: ./openassetio-mediacreation-build 54 | 55 | - name: Build and install Resolver 56 | run: | 57 | cmake -S . -DCMAKE_PREFIX_PATH="./openassetio-build;./openassetio-mediacreation-build" -B build 58 | cmake --build build 59 | cmake --install build 60 | 61 | - run: | 62 | python -m pip install -r tests/requirements.txt 63 | 64 | # PYTHONPATH here is extended with `/usr/local/lib/python` 65 | # because the USD install on this docker container is odd, and 66 | # stores the `pxr` lib in that space, whilst the regular python 67 | # libraries are contained at /usr/local/lib/python3.11, 68 | # (which is already on the pythonpath) 69 | # 70 | # LD_LIBRARY_PATH doesn't have /usr/local/lib on it by default 71 | # like you might expect because we're running as root, so we 72 | # just append it (it's so we can find python itself.) 73 | 74 | - name: Configure environment 75 | run: | 76 | echo "PXR_PLUGINPATH_NAME=$GITHUB_WORKSPACE/build/dist/resources/plugInfo.json" >> "$GITHUB_ENV" 77 | echo "LD_LIBRARY_PATH=$GITHUB_WORKSPACE/openassetio-build/lib64" >> "$GITHUB_ENV" 78 | echo "PYTHONPATH=/usr/local/lib/python/:$GITHUB_WORKSPACE/openassetio-build/lib/python3.11/site-packages:$GITHUB_WORKSPACE/openassetio-mediacreation-build/lib/python3.11/site-packages" >> "$GITHUB_ENV" 79 | 80 | - name: Test (Python manager) 81 | run: | 82 | export "OPENASSETIO_DEFAULT_CONFIG=$GITHUB_WORKSPACE/tests/resources/openassetio_config_python.toml" 83 | python -m pytest -v --capture=tee-sys tests 84 | 85 | - name: Test (C++ manager) 86 | run: | 87 | export "OPENASSETIO_DEFAULT_CONFIG=$GITHUB_WORKSPACE/tests/resources/openassetio_config_cpp.toml" 88 | export "OPENASSETIO_PLUGIN_PATH=$GITHUB_WORKSPACE/openassetio-build" 89 | python -m pytest -v --capture=tee-sys tests 90 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | /dist/ 3 | /build 4 | /CMakeUserPresets.json 5 | /out 6 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 1. Requirements 2 | cmake_minimum_required(VERSION 3.21) 3 | 4 | project( 5 | usdOpenAssetIOResolver 6 | VERSION 1.0.0 7 | ) 8 | 9 | set(CMAKE_CXX_STANDARD 17) 10 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 11 | 12 | # Additional include directories for CMake utils. 13 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) 14 | 15 | #----------------------------------------------------------------------- 16 | # Default install directory 17 | 18 | # Default install to a `dist` directory under the build directory, ready 19 | # for use in tests and for packaging. But don't override if user has 20 | # explicitly set CMAKE_INSTALL_PREFIX. 21 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND PROJECT_IS_TOP_LEVEL) 22 | set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/dist" CACHE PATH "Installation location" FORCE) 23 | endif () 24 | 25 | #----------------------------------------------------------------------- 26 | # Lint options 27 | 28 | # Default treating compiler warnings as errors to OFF, since 29 | # consumers of this project may use unpredictable toolchains. 30 | # For dev/CI we should remember to switch this ON, though! 31 | option(OPENASSETIO_USDRESOLVER_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) 32 | 33 | # Enable clang-format formatting check. 34 | option(OPENASSETIO_USDRESOLVER_ENABLE_CLANG_FORMAT "Enable clang-format check during build" OFF) 35 | 36 | # Enable clang-tidy static analysis tool. 37 | option(OPENASSETIO_USDRESOLVER_ENABLE_CLANG_TIDY "Enable clang-tidy analysis during build" OFF) 38 | 39 | # Enable cpplint linter. 40 | option(OPENASSETIO_USDRESOLVER_ENABLE_CPPLINT "Enable cpplint linter during build" OFF) 41 | 42 | # Add Static analysis targets 43 | include(StaticAnalyzers) 44 | if (OPENASSETIO_USDRESOLVER_ENABLE_CLANG_FORMAT) 45 | enable_clang_format() 46 | endif () 47 | if (OPENASSETIO_USDRESOLVER_ENABLE_CLANG_TIDY) 48 | enable_clang_tidy() 49 | endif () 50 | if (OPENASSETIO_USDRESOLVER_ENABLE_CPPLINT) 51 | enable_cpplint() 52 | endif () 53 | 54 | 55 | #----------------------------------------------------------------------- 56 | # Dependencies 57 | 58 | # Find USD. 59 | find_package(pxr REQUIRED) 60 | 61 | # Find OpenAssetIO 62 | find_package(OpenAssetIO REQUIRED) 63 | find_package(OpenAssetIO-MediaCreation REQUIRED) 64 | 65 | 66 | #----------------------------------------------------------------------- 67 | # Recurse to sources 68 | 69 | include(DefaultTargetProperties) 70 | add_subdirectory(src) 71 | 72 | 73 | #----------------------------------------------------------------------- 74 | # Print a status dump 75 | 76 | message(STATUS "Warnings as errors = ${OPENASSETIO_USDRESOLVER_WARNINGS_AS_ERRORS}") 77 | message(STATUS "Linter: clang-tidy = ${OPENASSETIO_USDRESOLVER_ENABLE_CLANG_TIDY} [${OPENASSETIO_USDRESOLVER_CLANGTIDY_EXE}]") 78 | message(STATUS "Linter: cpplint = ${OPENASSETIO_USDRESOLVER_ENABLE_CPPLINT} [${OPENASSETIO_USDRESOLVER_CPPLINT_EXE}]") 79 | message(STATUS "Linter: clang-format = ${OPENASSETIO_USDRESOLVER_ENABLE_CLANG_FORMAT} [${OPENASSETIO_USDRESOLVER_CLANGFORMAT_EXE}]") 80 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "lint", 6 | "cacheVariables": { 7 | "OPENASSETIO_USDRESOLVER_ENABLE_CLANG_FORMAT": "ON", 8 | "OPENASSETIO_USDRESOLVER_ENABLE_CLANG_TIDY": "ON", 9 | "OPENASSETIO_USDRESOLVER_ENABLE_CPPLINT": "ON", 10 | "OPENASSETIO_USDRESOLVER_WARNINGS_AS_ERRORS": "ON" 11 | } 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | set noparent 2 | linelength=99 3 | root=. 4 | # -runtime/references: Allow non-const references as function params. 5 | # -readability/nolint: Don't complain if unrecognized checks are 6 | # disabled by a NOLINT comment. This is because both cpplint 7 | # and clang-tidy use NOLINT, annoyingly. 8 | # -readability/check: CppLint seems to assume `CHECK` is a Google Test 9 | # macro, not a Catch2 macro, and erroneously complains that we should 10 | # use `CHECK_EQ` instead. 11 | # -whitespace/braces: Causes false positives with uniform initialization 12 | # syntax (e.g. `std::string_view{data, size}`). This check is also 13 | # performed by ClangFormat, anyway. 14 | # -readability/casting: Causes false positives with Trompeloeil mocks, 15 | # where CppLint seems to think a macro is actually a C-style cast. 16 | # This check is also performed by Clang-Tidy, anyway. 17 | # -build/c++11 Causes e.g. " is an unapproved C++11 header", 18 | # which is specific for Chromium devs, apparently. 19 | filter=-runtime/references,-readability/nolint,-readability/check,-whitespace/braces 20 | filter=-readability/casting 21 | filter=-build/include_subdir 22 | filter=-build/c++11 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # usdOpenAssetIOResolver 2 | 3 | A USD AR2 plugin that hosts OpenAssetIO. 4 | 5 | > **Note:** 6 | > This project is in a proof-of-concept phase, to explore compatibility 7 | > between the two ecosystems. It is in no way feature complete or 8 | > optimized for performance. 9 | 10 | Provides the capability to resolve entity references through any 11 | OpenAssetIO enabled manager without the need for USD specific 12 | programming. 13 | 14 | Special attention has been made to ensure that this plugin can be used 15 | in existing USD documents, preserving the `ArDefaultResolver` 16 | search-path based resolution behaviour for path based references. 17 | 18 | ## Example 19 | 20 | ```usd 21 | def "ParkingLot" 22 | { 23 | def "ParkingLot_Floor_1" ( 24 | references = @bal:///floor@ 25 | ) 26 | { 27 | } 28 | } 29 | ``` 30 | 31 | An asset management system's OpenAssetIO entity reference can be used 32 | anywhere the `@@` syntax is supported. In this case, a reference to 33 | an asset managed by our test manager, the [Basic Asset 34 | Library](https://github.com/OpenAssetIO/OpenAssetIO-Manager-BAL) is used. 35 | 36 | ## How entities are resolved 37 | 38 | When USD creates an instance of the resolver, The default OpenAssetIO 39 | manager will be initialized - see the 40 | [docs](https://openassetio.github.io/OpenAssetIO/glossary.html#default_config_var) 41 | for more on this mechanism. 42 | 43 | The plugin then resolves the [`LocatableContentTrait`](https://github.com/OpenAssetIO/OpenAssetIO-MediaCreation/blob/659e641ce7e4dba6c5c6508c30b484fa31c1d61a/traits.yml#L54) 44 | for each string that the configured manager claims as a reference, and 45 | passes this path on for loading. 46 | 47 | > **Note:** 48 | > The `LocatableContentTrait` dictates that the resolved `location` 49 | > should be an absolute path, and so the default USD search path 50 | > mechanism will have no effect on the resolved result. 51 | 52 | Asset variation based on the parent asset (`anchorAssetPath`) has not 53 | yet been implemented, but will be added at a later date. 54 | 55 | ## Project status 56 | 57 | This resolver is currently in prototype stage, it has several key 58 | limitations. 59 | 60 | - Python is currently required whilst the remaining work porting the 61 | core OpenAssetIO API to C++ is completed. 62 | 63 | - `managementPolicy` is not checked, and so the configured manager will 64 | always be queried for each reference during stage composition. 65 | 66 | - Only the `LocatableContentTrait` is resolved. File extensions and file 67 | modification times will are based on file-based fallbacks if possible, 68 | and return sensible defaults if not. Many potentially expected 69 | structures (ie, `AssetInfo`), will be empty. 70 | 71 | - There is no USD locale set in the OpenAssetIO context. 72 | 73 | - Only read workflows are supported. Methods related to writing data 74 | fall back to the `ArDefaultResolver`. 75 | 76 | - Error handling is as yet quite primitive, an incomplete configuration 77 | may provide cryptic and hard to understand errors. You are advised to 78 | be extra sure all your environment variables are setup correctly. 79 | 80 | - The implementation has in not been optimized for performance. 81 | 82 | ## Dependencies 83 | 84 | ### [OpenAssetIO](https://github.com/OpenAssetIO/OpenAssetIO/) (1.0.0-beta.2.0) 85 | 86 | The OpenAssetIO libary is available pre-built for some common platforms. 87 | These are available 88 | [here](https://github.com/OpenAssetIO/OpenAssetIO/releases). 89 | 90 | Alternatively, OpenAssetIO can be built from source. The steps to do 91 | this can be found 92 | [here](https://github.com/OpenAssetIO/OpenAssetIO/blob/main/doc/BUILDING.md). 93 | 94 | ### [USD](https://github.com/PixarAnimationStudios/USD) (22.11) 95 | 96 | Install USD by whatever means, the most straightforward being to check 97 | out the repo and use the provided 98 | [build_usd.py](https://github.com/PixarAnimationStudios/USD/tree/release/build_scripts) 99 | script. If you elect to install USD to a custom location, remember to 100 | take a note of it, so you can pass it to `CMAKE_PREFIX_PATH` below. 101 | 102 | The specific versions listed for these dependencies are simply the 103 | versions that the resolver was tested against during development, it's 104 | possible other versions will function. 105 | 106 | ## Building 107 | 108 | ```sh 109 | cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/openassetio/dist/;/path/to/USD 110 | cmake --build build 111 | cmake --install build 112 | ``` 113 | 114 | ## Running 115 | 116 | To enable the resolver, before running any USD application, you must set 117 | the `PXR_PLUGINPATH_NAME` environment variable to point to 118 | `plugInfo.json`. 119 | 120 | You also need to configure `OpenAssetIO` with a manager. Use the 121 | [OPENASSETIO_DEFAULT_CONFIG](https://openassetio.github.io/OpenAssetIO/glossary.html#default_config_var) 122 | variable. 123 | 124 | ```sh 125 | export PXR_PLUGINPATH_NAME=$(pwd)/build/dist/resources/plugInfo.json 126 | export OPENASSETIO_DEFAULT_CONFIG=path/to/config/openassetio.conf 127 | usdcat yourUsdFile.usd 128 | ``` 129 | 130 | > **Note** 131 | > 132 | > Depending on you install mechanism, you may also need to extend your 133 | > system paths (eg `LD_LIBRARY_PATH` and `PYTHONPATH`) to reference 134 | >`OpenAssetIO` and `Usd`. 135 | > 136 | > For an example of this, and a whole build/run configuration, see 137 | > [test.yml](.github/workflows/test.yml), which utilizes the 138 | > [openassetio-build](https://github.com/openassetio/OpenAssetIO/pkgs/container/openassetio-build) 139 | > and [ci-vfxall](https://hub.docker.com/r/aswf/ci-vfxall) Docker 140 | > containers to manage dependencies and install/run the resolver. 141 | 142 | ## Debug logging 143 | 144 | Before running any USD application 145 | 146 | ```sh 147 | export TF_DEBUG=OPENASSETIO_RESOLVER 148 | export OPENASSETIO_LOGGING_SEVERITY=1 149 | ``` 150 | 151 | To enable debug logging from the resolver. 152 | 153 | ## Testing 154 | 155 | To run tests, once built, from the project root: 156 | 157 | ```sh 158 | python -m pip install -r requirements.txt 159 | python -m pytest 160 | ``` 161 | 162 | > **Note** 163 | > 164 | > Refer to the [Running](#running) section for the environmental 165 | > prerequisites to run these tests. The tests will set 166 | > `OPENASSETIO_DEFAULT_CONFIG` appropriately, and unless otherwise 167 | > defined, attempt to set `PXR_PLUGINPATH_NAME` if the standard `build` 168 | > directory was used. 169 | 170 | ## A note on Python 171 | 172 | One of the goals of OpenAssetIO is to provide a flexible API surface for 173 | a variety of production use cases. We have seen many situations where 174 | asset management code is only present in interpreted languages such as 175 | Python. 176 | 177 | Python however, has a huge performance impact due to its use of the GIL. 178 | 179 | There has been significant interest in the ability to use Python-based 180 | code within the USD context. OpenAssetIO allows managers to write their 181 | code in either Python, or C/C++ depending on the performance 182 | characteristics required. 183 | 184 | This plugin facilitates code in either language to be used within USD. 185 | 186 | We _fully understand the concerns this may bring_, especially in the 187 | content of real-world production at scale, and plan to tackle this on 188 | several fronts: 189 | 190 | - _OpenAssetIO operates without Python in the case that C/C++ 191 | implementations of required methods are provided._ 192 | - OpenAssetIO will provide an (optional) out-of-process Python 193 | interpreter to avoid UI thread locking when the host tool uses python 194 | for its user interface. 195 | - OpenAssetIO allows for mixed implementations, such that high call 196 | volume methods such as `resolve` can be written in C++, and low volume 197 | methods (eg: `register`) can be implemented in Python. 198 | -------------------------------------------------------------------------------- /cmake/CompilerWarnings.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2013-2022 The Foundry Visionmongers Ltd 3 | 4 | function(openassetio_usdresolver_set_default_compiler_warnings target_name) 5 | 6 | set(CLANG_WARNINGS 7 | -Wall 8 | # Reasonable and standard. 9 | -Wextra 10 | # Warn the user if a variable declaration shadows one from a 11 | # parent context. 12 | -Wshadow 13 | # Warn the user if a class with virtual functions has a 14 | # non-virtual destructor. This helps catch hard to track down 15 | # memory errors. 16 | -Wnon-virtual-dtor 17 | # Warn for c-style casts. 18 | -Wold-style-cast 19 | # Warn for potential performance problem casts. 20 | -Wcast-align 21 | # Warn on anything being unused. 22 | -Wunused 23 | # Warn if you overload (not override) a virtual function. 24 | -Woverloaded-virtual 25 | # Warn if non-standard C++ is used. 26 | -Wpedantic 27 | # Warn on type conversions that may lose data. 28 | -Wconversion 29 | # Warn on sign conversions. 30 | -Wsign-conversion 31 | # Warn if a null dereference is detected. 32 | -Wnull-dereference 33 | # Warn if float is implicit promoted to double. 34 | -Wdouble-promotion 35 | # Warn on security issues around functions that format output 36 | # (ie printf). 37 | -Wformat=2 38 | # Warn on statements that fallthrough without an explicit 39 | # annotation. 40 | -Wimplicit-fallthrough) 41 | 42 | if (OPENASSETIO_USDRESOLVER_WARNINGS_AS_ERRORS) 43 | set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) 44 | set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX) 45 | endif () 46 | 47 | set(GCC_WARNINGS 48 | ${CLANG_WARNINGS} 49 | # Warn if indentation implies blocks where blocks do not exist. 50 | -Wmisleading-indentation 51 | # Warn if if / else chain has duplicated conditions. 52 | -Wduplicated-cond 53 | # Warn if if / else branches have duplicated code. 54 | -Wduplicated-branches 55 | # Warn about logical operations being used where bitwise were 56 | # probably wanted. 57 | -Wlogical-op 58 | # Warn if you perform a cast to the same type. 59 | -Wuseless-cast) 60 | 61 | if (MSVC) 62 | set(PROJECT_WARNINGS ${MSVC_WARNINGS}) 63 | message(AUTHOR_WARNING 64 | "Compiler warnings need configuring for '${CMAKE_CXX_COMPILER_ID}' compiler.") 65 | elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 66 | set(PROJECT_WARNINGS ${CLANG_WARNINGS}) 67 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 68 | set(PROJECT_WARNINGS ${GCC_WARNINGS}) 69 | else () 70 | message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") 71 | endif () 72 | 73 | target_compile_options(${target_name} PRIVATE ${PROJECT_WARNINGS}) 74 | 75 | endfunction() 76 | -------------------------------------------------------------------------------- /cmake/DefaultTargetProperties.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2013-2024 The Foundry Visionmongers Ltd 3 | 4 | include(CompilerWarnings) 5 | 6 | function(openassetio_usdresolver_set_default_target_properties target_name) 7 | #------------------------------------------------------------------- 8 | # C++ standard 9 | 10 | # Minimum C++ standard as per current VFX reference platform CY23+. 11 | target_compile_features(${target_name} PRIVATE cxx_std_17) 12 | 13 | set_target_properties( 14 | ${target_name} 15 | PROPERTIES 16 | # Ensure the proposed compiler supports our minimum C++ 17 | # standard. 18 | CXX_STANDARD_REQUIRED ON 19 | # Disable compiler extensions. E.g. use -std=c++11 instead of 20 | # -std=gnu++11. Helps limit cross-platform issues. 21 | CXX_EXTENSIONS OFF 22 | ) 23 | 24 | #------------------------------------------------------------------- 25 | # Compiler warnings 26 | openassetio_usdresolver_set_default_compiler_warnings(${target_name}) 27 | 28 | #------------------------------------------------------------------- 29 | # Symbol visibility 30 | 31 | # Hide symbols from this library by default. 32 | set_target_properties( 33 | ${target_name} 34 | PROPERTIES 35 | C_VISIBILITY_PRESET hidden 36 | CXX_VISIBILITY_PRESET hidden 37 | VISIBILITY_INLINES_HIDDEN YES 38 | ) 39 | 40 | # Hide all symbols from external statically linked libraries. 41 | if (IS_GCC_OR_CLANG AND NOT APPLE) 42 | # TODO(TC): Find a way to hide symbols on macOS 43 | target_link_options(${target_name} PRIVATE "-Wl,--exclude-libs,ALL") 44 | endif () 45 | 46 | #------------------------------------------------------------------- 47 | # Library version 48 | 49 | get_target_property(target_type ${target_name} TYPE) 50 | 51 | if (NOT ${target_type} STREQUAL EXECUTABLE) 52 | # When building or installing appropriate symlinks are created, if 53 | # supported. 54 | set_target_properties( 55 | ${target_name} 56 | PROPERTIES 57 | VERSION ${PROJECT_VERSION} 58 | SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 59 | ) 60 | endif () 61 | 62 | #------------------------------------------------------------------- 63 | # Linters/analyzers 64 | 65 | if (TARGET openassetio-usdresolver-cpplint) 66 | add_dependencies(${target_name} openassetio-usdresolver-cpplint) 67 | endif () 68 | 69 | if (TARGET openassetio-usdresolver-clangformat) 70 | add_dependencies(${target_name} openassetio-usdresolver-clangformat) 71 | endif () 72 | 73 | endfunction() 74 | -------------------------------------------------------------------------------- /cmake/StaticAnalyzers.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2013-2022 The Foundry Visionmongers Ltd 3 | 4 | macro(enable_clang_tidy) 5 | find_program(OPENASSETIO_USDRESOLVER_CLANGTIDY_EXE NAMES clang-tidy clang-tidy-12) 6 | 7 | if (OPENASSETIO_USDRESOLVER_CLANGTIDY_EXE) 8 | # Construct the clang-tidy command line 9 | set(CMAKE_CXX_CLANG_TIDY ${OPENASSETIO_USDRESOLVER_CLANGTIDY_EXE}) 10 | # Ignore unknown compiler flag check, otherwise e.g. GCC-only 11 | # compiler warning flags will cause the build to fail. 12 | list(APPEND CMAKE_CXX_CLANG_TIDY -extra-arg=-Wno-unknown-warning-option) 13 | 14 | # Set standard 15 | if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "") 16 | if ("${CMAKE_CXX_CLANG_TIDY_DRIVER_MODE}" STREQUAL "cl") 17 | list(APPEND CMAKE_CXX_CLANG_TIDY -extra-arg=/std:c++${CMAKE_CXX_STANDARD}) 18 | else () 19 | list(APPEND CMAKE_CXX_CLANG_TIDY -extra-arg=-std=c++${CMAKE_CXX_STANDARD}) 20 | endif () 21 | endif () 22 | else () 23 | message(FATAL_ERROR "clang-tidy requested but executable not found") 24 | endif () 25 | endmacro() 26 | 27 | macro(enable_cpplint) 28 | find_program(OPENASSETIO_USDRESOLVER_CPPLINT_EXE cpplint) 29 | if (OPENASSETIO_USDRESOLVER_CPPLINT_EXE) 30 | # Create a custom target to be added as a dependency to other 31 | # targets. Unfortunately the CMAKE_CXX_CPPLINT integration is 32 | # somewhat lacking - it won't fail the build and it won't check 33 | # headers. So we must roll our own target. 34 | add_custom_target( 35 | openassetio-usdresolver-cpplint 36 | COMMAND ${CMAKE_COMMAND} -E echo "Executing cpplint check..." 37 | COMMAND 38 | ${OPENASSETIO_USDRESOLVER_CPPLINT_EXE} 39 | # The default "build/include_order" check suffers from 40 | # false positives since the default behaviour is to assume 41 | # that all ``-like includes are C headers. 42 | # `standardcfirst` instead uses an allow-list of known C 43 | # headers. Annoyingly, this option is not supported in 44 | # the CPPLINT.cfg config file. 45 | --includeorder=standardcfirst 46 | --recursive 47 | ${PROJECT_SOURCE_DIR}/src 48 | ${PROJECT_SOURCE_DIR}/tests 49 | ) 50 | 51 | else () 52 | message(FATAL_ERROR "cpplint requested but executable not found") 53 | endif () 54 | endmacro() 55 | 56 | macro(enable_clang_format) 57 | find_program(OPENASSETIO_USDRESOLVER_CLANGFORMAT_EXE NAMES clang-format clang-format-12) 58 | if (OPENASSETIO_USDRESOLVER_CLANGFORMAT_EXE) 59 | file( 60 | GLOB_RECURSE _sources 61 | LIST_DIRECTORIES false 62 | CONFIGURE_DEPENDS # Ensure we re-scan if files change. 63 | ${PROJECT_SOURCE_DIR}/src/*.[ch]pp 64 | ${PROJECT_SOURCE_DIR}/src/*.[ch] 65 | ) 66 | 67 | # Create a custom target to be added as a dependency to other 68 | # targets. 69 | add_custom_target( 70 | openassetio-usdresolver-clangformat 71 | COMMAND ${CMAKE_COMMAND} -E echo "Executing clang-format check..." 72 | COMMAND 73 | ${OPENASSETIO_USDRESOLVER_CLANGFORMAT_EXE} 74 | --Werror --dry-run --style=file 75 | ${_sources} 76 | ) 77 | 78 | else () 79 | message(FATAL_ERROR "clang-format requested but executable not found") 80 | endif () 81 | endmacro() 82 | -------------------------------------------------------------------------------- /resources/build/linter-requirements.txt: -------------------------------------------------------------------------------- 1 | cpplint==1.5.5 2 | black==24.3.0 3 | pylint==2.17.2 4 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set(PLUGIN_NAME usdOpenAssetIOResolver) 3 | 4 | set( 5 | SRC 6 | resolver.cpp 7 | ) 8 | 9 | add_library(${PLUGIN_NAME} 10 | SHARED 11 | ${SRC} 12 | ) 13 | 14 | target_link_libraries(${PLUGIN_NAME} 15 | PRIVATE 16 | ar 17 | OpenAssetIO::openassetio-core 18 | OpenAssetIO::openassetio-python-bridge 19 | OpenAssetIO-MediaCreation::openassetio-mediacreation 20 | ) 21 | 22 | #----------------------------------------------------------------------- 23 | # Activate warnings as errors, pedantic, etc. 24 | openassetio_usdresolver_set_default_target_properties(${PLUGIN_NAME}) 25 | 26 | # ---------------------------------------------------------------------- 27 | # Silence warnings about deprecation from USD itself 28 | # At time of writing, from : from USD/include/pxr/base/tf/hashset.h:39 29 | target_compile_options(${PLUGIN_NAME} PRIVATE -Wno-deprecated) 30 | 31 | #----------------------------------------------------------------------- 32 | # Main install 33 | install( 34 | TARGETS 35 | ${PLUGIN_NAME} 36 | DESTINATION 37 | . 38 | ) 39 | 40 | #----------------------------------------------------------------------- 41 | # Install plugInfo.json 42 | install( 43 | FILES 44 | resources/plugInfo.json 45 | DESTINATION 46 | ./resources 47 | ) 48 | -------------------------------------------------------------------------------- /src/resolver.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | // Copyright 2023 The Foundry Visionmongers Ltd 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | // NOLINTNEXTLINE 27 | PXR_NAMESPACE_USING_DIRECTIVE 28 | PXR_NAMESPACE_OPEN_SCOPE 29 | TF_DEBUG_CODES(OPENASSETIO_RESOLVER) 30 | PXR_NAMESPACE_CLOSE_SCOPE 31 | 32 | namespace { 33 | /* 34 | * OpenAssetIO LoggerInterface implementation 35 | * 36 | * Converter logger from OpenAssetIO log framing to USD log outputs. 37 | */ 38 | class UsdOpenAssetIOResolverLogger final : public openassetio::log::LoggerInterface { 39 | public: 40 | void log(const Severity severity, const openassetio::Str &message) override { 41 | switch (severity) { 42 | case Severity::kCritical: 43 | TF_ERROR(TfDiagnosticType::TF_DIAGNOSTIC_FATAL_ERROR_TYPE, message); 44 | break; 45 | case Severity::kDebug: 46 | case Severity::kDebugApi: 47 | TF_DEBUG(OPENASSETIO_RESOLVER).Msg(message + "\n"); 48 | break; 49 | case Severity::kError: 50 | TF_ERROR(TfDiagnosticType::TF_DIAGNOSTIC_NONFATAL_ERROR_TYPE, message); 51 | break; 52 | case Severity::kInfo: 53 | case Severity::kProgress: 54 | TF_INFO(OPENASSETIO_RESOLVER).Msg(message + "\n"); 55 | break; 56 | case Severity::kWarning: 57 | TF_WARN(TfDiagnosticType::TF_DIAGNOSTIC_WARNING_TYPE, message); 58 | break; 59 | } 60 | } 61 | }; 62 | 63 | /** 64 | * OpenAssetIO HostInterface implementation 65 | * 66 | * This identifies the Ar2 plugin uniquely should the manager plugin 67 | * wish to adapt its behaviour. 68 | */ 69 | class UsdOpenAssetIOHostInterface final : public openassetio::hostApi::HostInterface { 70 | public: 71 | [[nodiscard]] openassetio::Identifier identifier() const override { 72 | return "org.openassetio.usdresolver"; 73 | } 74 | 75 | [[nodiscard]] openassetio::Str displayName() const override { 76 | return "OpenAssetIO USD Resolver"; 77 | } 78 | }; 79 | 80 | } // namespace 81 | 82 | // --------------------------------------------------------------------- 83 | 84 | /* 85 | * Ar Resolver Implementation 86 | */ 87 | class UsdOpenAssetIOResolver final : public PXR_NS::ArDefaultResolver { 88 | public: 89 | UsdOpenAssetIOResolver() { 90 | logger_ = 91 | openassetio::log::SeverityFilter::make(std::make_shared()); 92 | // Python plugin system. 93 | const auto pythonManagerImplementationFactory = 94 | openassetio::python::hostApi::createPythonPluginSystemManagerImplementationFactory( 95 | logger_); 96 | // C++ plugin system. 97 | const auto cppManagerImplementationFactory = 98 | openassetio::pluginSystem::CppPluginSystemManagerImplementationFactory::make(logger_); 99 | // Combined Python/C++ plugin system. Note: C++ is listed first so 100 | // has priority. 101 | const auto hybridManagerImplementationFactory = 102 | openassetio::pluginSystem::HybridPluginSystemManagerImplementationFactory::make( 103 | {cppManagerImplementationFactory, pythonManagerImplementationFactory}, logger_); 104 | const auto hostInterface = std::make_shared(); 105 | // Find the plugin configured using the OPENASSETIO_DEFAULT_CONFIG 106 | // file, initialise it, and create the host-facing Manager 107 | // middleware for us to communicate with it. 108 | manager_ = openassetio::hostApi::ManagerFactory::defaultManagerForInterface( 109 | hostInterface, hybridManagerImplementationFactory, logger_); 110 | if (!manager_) { 111 | throw std::invalid_argument{ 112 | "No default manager configured, " + 113 | openassetio::hostApi::ManagerFactory::kDefaultManagerConfigEnvVarName}; 114 | } 115 | // This USD plugin is useless unless the manager plugin has the 116 | // basic ability to `resolve(...)`. 117 | if (!manager_->hasCapability(openassetio::hostApi::Manager::Capability::kResolution)) { 118 | throw std::invalid_argument{manager_->displayName() + 119 | " is not capable of resolving entity references"}; 120 | } 121 | context_ = openassetio::Context::make(); 122 | } 123 | 124 | ~UsdOpenAssetIOResolver() override = default; 125 | 126 | protected: 127 | [[nodiscard]] std::string _CreateIdentifier( 128 | const std::string &assetPath, const ArResolvedPath &anchorAssetPath) const override { 129 | return catchAndLogExceptions( 130 | [&] { 131 | std::string identifier; 132 | if (manager_->isEntityReferenceString(assetPath)) { 133 | identifier = assetPath; 134 | } else { 135 | identifier = ArDefaultResolver::_CreateIdentifier(assetPath, anchorAssetPath); 136 | } 137 | return identifier; 138 | }, 139 | TF_FUNC_NAME()); 140 | } 141 | 142 | [[nodiscard]] ArResolvedPath _Resolve(const std::string &assetPath) const override { 143 | return catchAndLogExceptions( 144 | [&] { 145 | if (const auto entityReference = manager_->createEntityReferenceIfValid(assetPath)) { 146 | return ArResolvedPath{resolveToPath(*entityReference)}; 147 | } 148 | return ArDefaultResolver::_Resolve(assetPath); 149 | }, 150 | TF_FUNC_NAME()); 151 | } 152 | 153 | [[nodiscard]] std::string _CreateIdentifierForNewAsset( 154 | const std::string &assetPath, const ArResolvedPath &anchorAssetPath) const override { 155 | if (manager_->isEntityReferenceString(assetPath)) { 156 | std::string message = "Writes to OpenAssetIO entity references are not currently supported "; 157 | message += assetPath; 158 | logger_->critical(message); 159 | return ""; 160 | } 161 | return ArDefaultResolver::_CreateIdentifierForNewAsset(assetPath, anchorAssetPath); 162 | } 163 | 164 | [[nodiscard]] ArResolvedPath _ResolveForNewAsset(const std::string &assetPath) const override { 165 | if (manager_->isEntityReferenceString(assetPath)) { 166 | std::string message = "Writes to OpenAssetIO entity references are not currently supported "; 167 | message += assetPath; 168 | logger_->critical(message); 169 | return ArResolvedPath(""); 170 | } 171 | return ArDefaultResolver::_ResolveForNewAsset(assetPath); 172 | } 173 | 174 | [[nodiscard]] std::string _GetExtension(const std::string &assetPath) const override { 175 | return ArDefaultResolver::_GetExtension(assetPath); 176 | } 177 | 178 | [[nodiscard]] ArAssetInfo _GetAssetInfo(const std::string &assetPath, 179 | const ArResolvedPath &resolvedPath) const override { 180 | return ArDefaultResolver::_GetAssetInfo(assetPath, resolvedPath); 181 | } 182 | 183 | [[nodiscard]] ArTimestamp _GetModificationTimestamp( 184 | const std::string &assetPath, const ArResolvedPath &resolvedPath) const override { 185 | return ArDefaultResolver::_GetModificationTimestamp(assetPath, resolvedPath); 186 | } 187 | 188 | [[nodiscard]] std::shared_ptr _OpenAsset( 189 | const ArResolvedPath &resolvedPath) const override { 190 | return ArDefaultResolver::_OpenAsset(resolvedPath); 191 | } 192 | 193 | [[nodiscard]] bool _CanWriteAssetToPath(const ArResolvedPath &resolvedPath, 194 | std::string *whyNot) const override { 195 | return ArDefaultResolver::_CanWriteAssetToPath(resolvedPath, whyNot); 196 | } 197 | 198 | [[nodiscard]] std::shared_ptr _OpenAssetForWrite( 199 | const ArResolvedPath &resolvedPath, const WriteMode writeMode) const override { 200 | return ArDefaultResolver::_OpenAssetForWrite(resolvedPath, writeMode); 201 | } 202 | 203 | private: 204 | /** 205 | * Retrieve the resolved file path of an entity reference. 206 | * 207 | * This will resolve the "locateableContent" trait of the entity and 208 | * return the "location" property of it, converted from a URL to a 209 | * file path. 210 | * 211 | * @param entityReference The reference to resolve. 212 | * @return Resolved file path. 213 | */ 214 | [[nodiscard]] std::string resolveToPath( 215 | const openassetio::EntityReference &entityReference) const { 216 | using openassetio::access::ResolveAccess; 217 | using openassetio_mediacreation::traits::content::LocatableContentTrait; 218 | 219 | // Resolve the locatable content trait, this will provide a URL 220 | // that points to the final content 221 | const openassetio::trait::TraitsDataPtr traitsData = manager_->resolve( 222 | entityReference, {LocatableContentTrait::kId}, ResolveAccess::kRead, context_); 223 | 224 | const std::optional url = LocatableContentTrait(traitsData).getLocation(); 225 | if (!url) { 226 | throw std::invalid_argument{"Entity reference does not have a location: " + 227 | entityReference.toString()}; 228 | } 229 | // OpenAssetIO is URL based, but we need a path. Note: will throw if 230 | // the URL is not valid. 231 | return fileUrlPathConverter_.pathFromUrl(*url); 232 | } 233 | 234 | /** 235 | * Decorator to stop propagation of all exceptions. 236 | * 237 | * Exceptions occurring within the wrapped callable will be caught and 238 | * logged, and a default-constructed value (of the same type as the 239 | * callable's return type) returned instead of propagating the 240 | * exception. 241 | * 242 | * The callable must take no arguments (but may return a value). 243 | * 244 | * This is needed since USD reacts badly if an exception escapes an Ar 245 | * plugin (segfault, sigabrt). 246 | * 247 | * @tparam Fn Callable type. 248 | * @param func Callable instance. 249 | * @param name Name of function/process that caused the exception, to 250 | * append to log messages. 251 | * @return Result of callable if no exception occurred, otherwise a 252 | * default-constructed object. 253 | */ 254 | template 255 | auto catchAndLogExceptions(Fn &&func, const std::string_view name) const 256 | -> std::invoke_result_t { 257 | try { 258 | return func(); 259 | } catch (const std::exception &exc) { 260 | std::string msg = "OpenAssetIO error in "; 261 | msg += name; 262 | msg += ": "; 263 | msg += exc.what(); 264 | logger_->critical(msg); 265 | } catch (...) { 266 | std::string msg = "OpenAssetIO error in "; 267 | msg += name; 268 | msg += ": unknown non-exception type caught"; 269 | logger_->critical(msg); 270 | } 271 | return {}; 272 | } 273 | 274 | openassetio::log::LoggerInterfacePtr logger_; 275 | openassetio::hostApi::ManagerPtr manager_; 276 | openassetio::ContextConstPtr context_; 277 | openassetio::utils::FileUrlPathConverter fileUrlPathConverter_; 278 | }; 279 | 280 | PXR_NAMESPACE_OPEN_SCOPE 281 | AR_DEFINE_RESOLVER(UsdOpenAssetIOResolver, ArResolver) 282 | PXR_NAMESPACE_CLOSE_SCOPE 283 | -------------------------------------------------------------------------------- /src/resources/plugInfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "Plugins": [ 3 | { 4 | "Info": { 5 | "Types": { 6 | "UsdOpenAssetIOResolver": { 7 | "bases": [ 8 | "ArResolver" 9 | ] 10 | } 11 | } 12 | }, 13 | "LibraryPath": "../libusdOpenAssetIOResolver.so", 14 | "Name": "usdOpenAssetIOResolver", 15 | "Type": "library" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | pytest==6.2.4 2 | # pytest plugin that adds @pytest.mark.forked to flag a test that should 3 | # run in a forked subprocess. Useful for testing global initialization 4 | # code paths. 5 | pytest-forked==1.6.0 6 | git+https://github.com/OpenAssetIO/OpenAssetIO-Manager-BAL.git -------------------------------------------------------------------------------- /tests/resources/empty_shot.usda: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | 3 | def "World" 4 | { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/assetized_child_ref_non_assetized_grandchild/car.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "Car" 3 | { 4 | color3f color = (0, 0, 0) 5 | } -------------------------------------------------------------------------------- /tests/resources/integration_test_data/assetized_child_ref_non_assetized_grandchild/floor1.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "ParkingLot_Floor" 3 | { 4 | def "Car1" ( 5 | references = @car.usd@ 6 | ) 7 | { 8 | } 9 | def "Car2" ( 10 | references = @car.usd@ 11 | ) 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/assetized_child_ref_non_assetized_grandchild/parking_lot.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | 3 | def "ParkingLot" 4 | { 5 | def "ParkingLot_Floor_1" ( 6 | references = @bal:///assetized_child_ref_non_assetized_grandchild/floor@ 7 | ) 8 | { 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/bal_library.json: -------------------------------------------------------------------------------- 1 | { 2 | "entities": { 3 | "assetized_child_ref_non_assetized_grandchild/floor": { 4 | "versions": [ 5 | { 6 | "traits": { 7 | "openassetio-mediacreation:content.LocatableContent": { 8 | "location": "file://${bal_library_dir}/assetized_child_ref_non_assetized_grandchild/floor1.usd" 9 | } 10 | } 11 | } 12 | ] 13 | }, 14 | "non_assetized_child_ref_assetized_grandchild/car": { 15 | "versions": [ 16 | { 17 | "traits": { 18 | "openassetio-mediacreation:content.LocatableContent": { 19 | "location": "file://${bal_library_dir}/non_assetized_child_ref_assetized_grandchild/car.usd" 20 | } 21 | } 22 | } 23 | ] 24 | }, 25 | "recursive_assetized_resolve/floor": { 26 | "versions": [ 27 | { 28 | "traits": { 29 | "openassetio-mediacreation:content.LocatableContent": { 30 | "location": 31 | "file://${bal_library_dir}/recursive_assetized_resolve/floors/floor%20%40%201.usd" 32 | } 33 | } 34 | } 35 | ] 36 | }, 37 | "recursive_assetized_resolve/car": { 38 | "versions": [ 39 | { 40 | "traits": { 41 | "openassetio-mediacreation:content.LocatableContent": { 42 | "location": "file://${bal_library_dir}/recursive_assetized_resolve/cars/car.usd" 43 | } 44 | } 45 | } 46 | ] 47 | }, 48 | "not_a_file": { 49 | "versions": [ 50 | { 51 | "traits": { 52 | "openassetio-mediacreation:content.LocatableContent": { 53 | "location": "https://stuffonmycat.com" 54 | } 55 | } 56 | } 57 | ] 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/bal_library_incapable.json: -------------------------------------------------------------------------------- 1 | { 2 | "capabilities": [ 3 | "entityReferenceIdentification", 4 | "managementPolicyQueries", 5 | "entityTraitIntrospection" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/error_triggering_asset_ref/parking_lot.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | 3 | def "ParkingLot" 4 | { 5 | def "ParkingLot_Floor_1" ( 6 | references = @bal:///doesntexist@ 7 | ) 8 | { 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/non_assetized_child_ref_assetized_grandchild/car.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "Car" 3 | { 4 | color3f color = (0, 0, 0) 5 | } -------------------------------------------------------------------------------- /tests/resources/integration_test_data/non_assetized_child_ref_assetized_grandchild/floor1.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "ParkingLot_Floor" 3 | { 4 | def "Car1" ( 5 | references = @bal:///non_assetized_child_ref_assetized_grandchild/car@ 6 | ) 7 | { 8 | } 9 | def "Car2" ( 10 | references = @bal:///non_assetized_child_ref_assetized_grandchild/car@ 11 | ) 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/non_assetized_child_ref_assetized_grandchild/parking_lot.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | 3 | def "ParkingLot" 4 | { 5 | def "ParkingLot_Floor_1" ( 6 | references = @floor1.usd@ 7 | ) 8 | { 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/recursive_assetized_resolve/cars/car.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "Car" 3 | { 4 | color3f color = (0, 0, 0) 5 | } -------------------------------------------------------------------------------- /tests/resources/integration_test_data/recursive_assetized_resolve/floors/floor @ 1.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "ParkingLot_Floor" 3 | { 4 | def "Car1" ( 5 | references = @bal:///recursive_assetized_resolve/car@ 6 | ) 7 | { 8 | } 9 | def "Car2" ( 10 | references = @bal:///recursive_assetized_resolve/car@ 11 | ) 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/recursive_assetized_resolve/parking_lot.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | 3 | def "ParkingLot" 4 | { 5 | def "ParkingLot_Floor_1" ( 6 | references = @bal:///recursive_assetized_resolve/floor@ 7 | ) 8 | { 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/resolver_has_no_effect_with_no_search_path/car.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "Car" 3 | { 4 | color3f color = (0, 0, 0) 5 | } -------------------------------------------------------------------------------- /tests/resources/integration_test_data/resolver_has_no_effect_with_no_search_path/floor1.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "ParkingLot_Floor" 3 | { 4 | def "Car1" ( 5 | references = @car.usd@ 6 | ) 7 | { 8 | } 9 | def "Car2" ( 10 | references = @car.usd@ 11 | ) 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/resolver_has_no_effect_with_no_search_path/parking_lot.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | 3 | def "ParkingLot" 4 | { 5 | def "ParkingLot_Floor_1" ( 6 | references = @floor1.usd@ 7 | ) 8 | { 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/resolver_has_no_effect_with_search_path/parking_lot.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | 3 | def "ParkingLot" 4 | { 5 | def "ParkingLot_Floor_1" ( 6 | references = @floors/floor1.usd@ 7 | ) 8 | { 9 | } 10 | } 11 | 12 | -------------------------------------------------------------------------------- /tests/resources/integration_test_data/resolver_has_no_effect_with_search_path/search_path_root/cars/car.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "Car" 3 | { 4 | color3f color = (0, 0, 0) 5 | } -------------------------------------------------------------------------------- /tests/resources/integration_test_data/resolver_has_no_effect_with_search_path/search_path_root/floors/floor1.usd: -------------------------------------------------------------------------------- 1 | #usda 1.0 2 | def "ParkingLot_Floor" 3 | { 4 | def "Car1" ( 5 | references = @cars/car.usd@ 6 | ) 7 | { 8 | } 9 | def "Car2" ( 10 | references = @cars/car.usd@ 11 | ) 12 | { 13 | } 14 | } -------------------------------------------------------------------------------- /tests/resources/openassetio_config_cpp.toml: -------------------------------------------------------------------------------- 1 | # This config sets up the SimpleCppManager C++ manager/plugin for use in 2 | # the main test cases. 3 | 4 | [manager] 5 | identifier = "org.openassetio.examples.manager.simplecppmanager" 6 | 7 | [manager.settings] 8 | # Pretend to be BasicAssetLibrary aka BAL. This is so a single set of 9 | # USD files can be used for both Python and C++ testing. 10 | prefix = "bal:///" 11 | 12 | read_traits = ''' 13 | bal:///not_a_file,openassetio-mediacreation:content.LocatableContent,location,https://stuffonmycat.com 14 | bal:///recursive_assetized_resolve/floor,openassetio-mediacreation:content.LocatableContent,location,file://${config_dir}/integration_test_data/recursive_assetized_resolve/floors/floor%20%40%201.usd 15 | bal:///recursive_assetized_resolve/car,openassetio-mediacreation:content.LocatableContent,location,file://${config_dir}/integration_test_data/recursive_assetized_resolve/cars/car.usd 16 | bal:///assetized_child_ref_non_assetized_grandchild/floor,openassetio-mediacreation:content.LocatableContent,location,file://${config_dir}/integration_test_data/assetized_child_ref_non_assetized_grandchild/floor1.usd 17 | bal:///non_assetized_child_ref_assetized_grandchild/car,openassetio-mediacreation:content.LocatableContent,location,file://${config_dir}/integration_test_data/non_assetized_child_ref_assetized_grandchild/car.usd 18 | ''' -------------------------------------------------------------------------------- /tests/resources/openassetio_config_cpp.toml.incapable: -------------------------------------------------------------------------------- 1 | # This config sets up the SimpleCppManager C++ manager/plugin without 2 | # the "resolution" capability, for use in the 3 | # `test_when_manager_cannot_resolve_then_exception_thrown` test case. 4 | 5 | [manager] 6 | identifier = "org.openassetio.examples.manager.simplecppmanager" 7 | 8 | [manager.settings] 9 | # Only the minimal set of capabilities required to load a plugin - i.e. 10 | # missing the "resolution" capability. 11 | capabilities="entityReferenceIdentification,managementPolicyQueries,entityTraitIntrospection" 12 | -------------------------------------------------------------------------------- /tests/resources/openassetio_config_python.toml: -------------------------------------------------------------------------------- 1 | # This config sets up the BasicAssetLibrary (aka BAL) Python 2 | # manager/plugin for use in the main test cases. 3 | 4 | [manager] 5 | identifier = "org.openassetio.examples.manager.bal" 6 | 7 | [manager.settings] 8 | library_path = "${config_dir}/integration_test_data/bal_library.json" 9 | -------------------------------------------------------------------------------- /tests/resources/openassetio_config_python.toml.incapable: -------------------------------------------------------------------------------- 1 | # This config sets up the BasicAssetLibrary (aka BAL) Python 2 | # manager/plugin without the "resolution" capability, for use in the 3 | # `test_when_manager_cannot_resolve_then_exception_thrown` test case. 4 | 5 | [manager] 6 | identifier = "org.openassetio.examples.manager.bal" 7 | 8 | [manager.settings] 9 | library_path = "${config_dir}/integration_test_data/bal_library_incapable.json" 10 | -------------------------------------------------------------------------------- /tests/test_resolver.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2023 The Foundry Visionmongers Ltd 3 | """ 4 | Tests for the OpenAssetIO USD Ar2 adapter. 5 | 6 | Note that OPENASSETIO_DEFAULT_CONFIG must point to a configuration file 7 | that in turn points to a manager plugin that will satisfy these tests. 8 | """ 9 | 10 | # pylint: disable=no-member,redefined-outer-name 11 | # pylint: disable=wrong-import-position,unused-import 12 | # pylint: disable=missing-function-docstring,missing-module-docstring 13 | 14 | import os 15 | from unittest import mock 16 | 17 | import pytest 18 | 19 | # This environment var must be set before the usd imports. 20 | os.environ["TF_DEBUG"] = "OPENASSETIO_RESOLVER" 21 | if "PXR_PLUGINPATH_NAME" not in os.environ: 22 | # Set up our resolver plugin if not already set up, and we can 23 | root_dir = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) 24 | plug_info = os.path.join(root_dir, "build", "dist", "resources", "pluginfo.json") 25 | if os.path.exists(plug_info): 26 | os.environ["PXR_PLUGINPATH_NAME"] = plug_info 27 | 28 | from pxr import Plug, Usd, Ar, Sdf, Tf 29 | 30 | 31 | # TODO(DF): More tests for error cases. 32 | 33 | 34 | # Assert that the USD resolver checks that the OpenAssetIO manager is 35 | # capable of `resolve`ing. 36 | # 37 | # Fork process so that the USD plugin is initialized again, but with 38 | # patched `hasCapability`. 39 | @pytest.mark.forked 40 | def test_when_manager_cannot_resolve_then_exception_thrown(monkeypatch): 41 | # Use config that removes the "resolution" capability from the 42 | # manager's advertised set of capabilities. 43 | monkeypatch.setenv( 44 | "OPENASSETIO_DEFAULT_CONFIG", 45 | os.environ["OPENASSETIO_DEFAULT_CONFIG"] + ".incapable", 46 | ) 47 | 48 | with pytest.raises( 49 | ValueError, 50 | match=".+ is not capable of resolving entity references", 51 | ): 52 | open_stage( 53 | "resources/integration_test_data/recursive_assetized_resolve/floors/floor 1.usd" 54 | ) 55 | 56 | 57 | # Given a USD document that references an asset via a direct relative 58 | # file path, then the asset is resolved to the file path as expected. 59 | def test_openassetio_resolver_has_no_effect_with_no_search_path(): 60 | stage = open_stage( 61 | "resources/integration_test_data/resolver_has_no_effect_with_no_search_path/parking_lot.usd" 62 | ) 63 | assert_parking_lot_structure(stage) 64 | 65 | 66 | # Given a USD document that references an asset via a relative 67 | # search-path based file path, then the asset is resolved to the file 68 | # path as expected. 69 | def test_openassetio_resolver_has_no_effect_with_search_path(): 70 | context = build_search_path_context( 71 | "resources/integration_test_data/resolver_has_no_effect_with_search_path/search_path_root" 72 | ) 73 | stage = open_stage( 74 | "resources/integration_test_data/resolver_has_no_effect_with_search_path/parking_lot.usd", 75 | context, 76 | ) 77 | 78 | assert_parking_lot_structure(stage) 79 | 80 | 81 | # Given a USD document that references a second level document via an 82 | # assetized reference resolvable by OpenAssetIO, and that second 83 | # level document containing an assetized reference resolvable by 84 | # OpenAssetIO to a third level document, and that the resolved paths 85 | # are search path based, then the document can be fully resolved. 86 | def test_recursive_assetized_resolve(): 87 | stage = open_stage( 88 | "resources/integration_test_data/recursive_assetized_resolve/parking_lot.usd" 89 | ) 90 | 91 | assert_parking_lot_structure(stage) 92 | 93 | 94 | # Given a USD document that references a second level document via an 95 | # assetized reference resolvable by OpenAssetIO, and that second level 96 | # document containing a non-assetized, adjacent relative file path 97 | # reference to a third level document, then the document can be fully 98 | # resolved. 99 | def test_assetized_child_ref_non_assetized_grandchild(): 100 | stage = open_stage( 101 | "resources/integration_test_data" 102 | "/assetized_child_ref_non_assetized_grandchild/parking_lot.usd" 103 | ) 104 | 105 | assert_parking_lot_structure(stage) 106 | 107 | 108 | # Given a USD document that references a second level document via an 109 | # non-assetized, adjacent relative file path reference, and that second 110 | # level document containing an assetized reference resolvable by 111 | # OpenAssetIO to a third level document, then the document can be fully 112 | # resolved. 113 | def test_non_assetized_child_ref_assetized_grandchild(): 114 | stage = open_stage( 115 | "resources/integration_test_data" 116 | "/non_assetized_child_ref_assetized_grandchild/parking_lot.usd" 117 | ) 118 | 119 | assert_parking_lot_structure(stage) 120 | 121 | 122 | # Will attempt to resolve `bal:///doesntexist` (i.e. a non-existent 123 | # entity), which will trigger an exception in the manager internals. 124 | def test_error_triggering_asset_ref(capfd): 125 | open_stage( 126 | "resources/integration_test_data/error_triggering_asset_ref/parking_lot.usd" 127 | ) 128 | 129 | logs = capfd.readouterr() 130 | assert "entityResolutionError" in logs.err 131 | 132 | 133 | def test_when_resolves_to_non_file_url_then_error(): 134 | with pytest.raises(Tf.ErrorException) as exc: 135 | Usd.Stage.Open("bal:///not_a_file") 136 | # The exception seems to be truncated which looses the specifics of 137 | # our message (doh!). Check at least we were in the stack 138 | assert "UsdOpenAssetIOResolverLogger" in str(exc) 139 | 140 | 141 | def test_when_writing_to_file_then_ok(capfd, tmp_path): 142 | Sdf.Layer.CreateNew(str(tmp_path / "newLayer.usda")) 143 | logs = capfd.readouterr() 144 | assert ( 145 | "Writes to OpenAssetIO entity references are not currently supported" 146 | not in logs.err 147 | ) 148 | 149 | 150 | def test_when_writing_to_entity_ref_then_error(): 151 | with pytest.raises(Tf.ErrorException) as exc: 152 | Sdf.Layer.CreateNew("bal:///newLayer") 153 | assert "Writes to OpenAssetIO entity references are not currently supported" in str( 154 | exc 155 | ) 156 | 157 | 158 | ##### Utility Functions ##### 159 | 160 | 161 | # Log openassetio resolver messages 162 | @pytest.fixture(autouse=True) 163 | def enable_openassetio_logging_debug(): 164 | os.environ["OPENASSETIO_LOGGING_SEVERITY"] = "1" 165 | 166 | 167 | # As all the data tends to follow the same form, convenience method 168 | # to avoid repeating myself 169 | def assert_parking_lot_structure(usd_stage): 170 | floor = usd_stage.GetPrimAtPath("/ParkingLot/ParkingLot_Floor_1") 171 | 172 | assert floor.IsValid() 173 | 174 | car1 = floor.GetChild("Car1") 175 | car2 = floor.GetChild("Car2") 176 | 177 | assert car1.IsValid() 178 | assert car2.IsValid() 179 | 180 | assert car1.GetPropertyNames() == ["color"] 181 | assert car2.GetPropertyNames() == ["color"] 182 | 183 | 184 | # Set the default resolver search path to a subdirectory 185 | # Done this way so that you can run the test from any directory, 186 | # otherwise the working directory will impact the file loading. 187 | def build_search_path_context(path_relative_from_file): 188 | script_dir = os.path.realpath(os.path.dirname(__file__)) 189 | full_path = os.path.join(script_dir, path_relative_from_file) 190 | return Ar.DefaultResolverContext([full_path]) 191 | 192 | 193 | # Open the stage 194 | # Done this way so that you can run the test from any directory, 195 | # otherwise the working directory will impact the file loading. 196 | def open_stage(path_relative_from_file, context=None): 197 | script_dir = os.path.realpath(os.path.dirname(__file__)) 198 | full_path = os.path.join(script_dir, path_relative_from_file) 199 | 200 | if context is not None: 201 | return Usd.Stage.Open(full_path, context) 202 | 203 | return Usd.Stage.Open(full_path) 204 | --------------------------------------------------------------------------------