data_dir.cpp¶
src/config/data_dir.cpp
@file data_dir.cpp @brief Bundled data directory resolution.
Owners: @tvanfossen
resolve_data_dir
std::filesystem::path entropic::config::resolve_data_dir(const ParsedConfig &config)
Resolve the bundled data directory.
src/config/data_dir.cpp:81
Called by apply_workspace_app_context, build_assembled_prompt_for_tier, build_workspace, configure_common, load_bundled_default, sp_get_state
Calls share_dir_from_library
Source · 43 lines
std::filesystem::path resolve_data_dir(const ParsedConfig& config)
{
struct Candidate {
std::filesystem::path path;
const char* label;
};
std::vector<Candidate> candidates;
// Priority 1: ENTROPIC_DATA_DIR env var (explicit operator override)
if (const char* env = std::getenv("ENTROPIC_DATA_DIR"); env && *env) {
candidates.push_back({env, "ENTROPIC_DATA_DIR env"});
}
// Priority 2: config.config_dir / "data"
if (!config.config_dir.empty()) {
candidates.push_back({config.config_dir / "data", "config.config_dir"});
}
// Priority 3: binary-relative discovery (portable across prefixes)
if (auto from_lib = share_dir_from_library(); !from_lib.empty()) {
candidates.push_back({from_lib, "binary-relative (dladdr)"});
}
// Priority 4-5: compile-time install path, then source-tree / CWD fallbacks
candidates.push_back({CONFIG_ENTROPIC_DATA_DIR, "compile-time install path"});
candidates.push_back({CONFIG_ENTROPIC_SOURCE_DATA_DIR, "source tree (dev fallback)"});
candidates.push_back({"data", "CWD-relative (dev fallback)"});
std::filesystem::path result;
for (const auto& [path, label] : candidates) {
if (std::filesystem::is_directory(path)) {
s_log->info("Data dir from {}: {}", label, path.string());
result = path;
break;
}
}
if (result.empty()) {
s_log->warn("No data directory found — bundled files unavailable");
}
return result;
}