11// SPDX-License-Identifier: Apache-2.0
22// Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
33
4+ // This file is an implementation detail of the XRT coreutil library.
5+ // It is not part of the public XRT API. Include guards are not
6+ // at this level.
47#include " core/common/debug.h"
58#include " core/common/module_loader.h"
69
710#include < dlfcn.h>
11+
12+ #include < cstdlib>
813#include < filesystem>
914#include < stdexcept>
1015#include < string>
1419# error "XRT_INSTALL_PREFIX is undefined"
1520#endif
1621
22+ #ifndef XRT_VERSION_STRING
23+ # error "XRT_VERSION_STRING is undefined"
24+ #endif
25+
1726namespace xrt_core ::detail {
1827
1928namespace sfs = std::filesystem;
@@ -29,11 +38,36 @@ xilinx_xrt()
2938 if (std::string (info.dli_fname ).find (" libxrt_coreutil" ) == std::string::npos)
3039 return sfs::path (XRT_INSTALL_PREFIX);
3140
32- // Relocatable path based on install location of this DSO
33- sfs::path so_path (sfs::canonical (info.dli_fname )); // /.../lib/libxrt_coreutil.so
34- return so_path.parent_path ().parent_path ();
41+ try {
42+ // Relocatable path based on install location of this DSO
43+ sfs::path so_path (sfs::canonical (info.dli_fname )); // /.../lib/libxrt_coreutil.so
44+ return so_path.parent_path ().parent_path ();
45+ }
46+ catch (const std::exception&) {
47+ return sfs::path (XRT_INSTALL_PREFIX);
48+ }
3549}
3650
51+ // platform_repo_path() - Get candidate paths for platform repository data
52+ //
53+ // Returns a prioritized list of filesystem paths where
54+ // platform-specific data files (e.g., FPGA platform metadata) may be
55+ // located. The search order is:
56+ //
57+ // 1. XRT installation share directory:
58+ // - <xrt_root>/share (if xrt_root ends with "xrt")
59+ // - <xrt_root>/share/xrt (otherwise)
60+ //
61+ // 2. XDG user data directory (if XDG_DATA_HOME is set):
62+ // - $XDG_DATA_HOME/xrt/<version>
63+ // - $XDG_DATA_HOME/xrt
64+ //
65+ // 3. User's local share directory (if HOME is set):
66+ // - $HOME/.local/share/xrt/<version>
67+ // - $HOME/.local/share/xrt
68+ //
69+ // Returned paths are not validated - caller must check existence
70+ // Follows XDG Base Directory Specification for user data paths
3771std::vector<sfs::path>
3872platform_repo_path ()
3973{
@@ -51,10 +85,14 @@ platform_repo_path()
5185 paths.push_back (xrt / " share/xrt" );
5286
5387 // 2. XDG data path ($HOME/.local/share) is also a candidate
54- if (const char * xdg = std::getenv (" XDG_DATA_HOME" ); xdg && *xdg)
88+ if (const char * xdg = std::getenv (" XDG_DATA_HOME" ); xdg && *xdg) {
89+ paths.push_back (sfs::path (xdg) / " xrt" / XRT_VERSION_STRING);
5590 paths.push_back (sfs::path (xdg) / " xrt" );
56- else if (const char * home = std::getenv (" HOME" ); home && *home)
91+ }
92+ else if (const char * home = std::getenv (" HOME" ); home && *home) {
93+ paths.push_back (sfs::path (home) / " .local/share/xrt" / XRT_VERSION_STRING);
5794 paths.push_back (sfs::path (home) / " .local/share/xrt" );
95+ }
5896
5997 return paths;
6098}
0 commit comments