bob.hpp
Loading...
Searching...
No Matches
bob Namespace Reference

Contains the functionality of the Bob build system. More...

Namespaces

namespace  term
 Terminal related constants and functions.
 

Classes

class  Cli
 A command line interface (CLI) that can be used to run commands and subcommands. More...
 
class  CliCommand
 Represents a CLI command. More...
 
struct  CliFlag
 Represents a command flag argument. More...
 
class  Cmd
 Represents a command to be executed in the operating system shell. More...
 
struct  CmdFuture
 Represents a command that being executed in the background. More...
 
class  CmdRunner
 A class for running many commands in parallel. More...
 
struct  RebuildConfig
 Configuration for rebuilding the current executable. More...
 
class  Recipe
 A build recipe that defiles how to produce outputs from inputs. More...
 

Typedefs

typedef std::vector< fs::path > Paths
 A list of file paths.
 
typedef std::function< void(const vector< path > &, const vector< path > &)> RecipeFunc
 A function that can be used in a Recipe to build outputs from inputs.
 
typedef std::vector< CliFlagCliFlags
 A list of command line flags.
 
typedef std::function< int(CliCommand &)> CliCommandFunc
 A function that can be used to handle a command in a CLI.
 

Enumerations

enum class  CliFlagType { Bool , Value }
 Types of command line flags. More...
 

Functions

void go_rebuild_yourself (int argc, char *argv[], path source_file_name)
 
int run_yourself (fs::path bin, int argc, char *argv[])
 
bool file_needs_rebuild (path input, path output)
 
path mkdirs (path dir)
 
string I (path p)
 
path search_path (const string &bin_name)
 
void checklist (const vector< string > &items, const vector< bool > &statuses)
 
void ensure_installed (vector< string > packages)
 
bool find_root (path *root, string marker_file)
 
bool git_root (path *root)
 
void print_cli_args (const CliFlags &args)
 Prints the command line flags and their descriptions. Used for help output.
 

Detailed Description

Contains the functionality of the Bob build system.

Enumeration Type Documentation

◆ CliFlagType

enum class bob::CliFlagType
strong

Types of command line flags.

Enumerator
Bool 

Boolean flag, e.g. -v or --verbose.

Value 

Option with a value, e.g. -o file.txt or --output file.txt.

Function Documentation

◆ checklist()

void bob::checklist ( const vector< string > &  items,
const vector< bool > &  statuses 
)

Displays a checklist of items with their statuses.

Parameters
itemsA list of checklist item names.
statusesA list of boolean statuses; true means complete, false means incomplete.
Example
checklist({"Download", "Build", "Test"}, {true, false, false});
void checklist(const vector< string > &items, const vector< bool > &statuses)

◆ ensure_installed()

void bob::ensure_installed ( vector< string >  packages)

Ensures that the specified packages are installed. If they are not, a checklist is printed of the missing and found packages, and the program exits with an error code.

Parameters
packagesA list of package names to verify and install if missing.
Example
ensure_installed({"cmake", "ninja", "git"});
void ensure_installed(vector< string > packages)

◆ file_needs_rebuild()

bool bob::file_needs_rebuild ( path  input,
path  output 
)

Checks if an output file is older than its input file and needs to be rebuilt.

Parameters
inputThe source file path.
outputThe target file path.
Returns
true if the output is missing or older than the input; false otherwise.
Example
if (bob::file_needs_rebuild("main.cpp", "main.o")) {
// Compile `main.cpp` to `main.o`
}
bool file_needs_rebuild(path input, path output)

◆ find_root()

bool bob::find_root ( path *  root,
string  marker_file 
)

Finds the root directory containing a specific marker file.

Parameters
rootPointer to store the found root path.
marker_fileThe file name to look for in the directory hierarchy.
Returns
true if the root was found; false otherwise.
Example
path project_root;
if (find_root(&project_root, ".git")) {
std::cout << "Root: " << project_root << "\n";
}
bool find_root(path *root, string marker_file)

◆ git_root()

bool bob::git_root ( path *  root)

Finds the root of a Git repository.

Parameters
rootPointer to store the Git repository root path.
Returns
true if inside a Git repository; false otherwise.
Example
path git_root_path;
if (git_root(&git_root_path)) {
std::cout << "Git root: " << git_root_path << "\n";
}
bool git_root(path *root)

◆ go_rebuild_yourself()

void bob::go_rebuild_yourself ( int  argc,
char *  argv[],
path  source_file_name 
)

Rebuilds the current executable from its source file. After building the new executable, it will run the new executable with the same arguments as the current one. This function is called with GO_REBUILD_YOURSELF(argc, argv) macro which provides the source_file_name argument automatically.

◆ I()

string bob::I ( path  p)

Converts a path to a string with the -I prefix for use in compiler commands.

Parameters
pThe path to convert.
Returns
The path as a UTF-8 encoded string.
Example
Cmd compile({"g++", I("src"), "-o", "output"});
compile.run(); // Runs `g++ -Isrc -o output`
Represents a command to be executed in the operating system shell.
Definition bob.hpp:287
int run()
string I(path p)

◆ mkdirs()

path bob::mkdirs ( path  dir)

Creates a directory and all necessary parent directories.

Parameters
dirThe directory path to create.
Returns
The created directory path.
Examples
path build_dir = mkdirs("build/output");
path mkdirs(path dir)
or
path build_dir = "build/output";
mkdirs(build_dir);

◆ run_yourself()

int bob::run_yourself ( fs::path  bin,
int  argc,
char *  argv[] 
)

Runs the current executable and returns the exit status. This is used in the go_rebuild_yourself(int argc, char * argv[], path source_file_name) function.

◆ search_path()

path bob::search_path ( const string &  bin_name)

Searches for a binary in the system $PATH variable.

Parameters
bin_nameThe name of the binary to search for.
Returns
The path to the binary if found, otherwise an empty path.
Example
path git_bin = search_path("git");
if (git_bin.empty()) {
std::cerr << "git not found!\n";
}
path search_path(const string &bin_name)