Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.24)

set(package_name locc)
set(package_version 0.5.1)
set(package_version 0.5.2)
project(${package_name} VERSION ${package_version})

set(CMAKE_CXX_STANDARD 23)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ $ ./locc --log-level=info --heuristic=precision --threads=4 --sort-by=category

### Options

`locc` supports a few options, as of v0.5.1:
`locc` supports a few options, as of v0.5.2:

```
$ ./locc --help
Expand All @@ -83,6 +83,7 @@ OPTIONS
-s, --spec-json path to custom Specification JSON
-l, --log-level logging level (error/warn/info/debug)
--sort-by sort by (header name)
-d, --max-recurse-depth max depth for recursive directory iteration
--no-code-families no default Code Families
--no-text-categories no default text Categories
--no-exclude-suffixes no default exclude suffixes
Expand Down
2 changes: 2 additions & 0 deletions cli/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ auto App::parse_args(int const argc, char const* const* const argv) -> klib::arg
klib::args::named_option(m_args.spec_json, "s,spec-json", "path to custom Specification JSON"),
klib::args::named_option(m_args.log_level, "l,log-level", "logging level (error/warn/info/debug)"),
klib::args::named_option(m_args.sort_by, "sort-by", "sort by (header name)"),
klib::args::named_option(m_args.max_recurse_depth, "d,max-recurse-depth", "max depth for recursive directory iteration"),

klib::args::named_flag(m_args.no_code_families, "no-code-families", "no default Code Families"),
klib::args::named_flag(m_args.no_text_categories, "no-text-categories", "no default text Categories"),
Expand All @@ -86,6 +87,7 @@ void App::create_instance() {
.thread_count = ThreadCount(m_args.thread_count),
.heuristic = to_heuristic(m_args.heuristic),
.custom_spec_json = m_args.spec_json,
.max_recurse_depth = m_args.max_recurse_depth,
.flags = m_args.get_flags(),
};
m_instance = Instance::create(std::move(init_info));
Expand Down
1 change: 1 addition & 0 deletions cli/src/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class App {
std::string_view heuristic{};
std::string_view spec_json{};
std::string_view log_level{};
int max_recurse_depth{default_recurse_max_depth_v};
bool no_code_families{};
bool no_text_categories{};
bool no_excude_suffixes{};
Expand Down
3 changes: 3 additions & 0 deletions lib/include/locc/init_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ enum class Flag : std::uint8_t {
};
[[nodiscard]] constexpr auto enable_enum_bitops(Flag /*unused*/) { return true; }

constexpr auto default_recurse_max_depth_v = 100;

struct InitInfo {
ThreadCount thread_count{get_max_threads()};
Heuristic heuristic{Heuristic::Performance};
Specification custom_spec{};
std::string_view custom_spec_json{};
int max_recurse_depth{default_recurse_max_depth_v};
Flag flags{Flag::None};
};
} // namespace locc
9 changes: 7 additions & 2 deletions lib/src/detail/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,19 @@ void append_from_json(Config& out, std::string_view const json_path) {
} // namespace

auto Config::build(InitInfo info) -> Config {
auto ret = Config{.spec = std::move(info.custom_spec), .heuristic = info.heuristic};
auto ret = Config{.spec = std::move(info.custom_spec), .heuristic = info.heuristic, .max_depth = info.max_recurse_depth};

append_from_json(ret, info.custom_spec_json);
append_to(ret.spec, default_spec, info.flags);

if (ret.spec.code_families.empty() && ret.spec.text_categories.empty()) {
log.warn("no Code Families or text Categories, reverting to default Specification");
ret.spec = default_spec;
log.warn("no Code Families or text Categories, reverting to default Specification");
}

if (ret.max_depth < 0) {
ret.max_depth = default_recurse_max_depth_v;
log.warn("invalid max-depth: {}, reverting to default: {}", info.max_recurse_depth, default_recurse_max_depth_v);
}

return ret;
Expand Down
1 change: 1 addition & 0 deletions lib/src/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ struct Config {
dj::Json custom_spec_json{};
Specification spec{};
Heuristic heuristic{};
int max_depth{};
};
} // namespace locc::detail
13 changes: 10 additions & 3 deletions lib/src/detail/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ auto Executor::execute(std::string_view const path) -> Result {
log.info("processing path: {}", m_result.query_path);

if (fs::is_directory(m_workspace.path)) {
walk_directory(m_workspace.path);
walk_directory(m_workspace.path, 0);
} else if (fs::is_regular_file(m_workspace.path)) {
process_file(m_workspace.path);
} else {
Expand Down Expand Up @@ -57,15 +57,22 @@ void Executor::enqueue_job(fs::path path, Workspace::Entry& entry) {
}
}

void Executor::walk_directory(fs::path const& path) {
void Executor::walk_directory(fs::path const& path, int const depth) {
if (depth > m_workspace.config.max_depth) {
if constexpr (klib::log::debug_enabled_v) { log.debug("skipping directory: {} (depth: {})", path.generic_string(), depth); }
return;
}

auto const exclude_match = m_workspace.find_exclude_match(path);
if (!exclude_match.empty()) {
if constexpr (klib::log::debug_enabled_v) { log.debug("skipping directory: {} (exclude match: {})", path.generic_string(), exclude_match); }
return;
}

if constexpr (klib::log::debug_enabled_v) { log.debug("walking directory: {} (depth: {})", path.generic_string(), depth); }
for (auto const& it : fs::directory_iterator{path}) {
if (it.is_directory()) {
walk_directory(it.path());
walk_directory(it.path(), depth + 1);
continue;
}
if (it.is_symlink()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/detail/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Executor {

void process_file(fs::path path);
void enqueue_job(fs::path path, Workspace::Entry& entry);
void walk_directory(fs::path const& path);
void walk_directory(fs::path const& path, int depth);
void prepare_result();

[[nodiscard]] auto create_counter(fs::path path, Workspace::Entry const& entry) const -> std::unique_ptr<Counter>;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace locc {
namespace detail {
namespace {
[[nodiscard]] constexpr auto test(Flag const flags, Flag const mask) -> bool { return (flags & mask) == mask; }
[[nodiscard, maybe_unused]] constexpr auto test(Flag const flags, Flag const mask) -> bool { return (flags & mask) == mask; }

[[nodiscard, maybe_unused]] auto serialize_flags(Flag const flags) -> std::string {
auto ret = std::string{};
Expand All @@ -35,7 +35,8 @@ class Instance : public locc::Instance {
m_config = Config::build(std::move(info));

if constexpr (klib::log::debug_enabled_v) {
m_log.info("threads: {}, Heuristic: {}, flags: {}", int(get_thread_count()), heuristic_name_v[m_config.heuristic], serialize_flags(flags));
m_log.info("threads: {}, Heuristic: {}, max_depth: {}, flags: {}", int(get_thread_count()), heuristic_name_v[m_config.heuristic],
m_config.max_depth, serialize_flags(flags));
}
}

Expand Down