Blender  V3.3
usd_tests_common.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2022 Blender Foundation. All rights reserved. */
3 
4 #include "usd_tests_common.h"
5 
6 #include "testing/testing.h"
7 
8 #include <pxr/base/plug/registry.h>
9 
10 #include "BLI_path_util.h"
11 #include "BLI_utildefines.h"
12 
13 #include "BKE_appdir.h"
14 
15 namespace blender::io::usd {
16 
18 {
19  static char usd_datafiles_dir[FILE_MAX] = {'\0'};
20  static bool plugin_path_registered = false;
21  if (plugin_path_registered) {
22  return usd_datafiles_dir;
23  }
24  plugin_path_registered = true;
25 
26  const std::string &release_dir = blender::tests::flags_test_release_dir();
27  if (release_dir.empty()) {
28  return "";
29  }
30 
31  const size_t path_len = BLI_path_join(
32  usd_datafiles_dir, FILE_MAX, release_dir.c_str(), "datafiles", "usd", nullptr);
33 
34  /* #BLI_path_join removes trailing slashes, but the USD library requires one in order to
35  * recognize the path as directory. */
36  BLI_assert(path_len + 1 < FILE_MAX);
37  usd_datafiles_dir[path_len] = '/';
38  usd_datafiles_dir[path_len + 1] = '\0';
39 
40  pxr::PlugRegistry::GetInstance().RegisterPlugins(usd_datafiles_dir);
41 
42  return usd_datafiles_dir;
43 }
44 
45 } // namespace blender::io::usd
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define FILE_MAX
size_t BLI_path_join(char *__restrict dst, size_t dst_len, const char *path_first,...) ATTR_NONNULL(1
std::string register_usd_plugins_for_tests()