10#include <unordered_set>
14namespace asset_compiler
20auto normalize_dependency_path_string(std::string path) -> std::string
26auto extract_href_from_link_tag(hpp::string_view link_tag) -> hpp::string_view
28 size_t href_pos = link_tag.find(
"href=");
29 if(href_pos == std::string::npos)
34 char quote_char = link_tag[href_pos];
35 if(quote_char !=
'"' && quote_char !=
'\'')
40 size_t href_end = link_tag.find(quote_char, href_pos);
41 if(href_end == std::string::npos)
45 return link_tag.substr(href_pos, href_end - href_pos);
48auto resolve_ui_tree_dependency_path(
const fs::path& href_value,
const fs::path& base_file_path) -> fs::path
54 return fs::absolute(base_file_path.parent_path() / href_value);
57auto visit_key_for_path(
const fs::path& file_path) -> std::string
59 return fs::absolute(file_path).string();
62void append_shader_varying_dependency(
const fs::path& file_path, std::vector<fs::path>& processed_files)
64 const std::string file_name = file_path.stem().string();
65 const fs::path dir = file_path.parent_path();
66 fs::path varying = dir / (file_name +
".io");
68 if(!fs::exists(varying, err))
70 varying = dir /
"varying.def.io";
72 if(!fs::exists(varying, err))
74 varying = dir /
"varying.def.sc";
76 if(fs::exists(varying, err))
78 processed_files.push_back(varying);
82void resolve_shader_dependencies(
const fs::path& file_path,
83 std::vector<fs::path>& processed_files,
84 std::unordered_set<std::string>& visited,
87 if(!visited.insert(visit_key_for_path(file_path)).second)
95 append_shader_varying_dependency(file_path, processed_files);
99 processed_files.push_back(file_path);
102 std::ifstream file(file_path);
108 const std::string include_keyword =
"#include";
110 while(std::getline(file, line))
112 line.erase(0, line.find_first_not_of(
" \t"));
113 if(line.compare(0, include_keyword.length(), include_keyword) != 0)
117 size_t start = line.find_first_of(
"\"<") + 1;
118 size_t end = line.find_last_of(
"\">");
119 if(
start == std::string::npos || end == std::string::npos ||
start >= end)
123 if(line[
start - 1] ==
'<' && line[end] ==
'>')
127 const std::string include_path = normalize_dependency_path_string(line.substr(
start, end -
start));
128 const fs::path resolved_path = fs::absolute(file_path.parent_path() / fs::path(include_path));
129 resolve_shader_dependencies(resolved_path, processed_files, visited,
false);
133void resolve_ui_tree_dependencies(
const fs::path& file_path,
134 std::vector<fs::path>& processed_files,
135 std::unordered_set<std::string>& visited,
138 if(!visited.insert(visit_key_for_path(file_path)).second)
146 processed_files.push_back(file_path);
149 std::ifstream file(file_path);
155 std::string content_str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
156 hpp::string_view content(content_str);
158 while((pos = content.find(
"<link", pos)) != std::string::npos)
160 size_t tag_end = content.find(
'>', pos);
161 if(tag_end == std::string::npos)
165 hpp::string_view link_tag = content.substr(pos, tag_end - pos + 1);
166 hpp::string_view href_value = extract_href_from_link_tag(link_tag);
167 if(!href_value.empty())
169 fs::path resolved_path = resolve_ui_tree_dependency_path(fs::path(href_value), file_path);
171 auto extension = resolved_path.extension().string();
172 if(std::find(supported_deps.begin(), supported_deps.end(), extension) != supported_deps.end())
174 resolve_ui_tree_dependencies(resolved_path, processed_files, visited,
false);
186 std::unordered_set<std::string> visited;
187 resolve_shader_dependencies(file_path, processed_files, visited,
true);
193 std::unordered_set<std::string> visited;
194 resolve_ui_tree_dependencies(file_path, processed_files, visited,
true);
auto get_suported_dependencies_formats() -> const std::vector< std::string > &
path resolve_protocol(const path &_path)
Given the specified path/filename, resolve the final full filename. This will be based on either the ...
bool has_known_protocol(const path &_path)
Checks whether the path has a known protocol.
void end(encoder *_encoder)
auto replace(const std::string &str, const std::string &search, const std::string &replace) -> std::string
void resolve_dependencies< ui_tree >(const fs::path &file_path, std::vector< fs::path > &processed_files)
void resolve_dependencies< gfx::shader >(const fs::path &file_path, std::vector< fs::path > &processed_files)
std::vector< math::vec3 > start