CBuild
C++ build system with scripts written in c++
Loading...
Searching...
No Matches
Enumerations | Functions
CBuild::fs Namespace Reference

Enumerations

enum  type {
  FILE , DIRECTORY , DIR , SYMLINK_FILE ,
  SYMLINK_DIRECTORY , SYMLINK_DIR , HARDLINK
}
 Type for element creating. More...
 

Functions

int replace (std::string file, std::string token, std::string data)
 Replace [token] by [data] in [file].
 
int set_var (std::string file, std::string var_type, std::string var_name, std::string data)
 Set value of variable with type var_type wth name var_name to data This function loocks for variable like this: <var_type> <var_name>, then it gets all before <var_type> and saves it to variable. Then it gets all after first ; and saves it to variable or if we do define, simply skips this part, (so be careful with including something after define, or after replacing multiline define). Then it reconstruct variable part to <var_type> <var_name> = <date> or #define <var_name> <date> if we do define (var_name == define or #define). Then it reconstruct line from prefix, variable and postfix and writes it to file.
 
std::string path_to_file (std::string in)
 Convert path to filename by replacing '\' by '.'.
 
std::vector< std::string > dir (std::string path, std::string search)
 Search files using provided regex.
 
std::vector< std::string > dir (std::string path)
 Search files using standard regex (".*\.(cpp|cxx|cc|c)")
 
std::vector< std::string > dir_rec (std::string path, std::string search)
 Recursively search files using provided regex.
 
std::vector< std::string > dir_rec (std::string path)
 Recursively search files using standard regex (".*\.(cpp|cxx|cc|c)")
 
bool remove (std::string path, bool force=false)
 Delete files or directories.
 
bool copy (std::string start, std::string end)
 Copy files or directories.
 
bool move (std::string start, std::string end)
 Move files or directories, remove starting files or directories.
 
bool rename (std::string start, std::string end)
 Rename files or directories,.
 
bool create (std::vector< std::string > paths, CBuild::fs::type what)
 Create element.
 
bool exists (std::string path)
 Check if file exists.
 
std::string normalize_path (std::string path, std::string base_path="")
 Get absolute path to file using relative path and base path.
 
std::string normalize_relative_path (std::string path, std::string base_path="")
 Get absolute path to file using relative path and base path.
 
std::string base (std::string file)
 Get base file path (path to dir in what file is)
 
std::string curr_path ()
 Get current working dir of CBuild.run process.
 
std::regex c_cpp_file (".*\\.(cpp|cxx|cc|c)")
 

Enumeration Type Documentation

◆ type

Type for element creating.

Enumerator
FILE 

Standard file.

DIRECTORY 

Standard directory.

DIR 

Alias for DIRECTORY.

SYMLINK_FILE 

Standard symlink (can be unsupported or supported partially) (thought std::filesystem::create_symlink)

SYMLINK_DIRECTORY 

Standard symlink (can be unsupported or supported partially) (std::filesystem::create_directory_symlink)

SYMLINK_DIR 

Alias for SYMLINK_DIRECTORY.

HARDLINK 

Standard hardlink (can be unsupported or supported partially) (though std::filesystem::create_hard_link)

Definition at line 34 of file filesystem++.hpp.

Function Documentation

◆ base()

std::string CBuild::fs::base ( std::string file)

Get base file path (path to dir in what file is)

Parameters
file=> std::string -> Filepath

Definition at line 365 of file filesystem++.cpp.

Referenced by CBuild::get_file_data(), and parse_file().

◆ c_cpp_file()

std::regex CBuild::fs::c_cpp_file ( ".*\\.(cpp|cxx|cc|c)" )

Referenced by dir(), and dir_rec().

◆ copy()

bool CBuild::fs::copy ( std::string start,
std::string end )

Copy files or directories.

Parameters
start=> std::string -> path to file or directory
end=> std::string -> path to file or directory after copy
Returns
bool -> success or failure

Definition at line 178 of file filesystem++.cpp.

Referenced by CBuild::MINGW_GXX< hash >::post_link(), CBuild::MINGW_GXXMT< hash >::post_link(), CBuild::MINGW_GCC< hash >::post_link(), CBuild::MINGW_GCCMT< hash >::post_link(), and CBuild::CBuildDependency::prepare().

◆ create()

bool CBuild::fs::create ( std::vector< std::string > paths,
CBuild::fs::type what )

Create element.

Parameters
paths=> std::vector<std::string> -> Path to new element or path to file and then to link for symlinks and hardlinks
what=> CBuild::fs::type -> What create (custom enum type)
Returns
bool -> success or failure

Definition at line 210 of file filesystem++.cpp.

References DIR, DIRECTORY, FILE, HARDLINK, SYMLINK_DIR, SYMLINK_DIRECTORY, and SYMLINK_FILE.

Referenced by CBuild::Init::call(), CBuild::ccj_out::generate(), CBuild::makefile_out::generate(), CBuild::NetDependency::git_fetch(), CBuild::Toolchain::init(), CBuild::loop(), CBuild::CBuildDependency::prepare(), replace(), set_var(), and CBuild::store_hash().

◆ curr_path()

std::string CBuild::fs::curr_path ( )

Get current working dir of CBuild.run process.

Returns
std::string -> Path

Definition at line 368 of file filesystem++.cpp.

Referenced by normalize_relative_path().

◆ dir() [1/2]

std::vector< std::string > CBuild::fs::dir ( std::string path)

Search files using standard regex (".*\.(cpp|cxx|cc|c)")

Parameters
path=> std::string -> Starting path for search
Returns
std::vector<std::string> -> list of found files

Definition at line 63 of file filesystem++.cpp.

References c_cpp_file(), CBuild::printf_full(), and CBuild::RED.

◆ dir() [2/2]

std::vector< std::string > CBuild::fs::dir ( std::string path,
std::string search )

Search files using provided regex.

Parameters
path=> std::string -> Starting path for search
search=> std::string -> Search regex
Returns
std::vector<std::string> -> list of found files

Definition at line 39 of file filesystem++.cpp.

References CBuild::printf_full(), and CBuild::RED.

Referenced by CBuild::Toolchain::gen_file_list(), CBuild::load_hash(), and CBuild::CBuildDependency::prepare().

◆ dir_rec() [1/2]

std::vector< std::string > CBuild::fs::dir_rec ( std::string path)

Recursively search files using standard regex (".*\.(cpp|cxx|cc|c)")

Parameters
path=> std::string -> Starting path for search
Returns
std::vector<std::string> -> list of found files

Definition at line 109 of file filesystem++.cpp.

References c_cpp_file(), CBuild::printf_full(), and CBuild::RED.

◆ dir_rec() [2/2]

std::vector< std::string > CBuild::fs::dir_rec ( std::string path,
std::string search )

Recursively search files using provided regex.

Parameters
path=> std::string -> Starting path for search
search=> std::string -> Search regex
Returns
std::vector<std::string> -> list of found files

Definition at line 85 of file filesystem++.cpp.

References CBuild::printf_full(), and CBuild::RED.

◆ exists()

bool CBuild::fs::exists ( std::string path)

◆ move()

bool CBuild::fs::move ( std::string start,
std::string end )

Move files or directories, remove starting files or directories.

Parameters
start=> std::string -> path to file or directory
end=> std::string -> path to file or directory after move
Returns
bool -> success or failure

Definition at line 193 of file filesystem++.cpp.

References remove().

Referenced by replace(), and set_var().

◆ normalize_path()

std::string CBuild::fs::normalize_path ( std::string path,
std::string base_path = "" )

Get absolute path to file using relative path and base path.

Parameters
path=> std::string -> Relative path to file
base_path=> std::string -> Base path of this reative path, "" to none
Returns
std::string -> Absolute path

Definition at line 348 of file filesystem++.cpp.

◆ normalize_relative_path()

std::string CBuild::fs::normalize_relative_path ( std::string path,
std::string base_path = "" )

Get absolute path to file using relative path and base path.

Parameters
path=> std::string -> Relative path to file
base_path=> std::string -> Base path of this reative path, "" to none
Returns
std::string -> Path relative to working dir of CBuild executable

Definition at line 356 of file filesystem++.cpp.

References curr_path().

Referenced by CBuild::gcc_hash_impl(), CBuild::Toolchain::gen_file_list(), CBuild::get_file_data(), and parse_file().

◆ path_to_file()

std::string CBuild::fs::path_to_file ( std::string in)

Convert path to filename by replacing '\' by '.'.

Parameters
in=> std::string -> Input path
Returns
std::string -> Filename

Definition at line 118 of file files.cpp.

Referenced by replace(), and set_var().

◆ remove()

bool CBuild::fs::remove ( std::string path,
bool force = false )

Delete files or directories.

Parameters
path=> std::string -> path to file or directory
force=> remove_all in place of remove
Returns
bool -> success or failure

Definition at line 147 of file filesystem++.cpp.

Referenced by CBuild::NetDependency::git_fetch(), move(), replace(), and set_var().

◆ rename()

bool CBuild::fs::rename ( std::string start,
std::string end )

Rename files or directories,.

Exceptions
std::runtime_errorwith error message as string
Parameters
start=> std::string -> path to file or directory
end=> std::string -> new name (without path)
Returns
bool -> success or failure

Definition at line 131 of file filesystem++.cpp.

◆ replace()

int CBuild::fs::replace ( std::string file,
std::string token,
std::string data )

Replace [token] by [data] in [file].

Filebuffer for CBuild ecosystem.

Parameters
file=> std::string -> Path to file
token=> std::string -> Token for replacing
data=> std::string -> Data that replace token
Returns
int -> -1 = error, else - number of replaced tokens
Author
WolodiaM (w_mel.nosp@m.nyk@.nosp@m.outlo.nosp@m.ok.c.nosp@m.om)
Date
Fri May 12 10:58:05 AM EEST 2023

@license GPL v3.0 or later

Copyright (C) 2022 WolodiaM This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Definition at line 28 of file files.cpp.

References CBUILD_CACHE_DIR, CBUILD_COPY_CACHE_DIR, create(), FILE, move(), path_to_file(), and remove().

◆ set_var()

int CBuild::fs::set_var ( std::string file,
std::string var_type,
std::string var_name,
std::string data )

Set value of variable with type var_type wth name var_name to data This function loocks for variable like this: <var_type> <var_name>, then it gets all before <var_type> and saves it to variable. Then it gets all after first ; and saves it to variable or if we do define, simply skips this part, (so be careful with including something after define, or after replacing multiline define). Then it reconstruct variable part to <var_type> <var_name> = <date> or #define <var_name> <date> if we do define (var_name == define or #define). Then it reconstruct line from prefix, variable and postfix and writes it to file.

Parameters
file=> std::string -> Path to file for replacing
var_type=> std::string -> Type of variable
var_name=> std::string -> Name of variable
data=> std::string -> New value of variable
Returns
int -> -1 - error, else - number of replaced tokens

Definition at line 63 of file files.cpp.

References CBUILD_CACHE_DIR, CBUILD_COPY_CACHE_DIR, create(), FILE, move(), path_to_file(), and remove().