Vuo 2.4.4
Loading...
Searching...
No Matches
VuoMakeDependencies.cc
Go to the documentation of this file.
1
11#include "VuoException.hh"
12#include "VuoFileUtilities.hh"
13#include "VuoStringUtilities.hh"
14
21shared_ptr<VuoMakeDependencies> VuoMakeDependencies::createFromFile(const string &dependencyFilePath)
22{
23 string contents = VuoFileUtilities::readFileToString(dependencyFilePath);
24 VuoStringUtilities::replaceAll(contents, "\\\n", "");
25
26 string compiledFilePath;
27 vector<string> dependencyPaths;
28 size_t startPos = 0;
29 for (size_t i = 1; i < contents.length(); ++i)
30 {
31 if (compiledFilePath.empty() && contents[i] == ':' && contents[i-1] != '\\')
32 {
33 compiledFilePath = contents.substr(startPos, i-startPos);
34 startPos = i+1;
35 }
36 else if ((contents[i] == ' ' && contents[i-1] != '\\') || i == contents.length()-1)
37 {
38 string dependency = contents.substr(startPos, i-startPos);
39 dependency = VuoStringUtilities::trim(dependency);
40 if (! dependency.empty())
41 dependencyPaths.push_back(dependency);
42 startPos = i+1;
43 }
44 }
45
46 if (compiledFilePath.empty())
47 throw VuoException("Dependency file '%s' doesn't begin with a target path.");
48
49 return shared_ptr<VuoMakeDependencies>(new VuoMakeDependencies(compiledFilePath, dependencyPaths));
50}
51
55shared_ptr<VuoMakeDependencies> VuoMakeDependencies::createFromComponents(const string &compiledFilePath, const vector<string> &dependencyPaths)
56{
57 return shared_ptr<VuoMakeDependencies>(new VuoMakeDependencies(compiledFilePath, dependencyPaths));
58}
59
63VuoMakeDependencies::VuoMakeDependencies(const string &compiledFilePath, const vector<string> &dependencyPaths) :
64 compiledFilePath(compiledFilePath),
65 dependencyPaths(dependencyPaths)
66{
67}
68
74{
75 return "PLACEHOLDER";
76}
77
81void VuoMakeDependencies::setCompiledFilePath(const string &compiledFilePath)
82{
83 this->compiledFilePath = compiledFilePath;
84}
85
90{
91 return dependencyPaths;
92}
93
97void VuoMakeDependencies::setDependencyPaths(const vector<string> &dependencyPaths)
98{
99 this->dependencyPaths = dependencyPaths;
100}
101
108void VuoMakeDependencies::writeToFile(const string &dependencyFilePath)
109{
110 if (compiledFilePath == getPlaceholderCompiledFilePath())
111 throw VuoException("Before writing the VuoMakeDependencies to file, replace its placeholder compiled file path.");
112
113 string contents = compiledFilePath + ": \\\n" +
114 VuoStringUtilities::join(dependencyPaths, " \\\n") +
115 "\n";
116 VuoFileUtilities::writeStringToFile(contents, dependencyFilePath);
117}