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.16)

project(bldd
VERSION 0.2.0
VERSION 0.2.1
DESCRIPTION "Backward ldd - Find executables using shared libraries"
LANGUAGES CXX
)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ bldd -d /opt --no-recursive

BLDD supports [configuration files](./config/bldd.conf.example) for persistent settings.

By default, BLDD looks for a configuration file at `~/.config/bldd/bldd.conf`.
You can override this with the `--config` flag.

## Testing

BLDD includes unit and end-to-end tests:
Expand Down
10 changes: 9 additions & 1 deletion include/bldd/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include "bldd/types.h"
#include <cstdint>
#include <filesystem>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

namespace bldd {
Expand All @@ -26,12 +28,18 @@ struct Config {
bool recursive = true;

Config()
: scan_directories({ "/usr/bin", "/usr/local/bin" })
: scan_directories({})
, output_format(OutputFormat::TXT)
{
}

static Config load_from_file(std::string const& config_path);
static constexpr std::string_view kDefaultConfigPath = ".config/bldd/bldd.conf";
static std::filesystem::path get_default_path()
{
char const* home = getenv("HOME");
return home ? std::filesystem::path(home) / kDefaultConfigPath : std::filesystem::path {};
}
};

inline Config::OutputFormat format_from_string(std::string const&)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bldd"
version = "0.2.0"
version = "0.2.1"
description = ""
readme = ""
requires-python = ">=3.14"
Expand Down
37 changes: 37 additions & 0 deletions scripts/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,43 @@ if [[ "$PLATFORM" == "macos" ]]; then
fi
fi

# Config file test
echo ""
echo "--- Test: default-config-loading ---"
# Create default config directory and copy example config
DEFAULT_CONFIG_DIR="$HOME/.config/bldd"
DEFAULT_CONFIG_PATH="$DEFAULT_CONFIG_DIR/bldd.conf"

# Backup existing config if present
if [[ -f "$DEFAULT_CONFIG_PATH" ]]; then
mv "$DEFAULT_CONFIG_PATH" "$DEFAULT_CONFIG_PATH.backup"
RESTORE_CONFIG=true
else
RESTORE_CONFIG=false
fi

# Setup test config
mkdir -p "$DEFAULT_CONFIG_DIR"
cp "$WORKDIR/config/bldd.conf.example" "$DEFAULT_CONFIG_PATH"

# Run bldd and check for config loading message
OUTPUT=$($BLDD 2>&1) || true
echo "$OUTPUT"

# Cleanup
rm -f "$DEFAULT_CONFIG_PATH"
if [[ "$RESTORE_CONFIG" == "true" ]]; then
mv "$DEFAULT_CONFIG_PATH.backup" "$DEFAULT_CONFIG_PATH"
fi

# Check result
if echo "$OUTPUT" | grep -q "Loading configuration from default path.*bldd.conf"; then
echo "✓ PASSED: default-config-loading"
else
echo "✗ FAILED: default-config-loading (expected config loading message)"
exit 1
fi

# No results case
echo ""
echo "--- Test: no-results ---"
Expand Down
20 changes: 17 additions & 3 deletions src/cmd/cli.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "cli.h"
#include "bldd/config.h"
#include <filesystem>
#include <iostream>

namespace bldd::cmd {

namespace {

constexpr auto kVersion = "0.2.0";
constexpr auto kVersion = "0.2.1";

constexpr auto kDescription = "Backward LDD - Find all executable files that use specified shared libraries.\n"
"This tool scans directories for ELF executables and reports which executables\n"
Expand Down Expand Up @@ -105,6 +107,13 @@ Config Cli::build_config() const
{
Config config;

auto default_path = Config::get_default_path();
if (!default_path.empty() && std::filesystem::exists(default_path)) {
std::cerr << "Loading configuration from default path: "
<< default_path << "\n";
config = Config::load_from_file(default_path.string());
}

// Load from config file if specified
auto config_path = program_.get<std::string>("--config");
if (!config_path.empty()) {
Expand All @@ -121,8 +130,13 @@ Config Cli::build_config() const
config.library_filters = program_.get<std::vector<std::string>>("--library");
config.output_file = program_.get<std::string>("--output");
config.output_format = format_from_string(program_.get<std::string>("--format"));
config.verbose = program_.get<bool>("--verbose");
config.recursive = !program_.get<bool>("--no-recursive");

// Parse explicit flags
if (program_.get<bool>("--verbose"))
config.verbose = program_.get<bool>("--verbose");

if (!program_.get<bool>("--no-recursive"))
config.recursive = !program_.get<bool>("--no-recursive");

// Parse architecture filter
auto arch_str = program_.get<std::string>("--arch");
Expand Down
10 changes: 4 additions & 6 deletions tests/test_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ TEST_CASE("Config default values", "[config]")
{
bldd::Config config;

REQUIRE(config.scan_directories.size() == 2);
REQUIRE(config.scan_directories[0] == "/usr/bin");
REQUIRE(config.scan_directories[1] == "/usr/local/bin");
REQUIRE(config.scan_directories.size() == 0);
REQUIRE(config.library_filters.empty());
REQUIRE_FALSE(config.arch_filter.has_value());
REQUIRE(config.output_format == Config::OutputFormat::TXT);
Expand All @@ -54,7 +52,7 @@ TEST_CASE("Config load from nonexistent file", "[config]")
auto config = bldd::Config::load_from_file("/nonexistent/path/config.conf");

// Should return default config
REQUIRE(config.scan_directories.size() == 2);
REQUIRE(config.scan_directories.size() == 0);
REQUIRE(config.output_format == Config::OutputFormat::TXT);
}

Expand Down Expand Up @@ -87,7 +85,7 @@ TEST_CASE("Config parsing edge cases", "[config]")
auto config = bldd::Config::load_from_file(file.path());

// Should return default config
REQUIRE(config.scan_directories.size() == 2);
REQUIRE(config.scan_directories.size() == 0);
}

SECTION("Only comments")
Expand All @@ -100,7 +98,7 @@ TEST_CASE("Config parsing edge cases", "[config]")

auto config = bldd::Config::load_from_file(file.path());

REQUIRE(config.scan_directories.size() == 2);
REQUIRE(config.scan_directories.size() == 0);
}

SECTION("Whitespace handling")
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.