blob: e6e1b37185ce54b6ad071707133ee4a952893fbf (
plain) (
blame)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#include "Generator.h"
#include "FileSystemUtilities.h"
#include <iostream>
Generator::Generator(const std::vector<std::string>& aTemp)
: Template(aTemp), State(Unchecked)
{
}
Generator::Generator(const Generator& other)
: Template(other.Template), Input(other.Input), Output(other.Output), State(Unchecked)
{
}
ProcessController* Generator::createNextTask()
{
if (State != Unchecked) return 0;
State = Building;
std::vector<std::string> Args;
for (unsigned int i=1; i<Template.size(); ++i)
{
if (Template[i] == "$input")
for (unsigned int j=0; j<Input.size(); ++j)
Args.push_back(Input[j]);
else if (Template[i] == "$output")
Args.push_back(Output);
else
Args.push_back(Template[i]);
}
whisper(Template[0]);
for (unsigned int i=0; i<Args.size(); ++i)
whisper(" "+Args[i]);
whisper("\n");
return shellLaunchProcess(this,Template[0],Args)?this:0;
}
Generator* Generator::copy() const
{
return new Generator(*this);
}
void Generator::addInput(const std::string& anInput)
{
Input.push_back(pathAppend(configuration().sourcePath(),anInput));
}
void Generator::setOutput(const std::string& anOut)
{
Output = anOut;
}
const std::string& Generator::output() const
{
return Output;
}
void Generator::finished(int ret)
{
State = ret?Failed:Succeeded;
yieldFloor();
}
void Generator::standardOutput(const std::string& aString)
{
say(aString);
}
void Generator::standardError(const std::string& aString)
{
say(aString);
}
void Generator::failed()
{
State = Failed;
}
bool Generator::ready()
{
if (State == Unchecked)
checkState();
return State == Succeeded;
}
void Generator::checkState()
{
// no target set, always do this step
if (Output.empty())
return;
// target does not exist, do this step
if (!fileExists(Output))
return;
// an input file is newer, do this step
for (unsigned int i=0; i<Input.size(); ++i)
if (fileExists(Input[i]) && fileIsNewer(Input[i],Output))
return;
// output is already up to date
State = Succeeded;
}
|