42 int _mktemp_s(
char* templ) {
43 char* ofs = strchr(templ,
'X');
44 sprintf(ofs,
"%d", rand() % 1000000);
50 char* mkdtemp(
char* name_template) {
51 int err = _mktemp_s(name_template);
57 err = _mkdir(name_template);
67 string GetSystemTempDir() {
70 if (!GetTempPath(
sizeof(buf), buf))
74 const char* tempdir = getenv(
"TMPDIR");
90 " command = cat $in > $out\n");
112 for (vector<Edge*>::const_iterator e = state.
edges_.begin();
113 e != state.
edges_.end(); ++e) {
117 for (vector<Node*>::const_iterator in_node = (*e)->inputs_.begin();
118 in_node != (*e)->inputs_.end(); ++in_node) {
119 const vector<Edge*>& out_edges = (*in_node)->out_edges();
120 EXPECT_NE(find(out_edges.begin(), out_edges.end(), *e),
124 for (vector<Node*>::const_iterator out_node = (*e)->outputs_.begin();
125 out_node != (*e)->outputs_.end(); ++out_node) {
131 set<const Edge*> node_edge_set;
132 for (State::Paths::const_iterator p = state.
paths_.begin();
133 p != state.
paths_.end(); ++p) {
134 const Node* n = p->second;
136 node_edge_set.insert(n->
in_edge());
139 set<const Edge*> edge_set(state.
edges_.begin(), state.
edges_.end());
144 const string& contents) {
146 files_[path].contents = contents;
151 FileMap::const_iterator i =
files_.find(path);
153 *err = i->second.stat_error;
154 return i->second.mtime;
173 FileMap::iterator i =
files_.find(path);
175 *contents = i->second.contents;
178 *err = strerror(ENOENT);
186 FileMap::iterator i =
files_.find(path);
200 Fatal(
"couldn't get system temp dir");
202 Fatal(
"chdir: %s", strerror(errno));
205 char name_template[1024];
206 strcpy(name_template, name.c_str());
207 strcat(name_template,
"-XXXXXX");
208 char* tempname = mkdtemp(name_template);
210 Fatal(
"mkdtemp: %s", strerror(errno));
215 Fatal(
"chdir: %s", strerror(errno));
224 Fatal(
"chdir: %s", strerror(errno));
231 if (system(command.c_str()) < 0)
232 Fatal(
"system: %s", strerror(errno));
const vector< Edge * > & out_edges() const
void AssertParse(State *state, const char *input, ManifestParserOptions opts)
vector< Edge * > edges_
All the edges of the graph.
Node * GetNode(const string &path)
Short way to get a Node by its path from state_.
Node * GetNode(StringPiece path, uint64_t slash_bits)
Information about a node in the dependency graph: the file, whether it's dirty, mtime, etc.
set< string > files_removed_
virtual bool WriteFile(const string &path, const string &contents)
Create a file, with the specified name and contents Returns true on success, false on failure...
int now_
A simple fake timestamp for file operations.
StateTestWithBuiltinRules()
void Create(const string &path, const string &contents)
"Create" a file with contents.
set< string > files_created_
vector< string > directories_made_
void AddCatRule(State *state)
Add a "cat" rule to state.
string start_dir_
The temp directory containing our dir.
virtual bool MakeDir(const string &path)
Create a directory, returning false on failure.
Status
Result of ReadFile.
void VerifyGraph(const State &state)
void Fatal(const char *msg,...)
Log a fatal message and exit.
void Cleanup()
Clean up the temporary directory.
virtual TimeStamp Stat(const string &path, string *err) const
stat() a file, returning the mtime, or 0 if missing and -1 on other errors.
static uint64_t HashCommand(StringPiece command)
virtual Status ReadFile(const string &path, string *contents, string *err)
Read and store in given string.
void CreateAndEnter(const string &name)
Create a temporary directory and chdir into it.
Global state (file status) for a single run.
vector< string > files_read_
virtual int RemoveFile(const string &path)
Remove the file named path.
unsigned long long uint64_t
void AssertHash(const char *expected, uint64_t actual)
string temp_dir_name_
The subdirectory name for our dir, or empty if it hasn't been set up.
bool ParseTest(const string &input, string *err)
Parse a text string of input. Used by tests.