Skip to content

Commit

Permalink
feat: Validate recipe plugins on build and bundles (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelwan authored Aug 9, 2024
1 parent ce7953a commit 03c4b11
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 22 deletions.
23 changes: 12 additions & 11 deletions ecsact/cli/commands/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ cc_library(
hdrs = ["common.hh"],
copts = copts,
deps = [
"@docopt.cpp//:docopt",
"//ecsact/cli:report",
"//ecsact/cli:report_message",
"//ecsact/cli/detail:json_report",
"//ecsact/cli/detail:text_report",
"@docopt.cpp//:docopt",
],
)


cc_library(
name = "codegen",
srcs = ["codegen.cc"],
Expand All @@ -51,15 +50,15 @@ cc_library(
deps = [
":command",
":common",
"//ecsact/cli/commands/codegen:codegen",
"@magic_enum",
"@docopt.cpp//:docopt",
"//ecsact/cli/commands/codegen",
"@boost.dll",
"@ecsact_interpret",
"@docopt.cpp//:docopt",
"@ecsact_codegen//:plugin",
"@ecsact_codegen//:plugin_validate",
"@ecsact_interpret",
"@ecsact_runtime//:dylib",
"@ecsact_runtime//:meta",
"@magic_enum",
],
)

Expand All @@ -86,13 +85,14 @@ cc_library(
":common",
"//ecsact/cli:report",
"//ecsact/cli:report_message",
"//ecsact/cli/commands/build/recipe:taste",
"//ecsact/cli/commands/build/recipe:cook",
"//ecsact/cli/commands/build:cc_compiler",
"//ecsact/cli/commands/build:build_recipe",
"//ecsact/cli/commands/build:cc_compiler",
"//ecsact/cli/commands/build/recipe:cook",
"//ecsact/cli/commands/build/recipe:taste",
"//ecsact/cli/commands/recipe-bundle:build_recipe_bundle",
"@ecsact_interpret",
"@docopt.cpp//:docopt",
"@ecsact_codegen//:plugin_validate",
"@ecsact_interpret",
"@magic_enum",
],
)
Expand All @@ -110,8 +110,9 @@ cc_library(
"//ecsact/cli/commands/build:build_recipe",
"//ecsact/cli/commands/recipe-bundle:build_recipe_bundle",
"//ecsact/cli/detail:argv0",
"@ecsact_interpret",
"@docopt.cpp//:docopt",
"@ecsact_codegen//:plugin_validate",
"@ecsact_interpret",
"@magic_enum",
],
)
28 changes: 28 additions & 0 deletions ecsact/cli/commands/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
#include "ecsact/cli/commands/build/recipe/cook.hh"
#include "ecsact/cli/commands/build/recipe/taste.hh"
#include "ecsact/cli/commands/recipe-bundle/build_recipe_bundle.hh"
#include "ecsact/codegen/plugin_validate.hh"

namespace fs = std::filesystem;

using namespace std::string_view_literals;
using namespace std::string_literals;

constexpr auto USAGE = R"docopt(Ecsact Build Command
Expand Down Expand Up @@ -173,6 +175,32 @@ auto ecsact::cli::detail::build_command( //
}

auto recipe = std::move(std::get<build_recipe>(recipe_result));

for(auto& source : recipe.sources()) {
auto result = std::get_if<build_recipe::source_codegen>(&source);
if(result) {
if(result->plugins.empty()) {
ecsact::cli::report_error(
"Recipe source has no plugins {}",
recipe_path_str
);
return 1;
}

for(auto plugin : result->plugins) {
auto validate_result = ecsact::codegen::plugin_validate(plugin);
if(!validate_result.ok()) {
auto err_msg = "Plugin validation failed for '" + plugin + "'\n";
for(auto err : validate_result.errors) {
err_msg += " - "s + to_string(err) + "\n";
}
ecsact::cli::report_error("{}", err_msg);
return 1;
}
}
}
}

if(!recipe_composite) {
recipe_composite.emplace(std::move(recipe));
} else {
Expand Down
23 changes: 13 additions & 10 deletions ecsact/cli/commands/build/recipe/cook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,7 @@ auto cl_compile(compile_options options) -> int {
cl_args.push_back("/diagnostics:column");
cl_args.push_back("/DECSACT_BUILD");

// TODO(zaucy): Add debug mode
// if(options.debug) {
// compile_proc_args.push_back("/DEBUG:FULL");
// compile_proc_args.push_back("/MDd");
// compile_proc_args.push_back("/Z7");
// compile_proc_args.push_back("/EHsc");
// compile_proc_args.push_back("/bigobj");
// }

// cl_args.push_back("/we4530"); // treat exceptions as errors
cl_args.push_back("/we4530"); // treat exceptions as errors
cl_args.push_back("/wd4530"); // ignore use of exceptions warning
cl_args.push_back("/MD");
cl_args.push_back("/DNDEBUG");
Expand All @@ -605,6 +596,18 @@ auto cl_compile(compile_options options) -> int {
std::format("{}\\", fs::path{options.work_dir}.lexically_normal().string())
);

if(!options.debug) {
cl_args.push_back("/MD");
cl_args.push_back("/DNDEBUG");
} else {
cl_args.push_back("/FC"); // full source paths
cl_args.push_back("/MD");
cl_args.push_back("/Z7");
cl_args.push_back("/EHsc");
cl_args.push_back("/bigobj");
cl_args.push_back("/Od");
}

auto generated_defines =
ecsact::cli::cc_defines_gen(options.imports, options.exports);

Expand Down
30 changes: 29 additions & 1 deletion ecsact/cli/commands/recipe-bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
#include "ecsact/cli/commands/common.hh"
#include "ecsact/cli/commands/build/build_recipe.hh"
#include "ecsact/cli/commands/recipe-bundle/build_recipe_bundle.hh"
#include "ecsact/codegen/plugin_validate.hh"

namespace fs = std::filesystem;

using namespace std::string_view_literals;
using namespace std::string_literals;

constexpr auto USAGE = R"docopt(Ecsact Recipe Bundle Command
Expand Down Expand Up @@ -82,7 +84,7 @@ auto ecsact::cli::detail::recipe_bundle_command( //

auto recipe_composite = std::optional<build_recipe>{};
auto recipe_paths = args.at("<recipe>").asStringList();
for(auto recipe_path : args.at("<recipe>").asStringList()) {
for(auto recipe_path : recipe_paths) {
auto recipe_result = build_recipe::from_yaml_file(recipe_path);

if(std::holds_alternative<build_recipe_parse_error>(recipe_result)) {
Expand All @@ -95,6 +97,32 @@ auto ecsact::cli::detail::recipe_bundle_command( //
}

auto recipe = std::move(std::get<build_recipe>(recipe_result));

for(auto& source : recipe.sources()) {
auto result = std::get_if<build_recipe::source_codegen>(&source);
if(result) {
if(result->plugins.empty()) {
ecsact::cli::report_error(
"Recipe source has no plugins {}",
recipe_path
);
return 1;
}

for(auto plugin : result->plugins) {
auto validate_result = ecsact::codegen::plugin_validate(plugin);
if(!validate_result.ok()) {
auto err_msg = "Plugin validation failed for '" + plugin + "'\n";
for(auto err : validate_result.errors) {
err_msg += " - "s + to_string(err) + "\n";
}
ecsact::cli::report_error("{}", err_msg);
return 1;
}
}
}
}

if(!recipe_composite) {
recipe_composite.emplace(std::move(recipe));
} else {
Expand Down

0 comments on commit 03c4b11

Please sign in to comment.