CBuild
C++ build system with scripts written in c++
Loading...
Searching...
No Matches
cbuild_hash.hpp
Go to the documentation of this file.
1
22// C++ libraries
23#include "../map.hpp"
24#include "string"
25#include "vector"
26// Project includes
27#include "../build_data.hpp"
28#include "../print.hpp"
29#include "hasher.hpp"
30// Code
31#ifndef __CBUILD_HASH_HPP__
32#define __CBUILD_HASH_HPP__
33namespace CBuild {
34class CBuildHashV2 : public CBuild::Hash {
35 public:
38 get_files_for_recompilation(std::vector<std::string> file_list,
39 std::vector<std::string> objects_list) override;
40 virtual int compare_and_set_cargs(std::vector<std::string> cargs) override {
42 if (CBuild::read_target_metadata(this->target_id, &meta) != 0) {
43 return -1;
44 }
45 if (cargs != meta.cargs) {
46 meta.cargs = cargs;
48 CBuild::printf_full(CBuild::RED, "Compilation arguments mismatch.\n");
49 return 1;
50 }
51 return 0;
52 }
53 virtual int compare_and_set_largs(std::vector<std::string> largs) override {
55 if (CBuild::read_target_metadata(this->target_id, &meta) != 0) {
56 return -1;
57 }
58 if (largs != meta.largs) {
59 meta.largs = largs;
61 CBuild::printf_full(CBuild::RED, "Link arguments mismatch.\n");
62 return 1;
63 }
64 return 0;
65 }
66 virtual int compare_and_set_commands(std::string compiler, std::string linker,
67 std::string packer) override {
69 if (CBuild::read_target_metadata(this->target_id, &meta) != 0) {
70 return -1;
71 }
72 if (compiler != meta.compiler || linker != meta.linker || packer != meta.packer) {
73 meta.compiler = compiler;
74 meta.linker = linker;
75 meta.packer = packer;
77 CBuild::printf_full(CBuild::RED, "Compilation commands mismatch.\n");
78 return 1;
79 }
80 return 0;
81 }
82 virtual int compare_and_set_output_file(std::string out) override {
84 if (CBuild::read_target_metadata(this->target_id, &meta) != 0) {
85 return -1;
86 }
87 if (out != meta.out) {
88 meta.out = out;
90 CBuild::printf_full(CBuild::RED, "Output binary name mismatch: '%s' != '%s'\n",
91 out.c_str(), meta.out.c_str());
92 return 1;
93 }
94 return 0;
95 }
96 virtual void set_target_meta(std::vector<std::string> cargs, std::vector<std::string> largs,
97 std::string out, std::string compiler, std::string linker,
98 std::string packer) override {
100 meta.cargs = cargs;
101 meta.largs = largs;
102 meta.out = out;
103 meta.compiler = compiler;
104 meta.linker = linker;
105 meta.packer = packer;
107 }
108};
109} // namespace CBuild
110#endif // __CBUILD_HASH_HPP__
Build metadata config file.
CBuildHashV2(std::string target_id)
virtual int compare_and_set_output_file(std::string out) override
Compare output file name and update metadata.
virtual void set_target_meta(std::vector< std::string > cargs, std::vector< std::string > largs, std::string out, std::string compiler, std::string linker, std::string packer) override
Set the target meta.
virtual int compare_and_set_largs(std::vector< std::string > largs) override
Compare link args and update metadata.
virtual int compare_and_set_commands(std::string compiler, std::string linker, std::string packer) override
Compare shell commands used for compilation and update metadata.
virtual lib::map< std::string, std::string > get_files_for_recompilation(std::vector< std::string > file_list, std::vector< std::string > objects_list) override
Pass a list of source files and coresponding object files and get a map of source-object that need to...
virtual int compare_and_set_cargs(std::vector< std::string > cargs) override
Compare compile args and update metadata.
std::string target_id
Definition hasher.hpp:64
Simple map implementation with some stack operation added.
Definition map.hpp:79
Hasher base class and some helper functions This file implements some helper funtions,...
Custom implementation of map datatype.
Filebuffer for CBuild ecosystem.
Definition Build.hpp:34
void void printf_full(color fg, const char *fmt,...) __attribute__((format(printf
Some poor printf implementation for verbouse-only prints.
Definition print.cpp:89
@ RED
Definition print.hpp:34
int read_target_metadata(std::string target_id, CBuild::target_metadata_file *metadata)
Load metadata for a full target.
int write_target_metadata(std::string target_id, CBuild::target_metadata_file *metadata)
Write a metadata for a full target.
Custom print that support color codes.
Metadata for a full toolchain Structure of file:
std::string out
Path to output binary (relative to CBuild.run)
std::string packer
Command used to pack this target to a static library (what shell command was used)
std::vector< std::string > largs
Link args.
std::vector< std::string > cargs
Compile args.
std::string linker
Command used to link this target (what shell command was used)
std::string compiler
Command used to compile this target (what shell command was used)