} | } | ||||
fs::path compile_file_plan::calc_object_file_path(const build_env& env) const noexcept { | fs::path compile_file_plan::calc_object_file_path(const build_env& env) const noexcept { | ||||
// `relpath` is just the path from the root of the source directory to the source file. | |||||
auto relpath = fs::relative(_source.path, _source.basis_path); | |||||
auto relpath = _source.relative_path(); | |||||
// The full output directory is prefixed by `_subdir` | // The full output directory is prefixed by `_subdir` | ||||
auto ret = env.output_root / _subdir / relpath; | auto ret = env.output_root / _subdir / relpath; | ||||
ret.replace_filename(relpath.filename().string() + env.toolchain.object_suffix()); | ret.replace_filename(relpath.filename().string() + env.toolchain.object_suffix()); |
// Pick a subdir based on app/test | // Pick a subdir based on app/test | ||||
const auto subdir_base = is_test ? params.out_subdir / "test" : params.out_subdir; | const auto subdir_base = is_test ? params.out_subdir / "test" : params.out_subdir; | ||||
// Put test/app executables in a further subdirectory based on the source file path | // Put test/app executables in a further subdirectory based on the source file path | ||||
const auto subdir | |||||
= subdir_base / fs::relative(source.path.parent_path(), lib.src_source_root().path); | |||||
const auto subdir = subdir_base / source.relative_path().parent_path(); | |||||
// Pick compile rules based on app/test | // Pick compile rules based on app/test | ||||
auto rules = is_test ? test_rules : compile_rules; | auto rules = is_test ? test_rules : compile_rules; | ||||
// Pick input libs based on app/test | // Pick input libs based on app/test |
std::optional<source_kind> infer_source_kind(path_ref) noexcept; | std::optional<source_kind> infer_source_kind(path_ref) noexcept; | ||||
struct source_file { | struct source_file { | ||||
fs::path path; | |||||
fs::path basis_path; | |||||
/** | |||||
* The actual path to the file | |||||
*/ | |||||
fs::path path; | |||||
/** | |||||
* The path to source root that contains the file in question | |||||
*/ | |||||
fs::path basis_path; | |||||
/** | |||||
* The kind of the source file | |||||
*/ | |||||
source_kind kind; | source_kind kind; | ||||
static std::optional<source_file> from_path(path_ref path, path_ref base_path) noexcept; | static std::optional<source_file> from_path(path_ref path, path_ref base_path) noexcept; | ||||
fs::path relative_path() const noexcept { return fs::relative(path, basis_path); } | |||||
}; | }; | ||||
using source_list = std::vector<source_file>; | using source_list = std::vector<source_file>; |