12namespace asset_compiler
36 auto hasher = hpp::sha1::compute_file_sha1(file);
38 std::array<char, SHA1_HEX_SIZE> hex_buffer{};
39 hasher.print_hex(hex_buffer.data(),
true,
false);
42 catch(
const std::exception& e)
51 return compiled_asset_path.string() +
".manifest";
58 std::ofstream file(manifest_path);
61 APPLOG_ERROR(
"Failed to open manifest file for writing: {}", manifest_path.string());
67 archive(ser20::make_nvp(
"source_path", manifest.source_file_path.generic_string()));
68 archive(ser20::make_nvp(
"source_sha", manifest.source_sha));
69 archive(ser20::make_nvp(
"source_timestamp", manifest.source_timestamp));
73 catch(
const std::exception& e)
75 APPLOG_ERROR(
"Exception while saving manifest {}: {}", manifest_path.string(), e.what());
85 if(!fs::exists(manifest_path, ec) || ec)
90 std::ifstream file(manifest_path);
93 APPLOG_ERROR(
"Failed to open manifest file for reading: {}", manifest_path.string());
99 std::string source_path;
100 archive(ser20::make_nvp(
"source_path", source_path));
101 manifest.source_file_path = fs::path(source_path);
102 archive(ser20::make_nvp(
"source_sha", manifest.source_sha));
103 archive(ser20::make_nvp(
"source_timestamp", manifest.source_timestamp));
106 catch(
const std::exception& e)
108 APPLOG_ERROR(
"Exception while loading manifest {}: {}", manifest_path.string(), e.what());
115 auto resolve_input_file = [](
const fs::path& key) -> fs::path
119 if(absolute_path.extension() ==
".meta")
121 absolute_path.replace_extension();
123 return absolute_path;
126 auto source_file_path = resolve_input_file(source_path);
137 return current_manifest.
source_sha != manifest.source_sha;
#define APPLOG_WARNING(...)
#define APPLOG_ERROR(...)
auto get_data_directory(const std::string &prefix={}) -> std::string
auto get_meta_directory(const std::string &prefix={}) -> 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 ...
path replace(const path &_path, const path &_sequence, const path &_new_sequence)
Replacing any occurences of the specified path sequence with another.
path convert_to_protocol(const path &_path)
Oposite of the resolve_protocol this function tries to convert to protocol path from an absolute one.
auto create_oarchive_associative(std::ostream &stream)
auto create_iarchive_associative(std::istream &stream)
auto get_manifest_path(const fs::path &compiled_asset_path) -> fs::path
Generate manifest file path from compiled asset path.
auto save_manifest(const fs::path &manifest_path, const asset_manifest &manifest) -> bool
Save manifest to file.
auto is_source_file_changed(const fs::path &source_path, const asset_manifest &manifest) -> bool
Check if source file has changed compared to manifest.
auto load_manifest(const fs::path &manifest_path, asset_manifest &manifest) -> bool
Load manifest from file.
Manifest data for compiled assets.
fs::path source_file_path
Path to the source file.
void compute_source_sha()
fs::file_time_type::clock::time_point source_timestamp
Timestamp when the asset was compiled.
std::string source_sha
SHA1 hash of the source file content.