Skip to content

Commit

Permalink
Added per-node 'is_precious' flag to indicate that outputs are precious.
Browse files Browse the repository at this point in the history
Closes GH-25.
  • Loading branch information
deplinenoise committed Aug 21, 2010
1 parent 3f7f8d5 commit 24f09be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ run_job(td_job_queue *queue, td_node *node, const char *line_prefix)

engine->stats.build_time += t2 - t1;

if (0 != result)
/* If the build failed, and the node isn't set to keep all its output files
* in all possible cases (precious), then delete all output files as we
* can't assume anything about their state. */
if (0 != result && 0 == (TD_NODE_PRECIOUS & node->flags))
{
pthread_mutex_unlock(&queue->mutex);
/* remove all output files */
Expand All @@ -171,7 +174,10 @@ run_job(td_job_queue *queue, td_node *node, const char *line_prefix)
pthread_mutex_lock(&queue->mutex);
}

/* mark all output files as dirty */
/* Mark all output files as dirty regardless of whether the build succeeded
* or not. If it succeeded, we must assume the build overwrote them.
* Otherwise, it's likely we've deleted them. In any case, touching them
* again isn't going to hurt anything.*/
for (i = 0, count = node->output_count; i < count; ++i)
td_touch_file(node->outputs[i]);

Expand Down
11 changes: 11 additions & 0 deletions src/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,13 @@ make_node(lua_State *L)
}
lua_pop(L, 1);

lua_getfield(L, 2, "is_precious");
if (lua_toboolean(L, -1))
node->flags = TD_NODE_PRECIOUS;
else
node->flags = 0;
lua_pop(L, 1);

node->deps = setup_deps(L, self, node, &node->dep_count);

setup_file_signers(L, self, node);
Expand Down Expand Up @@ -1245,6 +1252,10 @@ clean_file(td_engine *engine, td_node *node, td_file **dirs, int *dir_count, td_
dirs[index] = dir;
}

/* Don't delete the output of precious nodes. */
if (TD_NODE_PRECIOUS & node->flags)
return;

stat = td_stat_file(engine, file);

if (TD_STAT_EXISTS & stat->flags)
Expand Down
8 changes: 8 additions & 0 deletions src/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ typedef struct td_ancestor_data
time_t access_time;
} td_ancestor_data;

enum {
/* Don't delete node outputs on build error or when cleaning. Useful for
* build jobs that take a very long time to run. */
TD_NODE_PRECIOUS = 1 << 0,
};

typedef struct td_node
{
/* An annotation that should print when building this node.
Expand Down Expand Up @@ -182,6 +188,8 @@ typedef struct td_node
td_digest guid;
const td_ancestor_data *ancestor_data;

int flags;

td_job job;
} td_node;

Expand Down

0 comments on commit 24f09be

Please sign in to comment.