41 std::vector<std::string>* pargs) {
50 std::ofstream makefile;
51 makefile.open(this->
OUT, std::ios::app);
52 std::string name =
"";
82 name += *(args->
get(
"toolchain_id"));
84 name += *(args->
get(
"task_id"));
90 makefile << name <<
":\n";
91 for (
auto elem : *
log) {
92 makefile <<
"\t" << elem <<
"\n";
113std::string
eval_cmd(std::array<std::string, 4> data) {
114 std::string
cmd = data[2] +
" -c ";
192 std::vector<std::string>* pargs) {
199 if (*(args->
get(
"toolchain_id")) == std::string(
"all")) {
208 auto cmds = toolchain->get_cmds();
209 if (cmds[0] != std::string(
"META") && cmds[1] != std::string(
"META") &&
210 cmds[2] != std::string(
"META")) {
211 toolchain->call(pargs,
true,
false,
true);
212 auto files = toolchain->gen_file_list_force();
213 auto targs = toolchain->get_compile_args();
214 auto dir = args->
get_ptr(
"curr_path")->data;
215 for (
auto file : files) {
219 std::array<std::string, 4>{file.key, file.data, cmds[0], targs}),
225 CBuild::print(
"This can breaks if compile_commands.json already exists and "
226 "this file was not created by CBuild!",
231 std::fstream ccj(this->OUT);
233 for (
unsigned int j = 0; j < data.
size(); j++) {
234 auto elem = data.
at(j);
240 ccj << (std::string(
"\t\"directory\": \"") + dir + std::string(
"\",\n"));
241 ccj << (std::string(
"\t\"command\": \"") +
243 ccj << (std::string(
"\t\"file\": \"") + elem.data.file + std::string(
"\"\n"));
255 size_t pos = str.find(
"\"file\":");
256 if (pos != std::string::npos) {
258 size_t st = str.find_first_of(
'"', pos + 7);
259 size_t ed = str.find_last_of(
'"');
260 std::string fname = str.substr(st + 1, ed - st - 1);
261 auto elem = data.
get_ptr(fname);
265 std::string(
"\" that is recompiled, replacing "
266 "\"command\" entry"));
268 ccj.
set_line(std::string(
"\t\"command\": \"") +
273 elem->data.in_file =
true;
278 }
catch (std::exception& e) {
283 for (
unsigned int j = 0; j < data.
size(); j++) {
284 auto elem = data.
at(j);
285 if (elem.data.in_file ==
false) {
287 std::string(
"\", inserting new entry"));
293 ccj.
set_line(std::string(
"\t\"directory\": \"") + dir + std::string(
"\","),
296 ccj.
set_line(std::string(
"\t\"command\": \"") +
301 ccj.
set_line(std::string(
"\t\"file\": \"") + elem.data.file +
Main headers of CBuild core.
Generator for compile_command.json.
virtual bool init() override
Some init.
virtual void generate(CBuild::RType mode, lib::map< std::string, std::string > *args, std::vector< std::string > *pargs) override
Generate some output.
std::string get_line(unsigned int pos)
Get line from buffer.
void set_line(std::string str, unsigned int pos)
Set line in file.
void del_line(unsigned int pos)
Delete line from file.
void update()
Update file/buffer based on internal state variable.
virtual bool init() override
Some init.
virtual void generate(CBuild::RType mode, lib::map< std::string, std::string > *args, std::vector< std::string > *pargs) override
Generate some output.
Simple map implementation with some stack operation added.
__SIZE_TYPE__ size()
Size of map.
void push_back(lib::mapData< _K, _D > element)
Push new element to map, stack operation ! Dangerous not perform chak if this elemnt exists in map.
const _D * get(_K key)
Get element by it's key.
lib::mapData< _K, _D > at(__SIZE_TYPE__ i)
Array operation, get element at index.
lib::mapData< _K, _D > * get_ptr(_K key)
Get reference to key and value of map.
Custom implementation of map datatype.
CBuild::Toolchain * GetToolchain(std::string name, bool force=false)
Get the registered toolchain.
bool exists(std::string path)
Check if file exists.
bool create(std::vector< std::string > paths, CBuild::fs::type what)
Create element.
Filebuffer for CBuild ecosystem.
void print(std::string msg, color fg=CBuild::WHITE)
Print colored text to STDOUT.
std::vector< std::string > * get_log()
Get the internall command log.
std::string eval_cmd(std::array< std::string, 4 > data)
Evaluate compilation cmd.
std::string preprocess_json_str(std::string_view str)
Preprocess string for json.
@ DEBUG
Build and run target in debug mode.
@ CLEAR
Clear build output and cache.
@ BUILD_RUN
Build and run target.
void disable_system()
Disable system commands execution.
std::string get_random_string(unsigned int length)
Generate random string with specified range, on Linux can use /dev/urandom.
void print_full(std::string msg, color fg=CBuild::WHITE)
Print colored text to STDOUT if verbose flag is set.
std::vector< std::string > log
Custom print that support color codes.
Command for compile_commands.json.
std::string base_path
"directory":
bool in_file
Does this entry is already in file.
std::string cmd
"command":