diff --git a/build.sh b/build.sh index b1fe5f9..e7ff502 100755 --- a/build.sh +++ b/build.sh @@ -7,6 +7,7 @@ clear # Clear existing build data and invoke cmake rm -R build rm -R dist +set -e # Exit on error cmake . -B build cmake --build build --clean-first # make clean all cmake --install build # make install diff --git a/src/CachedResolver/PythonExpose.py b/src/CachedResolver/PythonExpose.py index 2debfd3..4b8203f 100644 --- a/src/CachedResolver/PythonExpose.py +++ b/src/CachedResolver/PythonExpose.py @@ -116,7 +116,7 @@ def _ResolveAnchored(anchorPath, path): class Resolver: @staticmethod @log_function_args - def ResolveAndCache(assetPath): + def ResolveAndCache(assetPath, context): """Return the resolved path for the given assetPath or an empty ArResolvedPath if no asset exists at that path. Args: @@ -124,6 +124,10 @@ def ResolveAndCache(assetPath): Returns: Ar.ResolvedPath: The resolved path. """ + + #raise Exception(">>>>>>>{}".format(dir(context))) + print(":::::::::::::::::::::::::::::::::::::::::::::::::: Context ->", context.GetMappingPairs()) + context.AddMappingPair("debug", "How cool is this!") return Ar.ResolvedPath("Debug Working") # if not assetPath: diff --git a/src/CachedResolver/resolver.cpp b/src/CachedResolver/resolver.cpp index 5cd76c2..9155b08 100644 --- a/src/CachedResolver/resolver.cpp +++ b/src/CachedResolver/resolver.cpp @@ -148,45 +148,53 @@ CachedResolver::_Resolve( if (ctx) { // Search for mapping pairs auto &mappingPairs = ctx->GetMappingPairs(); + auto map_find = mappingPairs.find(assetPath); if(map_find != mappingPairs.end()){ ArResolvedPath resolvedPath = _ResolveAnchored(this->emptyString, map_find->second); - if (resolvedPath) { - return resolvedPath; - } + return resolvedPath; + // Assume that a map hit is always valid. + // if (resolvedPath) { + // return resolvedPath; + // } } // Search for cached pairs auto &cachedPairs = ctx->GetCachedPairs(); auto cache_find = cachedPairs.find(assetPath); if(cache_find != cachedPairs.end()){ ArResolvedPath resolvedPath = _ResolveAnchored(this->emptyString, cache_find->second); - if (resolvedPath) { - return resolvedPath; - } + return resolvedPath; + // Assume that a cache hit is always valid. + // if (resolvedPath) { + // return resolvedPath; + // } } + // Perform query if caches don't have a hit. + std::string pythonResult; { - // Perform query if caches don't have a hit. /* We perform the resource/thread lock in the context itself to allow for resolver multithreading with different contexts Is this approach in general a hacky solution? Yes, we are circumventing C++'s - 'constants' mechanism by redirecting our queries into Python. This way we can modify our - 'const' read locked resolver context. While it works, be aware that potential side effects may occur. + 'constants' mechanism by redirecting our queries into Python in which we + write-access our Resolver Context. This way we can modify our 'const' C++ read + locked resolver context. While it works, be aware that potential side effects may occur. */ const std::lock_guard lock(g_resolver_query_mutex); TF_DEBUG(CACHEDRESOLVER_RESOLVER).Msg("Resolver::_Resolve('%s') -> No cache hit, switching to Python query\n", assetPath.c_str()); - ArResolvedPath pythonResult; + int state = TfPyInvokeAndExtract(DEFINE_STRING(AR_CACHEDRESOLVER_USD_PYTHON_EXPOSE_MODULE_NAME), "Resolver.ResolveAndCache", - &pythonResult, assetPath); + &pythonResult, assetPath, *ctx); if (!state) { - std::cerr << "Failed to call Resolver._Resolve in " << DEFINE_STRING(AR_CACHEDRESOLVER_USD_PYTHON_EXPOSE_MODULE_NAME) << ".py. "; + std::cerr << "Failed to call Resolver.ResolveAndCache in " << DEFINE_STRING(AR_CACHEDRESOLVER_USD_PYTHON_EXPOSE_MODULE_NAME) << ".py. "; std::cerr << "Please verify that the python code is valid!" << std::endl; } - if (pythonResult) { - return pythonResult; - } + } + ArResolvedPath resolvedPath = _ResolveAnchored(this->emptyString, pythonResult); + if (resolvedPath) { + return resolvedPath; } } } diff --git a/src/CachedResolver/testenv/testCachedResolver.py b/src/CachedResolver/testenv/testCachedResolver.py index 237955e..c6d443c 100644 --- a/src/CachedResolver/testenv/testCachedResolver.py +++ b/src/CachedResolver/testenv/testCachedResolver.py @@ -19,7 +19,9 @@ def setUpClass(cls): def test_debug(self): resolver = Ar.GetResolver() resolved_path = resolver.Resolve("debug") - raise Exception(">> {}".format(resolved_path.GetPathString())) + print("::::::::::::::::::::::::::::::::::::::: Result Call 1 ->", resolved_path) + resolved_path = resolver.Resolve("debug") + print("::::::::::::::::::::::::::::::::::::::: Result Call 2 ->", resolved_path) def _test_CreateIdentifier(self): resolver = Ar.GetResolver()