BuildCache
Classes | Functions
bcache::sys Namespace Reference

System utility functions. More...

Classes

struct  run_result_t
 Run results from an external command. More...
 

Functions

run_result_t run (const string_list_t &args, const bool quiet=true, const std::string &work_dir=std::string())
 Run the given command. More...
 
run_result_t run_with_prefix (const string_list_t &args, const bool quiet=true, const std::string &work_dir=std::string())
 Run the given command with an optional prefix. More...
 
void open_in_default_editor (const std::string &path)
 Open a file in the user default editor. More...
 
void print_raw_stdout (const std::string &str)
 Print a string to stdout. More...
 
void print_raw_stderr (const std::string &str)
 Print a string to stderr. More...
 
std::string get_local_temp_folder ()
 Get the temporary folder for this BuildCache instance. More...
 

Detailed Description

System utility functions.

Function Documentation

◆ get_local_temp_folder()

std::string bcache::sys::get_local_temp_folder ( )

Get the temporary folder for this BuildCache instance.

The temporary folder is located somewhere under $BUILDCACHE_DIR, and as such is suitable for files that later need to be moved or linked inside the local cache structure (for instance). The folder can also be considered a separate namespace that is dedicated to BuildCache, which means that it is very unlikely that there will be any file name conflicts with other programs.

◆ open_in_default_editor()

void bcache::sys::open_in_default_editor ( const std::string &  path)

Open a file in the user default editor.

Parameters
pathPath to the file to edit.

◆ print_raw_stderr()

void bcache::sys::print_raw_stderr ( const std::string &  str)

Print a string to stderr.

Unlike using standard C++ methods, such as writing to std::cerr, this function sends the string to stderr without any text mode translations (such as LF -> CRLF). This is useful for correctly reproducing program output 1:1 (especially important on Windows).

Parameters
strThe string to be printed.
Exceptions
runtime_errorif the string could not be printed.

◆ print_raw_stdout()

void bcache::sys::print_raw_stdout ( const std::string &  str)

Print a string to stdout.

Unlike using standard C++ methods, such as writing to std::cout, this function sends the string to stdout without any text mode translations (such as LF -> CRLF). This is useful for correctly reproducing program output 1:1 (especially important on Windows).

Parameters
strThe string to be printed.
Exceptions
runtime_errorif the string could not be printed.

◆ run()

run_result_t bcache::sys::run ( const string_list_t args,
const bool  quiet = true,
const std::string &  work_dir = std::string() 
)

Run the given command.

Parameters
argsThe command and its arguments (the first item is the command).
quietSupress output to stdout/stderr during execution.
work_dirSet the CWD during the execution of the command.
Returns
The result from the command.
Exceptions
runtime_errorif the command could not be run.

◆ run_with_prefix()

run_result_t bcache::sys::run_with_prefix ( const string_list_t args,
const bool  quiet = true,
const std::string &  work_dir = std::string() 
)

Run the given command with an optional prefix.

Unlike the run() function, this function will optinally use a prefix (wrapper) as specified by the environment variable BUILDCACHE_PREFIX.

Parameters
argsThe command and its arguments (the first item is the command).
quietSupress output to stdout/stderr during execution.
work_dirSet the CWD during the execution of the command.
Returns
The result from the command.
Exceptions
runtime_errorif the command could not be run.