Skip to content

AkhileshManda/Bnao

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BNAO - Build and Organize

A make-like build tool written in Rust that provides dependency resolution and task execution capabilities.

Overview

BNAO is a simple yet powerful build automation tool that allows you to define tasks with dependencies and execute them in the correct order. It's similar to Make.

Features

  • Dependency Resolution: Automatically resolves task dependencies using topological sorting
  • Cycle Detection: Prevents circular dependencies with built-in cycle detection
  • Task Execution: Executes shell commands for each task
  • Simple Syntax: Easy-to-read task definition format
  • CLI Interface: Command-line interface for listing and building targets

Installation

Prerequisites

  • Rust 1.70+ (2024 edition)
  • Cargo package manager

Building from Source

# Clone the repository
git clone <repository-url>
cd bnao-own

# Build the project
cargo build --release

# Install globally (optional)
cargo install --path .

Usage

Basic Commands

# List all available targets
bnao list

# Build a specific target
bnao build <target-name>

Example

# List available targets
bnao list

# Build the 'link' target (which will also build its dependencies)
bnao build link

Task Definition Format

BNAO uses a simple text-based format for defining tasks. Create a file named bnao_dependency_file in your project root:

# Clean build artifacts
clean:
    echo "Cleaning build directory..."
    rm -rf build/
    mkdir -p build/
    echo "Build directory cleaned"

# Compile source files
compile: clean
    echo "Compiling source files..."
    gcc -c src/main.c -o build/main.o
    gcc -c src/utils.c -o build/utils.o
    echo "Compilation complete"

# Link object files into executable
link: compile
    echo "Linking object files..."
    gcc build/main.o build/utils.o -o build/myapp
    echo "Linking complete"

# Run tests (depends on link)
test: link
    echo "Running tests..."
    ./build/myapp --test
    echo "All tests passed"

Syntax Rules

  1. Target Definition: Targets are defined with a colon (:) at the end of the line
  2. Dependencies: Dependencies are listed after the colon, separated by spaces
  3. Commands: Commands are indented with tabs or 4 spaces
  4. Comments: Lines starting with # are treated as comments
  5. Empty Lines: Empty lines are ignored

Project Structure

bnao-own/
├── src/
│   ├── main.rs              # CLI interface and main entry point
│   ├── bnao_parser.rs       # Parser for BNAO files
│   ├── dependency_resolver.rs # Dependency resolution logic
│   └── bnao_executor.rs     # Task execution engine
├── bnao_dependency_file     # Example task definitions
├── sample_bnao_file         # Simple example file
├── Cargo.toml              # Rust project configuration
└── README.md               # This file

Core Components

1. Parser (bnao_parser.rs)

  • Parses BNAO files into structured task definitions
  • Handles comments, empty lines, and command indentation
  • Returns a HashMap of task names to BnaoTask structs

2. Dependency Resolver (dependency_resolver.rs)

  • Implements topological sorting for dependency resolution
  • Detects circular dependencies
  • Returns tasks in the correct execution order

3. Executor (bnao_executor.rs)

  • Executes shell commands for each task
  • Handles command failures and error reporting
  • Provides output from successful commands

Error Handling

BNAO provides comprehensive error handling for:

  • Circular Dependencies: Detects and reports circular dependency chains
  • Missing Tasks: Reports when referenced tasks don't exist
  • Command Failures: Captures and displays command execution errors
  • Parse Errors: Reports syntax errors in BNAO files

Example Use Cases

C/C++ Project Build

clean:
    rm -rf build/
    mkdir -p build/

compile: clean
    gcc -c src/main.c -o build/main.o
    gcc -c src/utils.c -o build/utils.o

link: compile
    gcc build/main.o build/utils.o -o build/myapp

test: link
    ./build/myapp --test

install: link
    cp build/myapp /usr/local/bin/

Node.js Project

install:
    npm install

build: install
    npm run build

test: build
    npm test

deploy: test
    npm run deploy

Dependencies

  • clap: Command-line argument parsing
  • std: Standard library for file I/O, process execution, and collections

Development

Running Tests

cargo test

Building for Development

cargo build

Running the Binary

cargo run -- list
cargo run -- build <target>

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is open source. Please check the license file for details.

About

Making my own make

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages