aboutsummaryrefslogtreecommitdiff
path: root/src/conditionfiletime.cpp
blob: 224caf19d2ce79bf78ae742ac50dae473be4b01c (plain)
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
#include "conditionfiletime.h"
#include "target.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include <bu/sio.h>
using namespace Bu;

ConditionFileTime::ConditionFileTime()
{
}

ConditionFileTime::~ConditionFileTime()
{
}

bool ConditionFileTime::shouldExec( class Runner &r, Target &rTarget )
{
	for( StrList::const_iterator j = rTarget.getOutputList().begin(); j; j++ )
	{
		if( access( (*j).getStr(), F_OK ) )
		{
			//sio << "-- Target processed because '" << *j << "' doesn't exist."
			//	<< sio.nl;
			// Output doesn't exist
			return true;
		}
	}

	time_t tOut = 0;
	struct stat s;
	for( StrList::const_iterator j = rTarget.getOutputList().begin();
		 j; j++ )
	{
		stat( (*j).getStr(), &s );
		if( tOut == 0 || tOut > s.st_mtime )
		{
			tOut = s.st_mtime;
		}
	}
	for( StrList::const_iterator j = rTarget.getInputList().begin();
		 j; j++ )
	{
		stat( (*j).getStr(), &s );
		if( tOut < s.st_mtime )
		{
			//sio << "-- Target processed because '" << *j
			//	<< "' is newer than output." << sio.nl;
			return true;
		}
	}
	rTarget.buildRequires( r );
	for( StrList::const_iterator j = rTarget.getRequiresList().begin();
		 j; j++ )
	{
		stat( (*j).getStr(), &s );
		if( tOut < s.st_mtime )
		{
			//sio << "-- Target processed because '" << *j
			//	<< "' is newer than output." << sio.nl;
			return true;
		}
	}
	return false; 
}

Condition *ConditionFileTime::clone()
{
	return new ConditionFileTime();
}