-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeRecord.h
More file actions
77 lines (70 loc) · 1.98 KB
/
MakeRecord.h
File metadata and controls
77 lines (70 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once
#include <algorithm>
#include <fstream>
#include <functional>
#include <iterator>
#include <map>
#include <regex>
#include <sstream>
#include <string>
#include <vector>
using std::function;
using std::map;
using std::string;
using std::vector;
/**
* Represents a structured version of a Makefile. Allows
* for ease of access to make rules, targets, dependencies, etc.
*/
class MakeRecord {
public:
/**
* Builds a new record from the Makefile in the program's execution
* working directory.
*/
MakeRecord();
/**
* Representative structure for a single make rule. Contains
* member variables for the rule's target as well its dependencies.
*/
class Rule {
public:
Rule(){/* Nothing */};
Rule(const string& t, const vector<string>& d)
: target(t), deps(d){/* Nothing */};
void addDeps(const vector<string>& other) {
deps.insert(deps.end(), other.begin(), other.end());
}
void removeDep(const string& dep) {
for (auto it = deps.begin(); it != deps.end(); it++) {
if (*it == dep) {
deps.erase(it);
return;
}
}
}
/* Internal class storage: */
string target;
vector<string> deps;
};
/**
* Retrieves a given rule from the Makefile.
*/
MakeRecord::Rule getRule(); /* Gets default rule */
MakeRecord::Rule getRule(const string& rule);
/**
* Checks if a rule exists in the current makefile instance
*/
bool ruleExists(const string& rule);
private:
/**
* Wrapper function for iterating over lines in
* a valid UTF-formatted Makefile using UNIX fs API.
* Throws an exception if no valid makefile is in
* the execution working directory.
*/
void __forEachLine(function<void(string)> cb);
/* Internal class storage for make rules */
map<string, Rule> __rules;
Rule defaultTarget;
};