]> git.tdb.fi Git - builder.git/blob - source/lib/task.cpp
Report timings of the build
[builder.git] / source / lib / task.cpp
1 #include <msp/fs/dir.h>
2 #include <msp/fs/stat.h>
3 #include <msp/fs/utils.h>
4 #include <msp/time/utils.h>
5 #include "filetarget.h"
6 #include "task.h"
7
8 using namespace std;
9 using namespace Msp;
10
11 void Task::add_target(const FileTarget &t)
12 {
13         targets.push_back(&t);
14 }
15
16 void Task::set_unlink(bool u)
17 {
18         unlink = u;
19 }
20
21 void Task::prepare()
22 {
23         start_time = Time::now();
24
25         for(const FileTarget *t: targets)
26         {
27                 const FS::Path &f = t->get_path();
28                 if(FS::exists(f))
29                 {
30                         // If the file exists, the directory it's in must exist too
31                         FS::unlink(f);
32                 }
33                 else
34                 {
35                         FS::Path dir = FS::dirname(f);
36                         if(!FS::exists(dir))
37                                 FS::mkpath(dir, 0755);
38                 }
39         }
40 }
41
42 void Task::finished(bool success)
43 {
44         if(!duration && start_time)
45                 duration = Time::now()-start_time;
46         signal_finished.emit(success);
47 }