MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Dependencies.cpp
Go to the documentation of this file.
1#include "Dependencies.hpp"
2
4
5namespace MayaFlux::Host {
6
7namespace {
8
10 {
11 if (!located) {
12 return std::unexpected(detail::to_failure(located.error()));
13 }
14
15 std::error_code ec;
16 std::filesystem::path canonical = std::filesystem::canonical(located->path, ec);
17 if (ec) {
18 canonical = located->path;
19 }
20
21 auto loaded = detail::apply_or_stage(detail::Stage::Library, canonical.string());
22 if (!loaded) {
23 return std::unexpected(std::move(loaded.error()));
24 }
25 return canonical;
26 }
27
28}
29
31 const std::filesystem::path& directory,
32 std::string_view marker_file)
33{
34 auto root = Platform::acquire_header_root(directory, marker_file);
35 if (!root) {
36 return std::unexpected(detail::to_failure(root.error()));
37 }
38
39 auto added = detail::apply_or_stage(detail::Stage::IncludePath, root->string());
40 if (!added) {
41 return std::unexpected(std::move(added.error()));
42 }
43 return *root;
44}
45
47 std::string_view file_name,
48 std::span<const std::filesystem::path> roots)
49{
50 Failure failure { "header not found: " + std::string(file_name), {} };
51
52 for (const auto& root : roots) {
53 auto found = Platform::acquire_header_root(root, file_name);
54 if (!found) {
55 Failure refused = detail::to_failure(found.error());
56 failure.tried.insert(failure.tried.end(), refused.tried.begin(), refused.tried.end());
57 continue;
58 }
59
60 const std::filesystem::path header = *found / file_name;
61 if (auto included = eval_file(header); !included) {
62 return std::unexpected(std::move(included.error()));
63 }
64 return header;
65 }
66
67 return std::unexpected(std::move(failure));
68}
69
70Result<std::filesystem::path> load_library(const std::filesystem::path& path)
71{
72 return load_acquired(Platform::acquire_library(Platform::LibraryFromPath { path }));
73}
74
76 const std::filesystem::path& prefix,
77 std::string_view base_name)
78{
79 return load_acquired(Platform::acquire_library(
80 Platform::LibraryFromPrefix { prefix, std::string(base_name) }));
81}
82
83Result<void> add_compile_flag(const std::string& flag)
84{
85 if (flag.empty()) {
86 return std::unexpected(Failure { "empty compile flag", {} });
87 }
89}
90
91} // namespace MayaFlux::Host
Failure to_failure(const Platform::AcquireFailure &failure)
Definition Session.cpp:165
Result< void > apply_or_stage(Stage stage, std::string value)
Apply an item to the running session, or stage it until start_session.
Definition Session.cpp:129
Result< std::filesystem::path > load_library_from_prefix(const std::filesystem::path &prefix, std::string_view base_name)
Load a shared library by name from one prefix.
std::expected< T, Failure > Result
Result of a Host call.
Definition Session.hpp:26
Result< void > add_compile_flag(const std::string &flag)
Add a compile flag to the JIT.
Result< std::filesystem::path > add_include_root(const std::filesystem::path &directory, std::string_view marker_file)
Add a directory to the JIT include search path.
Result< std::filesystem::path > add_header(std::string_view file_name, std::span< const std::filesystem::path > roots)
Include a header in the session.
Result< void > eval_file(const std::filesystem::path &path)
Evaluate a source file by including it.
Definition Session.cpp:364
Result< std::filesystem::path > load_library(const std::filesystem::path &path)
Load a shared library from an explicit file path.
std::expected< T, AcquireFailure > Acquired
Acquired< LibraryLocation > acquire_library(const LibrarySource &source)
Resolve a library request to a location the loader can open.
Acquired< std::filesystem::path > acquire_header_root(const std::filesystem::path &directory, std::string_view marker_file={})
Validate a header root: an existing directory, optionally containing a marker file.
std::vector< std::filesystem::path > tried
Definition Session.hpp:19
Why a Host call was refused, with every path that was checked.
Definition Session.hpp:17
A shared library at an explicit file path, absolute or relative to the working directory.
A shared library given by name, searched under one prefix.