aboutsummaryrefslogtreecommitdiff
path: root/src/conditionfiletime.cpp
blob: 9ffb46f3515c0bb62461e43bafa073d99a3998df (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright (C) 2007-2014 Xagasoft, All rights reserved.
 *
 * This file is part of the Xagasoft Build and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "conditionfiletime.h"
#include "target.h"

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

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

#include <bu/plugger.h>
PluginInterface3( pluginConditionFileTime, fileTime, ConditionFileTime,
        Condition, "Mike Buland", 0, 1 );

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
            rTarget.buildRequires( r );
            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;
            rTarget.buildRequires( r );
            return true;
        }
    }
    rTarget.gatherRequires( 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;
            rTarget.buildRequires( r );
            return true;
        }
    }
    return false; 
}

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