Skip to content

Commit 26a207d

Browse files
committed
Remove file exists check for CachedResolver resolved paths
1 parent fdd9a11 commit 26a207d

7 files changed

Lines changed: 57 additions & 83 deletions

File tree

src/CachedResolver/CMakeLists.txt

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ endif()
1010
### Targets ###
1111
## Target library > cachedResolver ##
1212
add_library(${AR_CACHEDRESOLVER_TARGET_LIB}
13-
SHARED
14-
debugCodes.cpp
15-
resolver.cpp
16-
resolverContext.cpp
17-
resolverTokens.cpp
18-
# Since when our resolver calls into Python it passes the ResolverContext,
19-
# we need to ensure that Python has loaded the ResolverContext C++ representation.
20-
# While we do have duplicate compiled code by adding the below, this allows us to not do hacky workarounds like
21-
# LD_PRELOAD-ing the lib. See https://github.com/LucaScheller/VFX-UsdAssetResolver/issues/3 for more information.
22-
# If you know a better way around this please file a PR :)
23-
module.cpp
24-
moduleDeps.cpp
25-
wrapResolver.cpp
26-
wrapResolverContext.cpp
27-
wrapResolverTokens.cpp
13+
debugCodes.cpp
14+
resolver.cpp
15+
resolverContext.cpp
16+
resolverTokens.cpp
17+
# Since when our resolver calls into Python it passes the ResolverContext,
18+
# we need to ensure that Python has loaded the ResolverContext C++ representation.
19+
# While we do have duplicate compiled code by adding the below, this allows us to not do hacky workarounds like
20+
# LD_PRELOAD-ing the lib. See https://github.com/LucaScheller/VFX-UsdAssetResolver/issues/3 for more information.
21+
# If you know a better way around this please file a PR :)
22+
module.cpp
23+
moduleDeps.cpp
24+
wrapResolver.cpp
25+
wrapResolverContext.cpp
26+
wrapResolverTokens.cpp
2827
)
2928
set_boost_namespace(${AR_CACHEDRESOLVER_TARGET_LIB})
3029
# Libs
@@ -66,15 +65,14 @@ install(TARGETS ${AR_CACHEDRESOLVER_TARGET_LIB} DESTINATION ${AR_CACHEDRESOLVER_
6665

6766
## Target library > cachedResolver Python ##
6867
add_library(${AR_CACHEDRESOLVER_TARGET_PYTHON}
69-
SHARED
70-
module.cpp
71-
moduleDeps.cpp
72-
# resolver.cpp
73-
resolverTokens.cpp
74-
resolverContext.cpp
75-
wrapResolver.cpp
76-
wrapResolverContext.cpp
77-
wrapResolverTokens.cpp
68+
module.cpp
69+
moduleDeps.cpp
70+
# resolver.cpp
71+
resolverTokens.cpp
72+
resolverContext.cpp
73+
wrapResolver.cpp
74+
wrapResolverContext.cpp
75+
wrapResolverTokens.cpp
7876
)
7977
add_dependencies(${AR_CACHEDRESOLVER_TARGET_PYTHON} ${AR_CACHEDRESOLVER_TARGET_LIB})
8078
set_boost_namespace(${AR_CACHEDRESOLVER_TARGET_PYTHON})

src/CachedResolver/PythonExpose.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,16 @@ def ResolveAndCache(context, assetPath):
112112
LOG.debug(
113113
"::: ResolverContext.ResolveAndCache | {} | {}".format(assetPath, context.GetCachingPairs())
114114
)
115+
"""Implement custom resolve logic and add the resolved path to the cache.
115116
resolved_asset_path = "/some/path/to/a/file.usd"
116117
context.AddCachingPair(assetPath, resolved_asset_path)
117-
"""
118-
To clear the context cache call:
118+
# To clear the context cache call:
119119
context.ClearCachingPairs()
120120
"""
121121
"""The code below is only needed to verify that UnitTests work."""
122122
UnitTestHelper.resolve_and_cache_call_counter += 1
123+
resolved_asset_path = "/some/path/to/a/file.usd"
124+
context.AddCachingPair(assetPath, resolved_asset_path)
123125
if assetPath == "unittest.usd":
124126
current_dir_path = UnitTestHelper.current_directory_path
125127
asset_a_file_path = os.path.join(current_dir_path, "assetA.usd")

src/CachedResolver/resolver.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ _AnchorRelativePath(
6161
const std::string& path)
6262
{
6363
if (TfIsRelativePath(anchorPath) ||
64-
!_IsRelativePath(path)) {
64+
!_IsFileRelativePath(path)) {
6565
return path;
6666
}
6767
// Ensure we are using forward slashes and not back slashes.
@@ -74,18 +74,6 @@ _AnchorRelativePath(
7474
return TfNormPath(anchoredPath);
7575
}
7676

77-
static ArResolvedPath
78-
_ResolveAnchored(
79-
const std::string& anchorPath,
80-
const std::string& path)
81-
{
82-
std::string resolvedPath = path;
83-
if (!anchorPath.empty()) {
84-
resolvedPath = TfStringCatPaths(anchorPath, path);
85-
}
86-
return TfPathExists(resolvedPath) ? ArResolvedPath(TfAbsPath(resolvedPath)) : ArResolvedPath();
87-
}
88-
8977
CachedResolver::CachedResolver() {
9078
this->SetExposeAbsolutePathIdentifierState(TfGetenvBool(DEFINE_STRING(AR_CACHEDRESOLVER_ENV_EXPOSE_ABSOLUTE_PATH_IDENTIFIERS), false));
9179
this->SetExposeRelativePathIdentifierState(TfGetenvBool(DEFINE_STRING(AR_CACHEDRESOLVER_ENV_EXPOSE_RELATIVE_PATH_IDENTIFIERS), false));
@@ -174,13 +162,6 @@ CachedResolver::_CreateIdentifier(
174162
}
175163
}
176164
}
177-
// Anchor non file path based identifiers and see if a file exists.
178-
// This is mostly for debugging as it allows us to add a file relative to our
179-
// anchor directory that has a higher priority than our (usually unanchored)
180-
// resolved asset path.
181-
if (_IsNotFilePath(assetPath) && Resolve(anchoredAssetPath).empty()) {
182-
return TfNormPath(assetPath);
183-
}
184165
return TfNormPath(anchoredAssetPath);
185166
}
186167

@@ -213,9 +194,6 @@ CachedResolver::_Resolve(
213194
if (assetPath.empty()) {
214195
return ArResolvedPath();
215196
}
216-
if (SdfLayer::IsAnonymousLayerIdentifier(assetPath)){
217-
return ArResolvedPath(assetPath);
218-
}
219197

220198
if (this->_IsContextDependentPath(assetPath)) {
221199
const CachedResolverContext* contexts[2] = {this->_GetCurrentContextPtr(), &_fallbackContext};
@@ -225,7 +203,7 @@ CachedResolver::_Resolve(
225203
auto &mappingPairs = ctx->GetMappingPairs();
226204
auto map_find = mappingPairs.find(assetPath);
227205
if(map_find != mappingPairs.end()){
228-
ArResolvedPath resolvedPath = _ResolveAnchored(this->emptyString, map_find->second);
206+
ArResolvedPath resolvedPath = ArResolvedPath(TfAbsPath(map_find->second));
229207
return resolvedPath;
230208
// Assume that a map hit is always valid.
231209
// if (resolvedPath) {
@@ -236,7 +214,7 @@ CachedResolver::_Resolve(
236214
auto &cachedPairs = ctx->GetCachingPairs();
237215
auto cache_find = cachedPairs.find(assetPath);
238216
if(cache_find != cachedPairs.end()){
239-
ArResolvedPath resolvedPath = _ResolveAnchored(this->emptyString, cache_find->second);
217+
ArResolvedPath resolvedPath = ArResolvedPath(TfAbsPath(cache_find->second));
240218
return resolvedPath;
241219
// Assume that a cache hit is always valid.
242220
// if (resolvedPath) {
@@ -250,7 +228,7 @@ CachedResolver::_Resolve(
250228
allow for resolver multithreading with different contexts.
251229
See .ResolveAndCachePair for more information.
252230
*/
253-
ArResolvedPath resolvedPath = _ResolveAnchored(this->emptyString, ctx->ResolveAndCachePair(assetPath));
231+
ArResolvedPath resolvedPath = ArResolvedPath(TfAbsPath(ctx->ResolveAndCachePair(assetPath)));
254232
if (resolvedPath) {
255233
return resolvedPath;
256234
}
@@ -261,7 +239,7 @@ CachedResolver::_Resolve(
261239
return ArResolvedPath();
262240
}
263241

264-
return _ResolveAnchored(std::string(), assetPath);
242+
return TfPathExists(assetPath) ? ArResolvedPath(TfAbsPath(assetPath)) : ArResolvedPath();
265243
}
266244

267245
ArResolvedPath

src/CachedResolver/resolverContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void CachedResolverContext::Initialize(){
9999
"ResolverContext.Initialize",
100100
this);
101101
if (!state) {
102-
std::cerr << "Failed to call Resolver.ResolveAndCache in " << DEFINE_STRING(AR_CACHEDRESOLVER_USD_PYTHON_EXPOSE_MODULE_NAME) << ".py. ";
102+
std::cerr << "Failed to call Resolver.Initialize in " << DEFINE_STRING(AR_CACHEDRESOLVER_USD_PYTHON_EXPOSE_MODULE_NAME) << ".py. ";
103103
std::cerr << "Please verify that the python code is valid!" << std::endl;
104104
}
105105
}

src/CachedResolver/testenv/testCachedResolver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def test_Resolve(self):
380380
self.assertEqual(resolved_path.GetPathString(), layer_file_path)
381381
self.assertTrue(os.path.isabs(resolved_path.GetPathString()))
382382
resolved_path = resolver.Resolve("example.usd")
383-
self.assertEqual(resolved_path.GetPathString(), "")
383+
self.assertEqual(resolved_path.GetPathString(), "/some/path/to/a/file.usd")
384384
resolved_path = resolver.Resolve("/some/invalid/path.usd")
385385
self.assertEqual(resolved_path.GetPathString(), "")
386386
resolved_path = resolver.Resolve(layer_file_path)
@@ -454,14 +454,15 @@ def test_ResolveWithScopedCache(self):
454454
resolver.Resolve(layer_identifier),
455455
)
456456
# Remove file
457+
ctx.RemoveCachingByKey(layer_identifier)
457458
os.remove(layer_file_path)
458459
# Query cached result
459460
self.assertEqual(
460461
os.path.abspath(layer_file_path),
461462
resolver.Resolve(layer_identifier),
462463
)
463-
# Uncached result should now return empty result
464-
self.assertEqual("", resolver.Resolve(layer_identifier))
464+
# Uncached result should now return the default PythonExpose.py result
465+
self.assertEqual(resolver.Resolve(layer_identifier), "/some/path/to/a/file.usd")
465466

466467
def test_ResolverCachingMechanism(self):
467468
with tempfile.TemporaryDirectory() as temp_dir_path:

src/FileResolver/CMakeLists.txt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ endif()
1010
### Targets ###
1111
## Target library > fileResolver ##
1212
add_library(${AR_FILERESOLVER_TARGET_LIB}
13-
SHARED
14-
debugCodes.cpp
15-
resolver.cpp
16-
resolverContext.cpp
17-
resolverTokens.cpp
13+
debugCodes.cpp
14+
resolver.cpp
15+
resolverContext.cpp
16+
resolverTokens.cpp
1817
)
1918
set_boost_namespace(${AR_FILERESOLVER_TARGET_LIB})
2019
# Libs
@@ -53,13 +52,12 @@ install(TARGETS ${AR_FILERESOLVER_TARGET_LIB} DESTINATION ${AR_FILERESOLVER_USD_
5352

5453
## Target library > fileResolver Python ##
5554
add_library(${AR_FILERESOLVER_TARGET_PYTHON}
56-
SHARED
57-
module.cpp
58-
moduleDeps.cpp
59-
resolverTokens.cpp
60-
wrapResolver.cpp
61-
wrapResolverContext.cpp
62-
wrapResolverTokens.cpp
55+
module.cpp
56+
moduleDeps.cpp
57+
resolverTokens.cpp
58+
wrapResolver.cpp
59+
wrapResolverContext.cpp
60+
wrapResolverTokens.cpp
6361
)
6462
add_dependencies(${AR_FILERESOLVER_TARGET_PYTHON} ${AR_FILERESOLVER_TARGET_LIB})
6563
set_boost_namespace(${AR_FILERESOLVER_TARGET_PYTHON})

src/PythonResolver/CMakeLists.txt

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ endif()
1010
### Targets ###
1111
## Target library > pythonResolver ##
1212
add_library(${AR_PYTHONRESOLVER_TARGET_LIB}
13-
SHARED
14-
debugCodes.cpp
15-
resolver.cpp
16-
resolverContext.cpp
17-
resolverTokens.cpp
13+
debugCodes.cpp
14+
resolver.cpp
15+
resolverContext.cpp
16+
resolverTokens.cpp
1817
)
1918
set_boost_namespace(${AR_PYTHONRESOLVER_TARGET_LIB})
2019
# Libs
@@ -53,15 +52,13 @@ install(TARGETS ${AR_PYTHONRESOLVER_TARGET_LIB} DESTINATION ${AR_PYTHONRESOLVER_
5352

5453
## Target library > pythonResolver Python ##
5554
add_library(${AR_PYTHONRESOLVER_TARGET_PYTHON}
56-
SHARED
57-
module.cpp
58-
moduleDeps.cpp
59-
resolverTokens.cpp
60-
resolverContext.cpp
61-
wrapResolver.cpp
62-
wrapResolverContext.cpp
63-
wrapResolverTokens.cpp
64-
55+
module.cpp
56+
moduleDeps.cpp
57+
resolverTokens.cpp
58+
resolverContext.cpp
59+
wrapResolver.cpp
60+
wrapResolverContext.cpp
61+
wrapResolverTokens.cpp
6562
)
6663
add_dependencies(${AR_PYTHONRESOLVER_TARGET_PYTHON} ${AR_PYTHONRESOLVER_TARGET_LIB})
6764
set_boost_namespace(${AR_PYTHONRESOLVER_TARGET_PYTHON})

0 commit comments

Comments
 (0)