diff --git a/src/build/delta.cc b/src/build/delta.cc index bc81e91f..e0f1976b 100644 --- a/src/build/delta.cc +++ b/src/build/delta.cc @@ -349,9 +349,9 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, } } - dependents_wave.push_back({BuildPlan::Action::Type::Dependents, - std::move(destination), - std::move(action_dependencies), uri}); + dependents_wave.push_back( + {BuildPlan::Action::Type::Dependents, std::move(destination), + std::move(action_dependencies), uri, incremental}); } std::ranges::sort(dependents_wave, [](const BuildPlan::Action &left, @@ -506,7 +506,8 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, plan.waves.push_back({{.type = BuildPlan::Action::Type::Comment, .destination = comment_path, .dependencies = {}, - .data = comment}}); + .data = comment, + .incremental = incremental}}); plan.size = 1; return plan; } @@ -518,7 +519,8 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, plan.waves.push_back({{.type = BuildPlan::Action::Type::Remove, .destination = comment_path, .dependencies = {}, - .data = {}}}); + .data = {}, + .incremental = incremental}}); plan.size = 1; return plan; } @@ -758,7 +760,8 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, plan.waves.push_back({{.type = BuildPlan::Action::Type::Comment, .destination = comment_path, .dependencies = {}, - .data = comment}}); + .data = comment, + .incremental = incremental}}); plan.size = 1; return plan; } @@ -770,7 +773,8 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, plan.waves.push_back({{.type = BuildPlan::Action::Type::Remove, .destination = comment_path, .dependencies = {}, - .data = {}}}); + .data = {}, + .incremental = incremental}}); plan.size = 1; return plan; } @@ -994,9 +998,9 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, action_deps.emplace_back(std::move(dep)); } - dag_waves[wave].push_back({target.action, - std::filesystem::path{target_path}, - std::move(action_deps), target.data}); + dag_waves[wave].push_back( + {target.action, std::filesystem::path{target_path}, + std::move(action_deps), target.data, incremental}); } } @@ -1014,13 +1018,15 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, std::filesystem::path{make_base_string( output_string, SCHEMAS_DIRECTORY, relative_string)}, {}, - {}}); + {}, + incremental}); remove_wave.push_back( {BuildPlan::Action::Type::Remove, std::filesystem::path{make_base_string( output_string, EXPLORER_DIRECTORY, relative_string)}, {}, - {}}); + {}, + incremental}); } for (const auto &schema : active_schemas) { @@ -1043,7 +1049,8 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, remove_wave.push_back({BuildPlan::Action::Type::Remove, std::filesystem::path{std::move(target_path)}, {}, - {}}); + {}, + incremental}); } } } @@ -1138,7 +1145,8 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, remove_wave.push_back({BuildPlan::Action::Type::Remove, std::filesystem::path{root}, {}, - {}}); + {}, + incremental}); } } @@ -1173,7 +1181,8 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, remove_wave.push_back({BuildPlan::Action::Type::Remove, std::filesystem::path{entry_path}, {}, - {}}); + {}, + incremental}); web_removed = true; } } @@ -1210,29 +1219,33 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, init_wave.push_back({.type = BuildPlan::Action::Type::Version, .destination = version_path, .dependencies = {}, - .data = version}); + .data = version, + .incremental = incremental}); init_wave.push_back({.type = BuildPlan::Action::Type::Configuration, .destination = configuration_path, .dependencies = {}, - .data = {}}); + .data = {}, + .incremental = incremental}); if (!comment.empty()) { init_wave.push_back({.type = BuildPlan::Action::Type::Comment, .destination = comment_path, .dependencies = {}, - .data = comment}); + .data = comment, + .incremental = incremental}); } else if (entries.contains(comment_string)) { remove_wave.push_back( - {BuildPlan::Action::Type::Remove, comment_path, {}, {}}); + {BuildPlan::Action::Type::Remove, comment_path, {}, {}, incremental}); } plan.waves.push_back(std::move(init_wave)); } else if (!comment.empty()) { plan.waves.push_back({{.type = BuildPlan::Action::Type::Comment, .destination = comment_path, .dependencies = {}, - .data = comment}}); + .data = comment, + .incremental = incremental}}); } else if (entries.contains(comment_string)) { remove_wave.push_back( - {BuildPlan::Action::Type::Remove, comment_path, {}, {}}); + {BuildPlan::Action::Type::Remove, comment_path, {}, {}, incremental}); } for (auto &wave : dag_waves) { @@ -1252,7 +1265,8 @@ auto delta(const BuildPhase phase, const BuildPlan::Type build_type, {rule.action, output / rule.filename, {configuration_path}, - build_type == BuildPlan::Type::Full ? "Full" : "Headless"}); + build_type == BuildPlan::Type::Full ? "Full" : "Headless", + incremental}); } if (!global_wave.empty()) { diff --git a/src/build/include/sourcemeta/one/build.h b/src/build/include/sourcemeta/one/build.h index 21ed7843..c331fda8 100644 --- a/src/build/include/sourcemeta/one/build.h +++ b/src/build/include/sourcemeta/one/build.h @@ -54,6 +54,7 @@ struct BuildPlan { std::filesystem::path destination; Dependencies dependencies; std::string_view data; + bool incremental; }; std::filesystem::path output; diff --git a/src/index/explorer.h b/src/index/explorer.h index 07fea721..8d52dfc2 100644 --- a/src/index/explorer.h +++ b/src/index/explorer.h @@ -213,7 +213,8 @@ struct GENERATE_EXPLORER_SCHEMA_METADATA { action.destination, result, "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } }; @@ -440,7 +441,8 @@ struct GENERATE_EXPLORER_DIRECTORY_LIST { action.destination, meta, "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } }; diff --git a/src/index/generators.h b/src/index/generators.h index 379acdf5..c944a67e 100644 --- a/src/index/generators.h +++ b/src/index/generators.h @@ -124,7 +124,8 @@ struct GENERATE_MATERIALISED_SCHEMA { sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{std::string{dialect_identifier}}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); resolver.cache_path(action.data, action.destination); return true; } @@ -169,7 +170,8 @@ struct GENERATE_POINTER_POSITIONS { action.destination, result, "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } }; @@ -198,7 +200,8 @@ struct GENERATE_FRAME_LOCATIONS { action.destination, result, "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } }; @@ -236,7 +239,8 @@ struct GENERATE_DEPENDENCIES { action.destination, result, "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } @@ -321,7 +325,8 @@ struct GENERATE_DEPENDENTS { action.destination, result, "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } }; @@ -379,7 +384,8 @@ struct GENERATE_HEALTH { action.destination, report, "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } @@ -454,7 +460,8 @@ struct GENERATE_BUNDLE { sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{std::string{dialect_identifier}}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } }; @@ -488,7 +495,8 @@ struct GENERATE_EDITOR { sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{std::string{dialect_identifier}}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } }; @@ -496,7 +504,8 @@ struct GENERATE_EDITOR { static auto generate_blaze_template( const std::filesystem::path &destination, const sourcemeta::one::BuildPlan::Action::Dependencies &dependencies, - const sourcemeta::blaze::Mode mode) -> void { + const sourcemeta::blaze::Mode mode, const bool enable_debug_checks) + -> void { const auto timestamp_start{std::chrono::steady_clock::now()}; const auto contents{sourcemeta::one::read_json(dependencies.front())}; sourcemeta::core::SchemaFrame frame{ @@ -514,7 +523,8 @@ static auto generate_blaze_template( destination, result, "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + enable_debug_checks); } struct GENERATE_BLAZE_TEMPLATE_EXHAUSTIVE { @@ -525,7 +535,8 @@ struct GENERATE_BLAZE_TEMPLATE_EXHAUSTIVE { const sourcemeta::one::Configuration &, const sourcemeta::core::JSON &) -> bool { generate_blaze_template(action.destination, action.dependencies, - sourcemeta::blaze::Mode::Exhaustive); + sourcemeta::blaze::Mode::Exhaustive, + action.incremental); return true; } }; @@ -538,7 +549,8 @@ struct GENERATE_BLAZE_TEMPLATE_FAST { const sourcemeta::one::Configuration &, const sourcemeta::core::JSON &) -> bool { generate_blaze_template(action.destination, action.dependencies, - sourcemeta::blaze::Mode::FastValidation); + sourcemeta::blaze::Mode::FastValidation, + action.incremental); return true; } }; @@ -583,7 +595,8 @@ struct GENERATE_STATS { "application/json", sourcemeta::one::Encoding::GZIP, sourcemeta::core::JSON{nullptr}, std::chrono::duration_cast(timestamp_end - - timestamp_start)); + timestamp_start), + action.incremental); return true; } }; diff --git a/src/shared/include/sourcemeta/one/shared_metapack.h b/src/shared/include/sourcemeta/one/shared_metapack.h index ce556c11..3092e616 100644 --- a/src/shared/include/sourcemeta/one/shared_metapack.h +++ b/src/shared/include/sourcemeta/one/shared_metapack.h @@ -43,14 +43,16 @@ auto write_json(const std::filesystem::path &destination, const sourcemeta::core::JSON::String &mime, const Encoding encoding, const sourcemeta::core::JSON &extension, - const std::chrono::milliseconds duration) -> void; + const std::chrono::milliseconds duration, + const bool enable_debug_checks) -> void; auto write_pretty_json(const std::filesystem::path &destination, const sourcemeta::core::JSON &document, const sourcemeta::core::JSON::String &mime, const Encoding encoding, const sourcemeta::core::JSON &extension, - const std::chrono::milliseconds duration) -> void; + const std::chrono::milliseconds duration, + const bool enable_debug_checks) -> void; auto write_text(const std::filesystem::path &destination, const std::string_view contents, diff --git a/src/shared/metapack.cc b/src/shared/metapack.cc index fa5caebf..d2ee32a4 100644 --- a/src/shared/metapack.cc +++ b/src/shared/metapack.cc @@ -5,6 +5,12 @@ #include #include +// TODO: Add this macro to all other file types too +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define ASSERT_NOT_REDUNDANT_WRITE(destination, document, debug_checks) \ + assert(!(debug_checks) || !std::filesystem::exists(destination) || \ + read_json(destination) != (document)) + #include // assert #include // std::chrono::system_clock::time_point #include // std::functional @@ -162,7 +168,9 @@ auto write_json(const std::filesystem::path &destination, const sourcemeta::core::JSON::String &mime, const Encoding encoding, const sourcemeta::core::JSON &extension, - const std::chrono::milliseconds duration) -> void { + const std::chrono::milliseconds duration, + const bool enable_debug_checks) -> void { + ASSERT_NOT_REDUNDANT_WRITE(destination, document, enable_debug_checks); write_stream(destination, mime, encoding, extension, duration, [&document](auto &stream) { sourcemeta::core::stringify(document, stream); @@ -174,7 +182,9 @@ auto write_pretty_json(const std::filesystem::path &destination, const sourcemeta::core::JSON::String &mime, const Encoding encoding, const sourcemeta::core::JSON &extension, - const std::chrono::milliseconds duration) -> void { + const std::chrono::milliseconds duration, + const bool enable_debug_checks) -> void { + ASSERT_NOT_REDUNDANT_WRITE(destination, document, enable_debug_checks); write_stream(destination, mime, encoding, extension, duration, [&document](auto &stream) { sourcemeta::core::prettify(document, stream);