Skip to content

Commit

Permalink
fix: relative recipe paths correctly resolved (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy authored Sep 21, 2024
1 parent 614d537 commit 87474a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ecsact/cli/commands/build/build_recipe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ auto ecsact::build_recipe::merge( //
if(std::holds_alternative<source_path>(src)) {
source_path src_path = std::get<source_path>(src);
if(!src_path.path.is_absolute()) {
src_path.path = fs::relative(
src_path.path = fs::proximate(
target.base_directory() / src_path.path,
base.base_directory()
);
Expand Down
26 changes: 21 additions & 5 deletions ecsact/cli/commands/build/recipe/cook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,25 +309,34 @@ static auto handle_source( //
}

for(auto path : paths) {
if(!fs::exists(src_path)) {
if(!fs::exists(path)) {
ecsact::cli::report_error(
"Source file {} does not exist",
src_path.generic_string()
path.generic_string()
);
return 1;
}
if(fs::is_directory(path)) {
ecsact::cli::report_warning(
"Ignoring directory source {} ",
path.generic_string()
);
continue;
}
auto rel_outdir = outdir;
if(auto stripped = path_strip_prefix(src_path, before_glob)) {
if(auto stripped = path_strip_prefix(path, before_glob)) {
rel_outdir = outdir / *stripped;
}

rel_outdir = rel_outdir.lexically_normal();

fs::create_directories(rel_outdir, ec);
fs::copy(src_path, rel_outdir, ec);
fs::copy(path, rel_outdir, ec);

if(ec) {
ecsact::cli::report_error(
"Failed to copy source {} to {}: {}",
src_path.generic_string(),
path.generic_string(),
rel_outdir.generic_string(),
ec.message()
);
Expand All @@ -339,6 +348,13 @@ static auto handle_source( //
rel_outdir.generic_string()
);
}

ecsact::cli::report_info(
"Copied {} to {}",
path.string(),
rel_outdir.string(),
ec.message()
);
}

return 0;
Expand Down
6 changes: 5 additions & 1 deletion ecsact/cli/commands/recipe-bundle/build_recipe_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,15 @@ auto ecsact::build_recipe_bundle::create( //
return src;
},
[&](build_recipe::source_path src) -> source_visitor_result_t {
auto src_path = src.path;
if(!src_path.is_absolute()) {
src_path = recipe.base_directory() / src.path;
}
auto src_path_basename = src.path.filename();
auto archive_rel_path =
(fs::path{"files"} / src.outdir.value_or(".") / src_path_basename)
.lexically_normal();
auto file_buffer = read_file(src.path);
auto file_buffer = read_file(src_path);

if(!file_buffer) {
return std::logic_error{"read file fail"};
Expand Down

0 comments on commit 87474a3

Please sign in to comment.