CBuild
C++ build system with scripts written in c++
Loading...
Searching...
No Matches
manual_hash.hpp
Go to the documentation of this file.
1
21#ifndef __MANUAL_HASH_HPP__
22#define __MANUAL_HASH_HPP__
23// C++ libs
24#include "string"
25#include "vector"
26// Project headers
27#include "../build_data.hpp"
28#include "../hash.hpp"
29#include "../map.hpp"
30#include "hasher.hpp"
31// Code
32namespace CBuild {
33class CBuildHash : public CBuild::Hash {
34 protected:
35 std::string gen_out_file(std::string file) {
36 // path to base diretory for out files
37 std::string base =
38 CBUILD_BUILD_DIR + "/" + this->target_id + "/" + CBUILD_BUILD_CACHE_DIR + "/";
39 // Find dot in file name
40 unsigned long pos = file.find_last_of(".");
41 // Cut it out
42 file = file.substr(0, pos);
43 // Replace all slashes by dots
44 while (file.find("/") != std::string::npos) {
45 file.replace(file.find("/"), std::string("/").size(), ".");
46 }
47 // Add .o extension
48 file += ".o";
49 // Return full path
50 base += file;
51 return base;
52 }
53
54 public:
57 get_files_for_recompilation(std::vector<std::string> file_list,
58 std::vector<std::string> objects_list) override {
59 if (file_list.size() != objects_list.size()) {
60 return {};
61 }
62 auto files = CBuild::get_files(file_list, objects_list, this->target_id);
64 for (size_t i = 0; i < files.size(); i++) {
65 ret.push_back(files.at(i), this->gen_out_file(files.at(i)));
66 }
67 return ret;
68 }
69 virtual int compare_and_set_cargs(std::vector<std::string> cargs) override {
71 if (CBuild::read_target_metadata(this->target_id, &meta) != 0) {
72 return -1;
73 }
74 if (cargs != meta.cargs) {
75 meta.cargs = cargs;
77 return 1;
78 }
79 return 0;
80 }
81 virtual int compare_and_set_largs(std::vector<std::string> largs) override {
83 if (CBuild::read_target_metadata(this->target_id, &meta) != 0) {
84 return -1;
85 }
86 if (largs != meta.largs) {
87 meta.largs = largs;
89 return 1;
90 }
91 return 0;
92 }
93 virtual int compare_and_set_commands(std::string compiler, std::string linker,
94 std::string packer) override {
96 if (CBuild::read_target_metadata(this->target_id, &meta) != 0) {
97 return -1;
98 }
99 if (compiler != meta.compiler || linker != meta.linker || packer != meta.packer) {
100 meta.compiler = compiler;
101 meta.linker = linker;
102 meta.packer = packer;
104 return 1;
105 }
106 return 0;
107 }
108 virtual int compare_and_set_output_file(std::string out) override {
110 if (CBuild::read_target_metadata(this->target_id, &meta) != 0) {
111 return -1;
112 }
113 if (out != meta.out) {
114 meta.out = out;
116 return 1;
117 }
118 return 0;
119 }
120 virtual void set_target_meta(std::vector<std::string> cargs, std::vector<std::string> largs,
121 std::string out, std::string compiler, std::string linker,
122 std::string packer) override {
124 meta.cargs = cargs;
125 meta.largs = largs;
126 meta.out = out;
127 meta.compiler = compiler;
128 meta.linker = linker;
129 meta.packer = packer;
131 }
132};
133} // namespace CBuild
134#endif // __MANUAL_HASH_HPP__
#define CBUILD_BUILD_CACHE_DIR
Object cache in build/toolchain.
#define CBUILD_BUILD_DIR
Build directory of CBuild.
Build metadata config file.
std::string gen_out_file(std::string file)
virtual int compare_and_set_output_file(std::string out) override
Compare output file name 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.
CBuildHash(std::string target_id)
virtual int compare_and_set_largs(std::vector< std::string > largs) override
Compare link args 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_commands(std::string compiler, std::string linker, std::string packer) override
Compare shell commands used for compilation and update metadata.
std::string target_id
Definition hasher.hpp:64
Simple map implementation with some stack operation added.
Definition map.hpp:79
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.
Definition map.hpp:111
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
std::vector< std::string > get_files(std::vector< std::string > files, std::vector< std::string > objects, std::string toolchain_id)
Get changed files.
Definition hash.cpp:395
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.
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)