summaryrefslogtreecommitdiff
path: root/task.h
blob: 7ea95fca7613b4140348f36f700ad10c071a0ca0 (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
// -*- c++ -*-
#pragma once

#include <vector>
#include <string>
#include <atomic>
#include <list>
#include <memory>

#include "libcppbuild.h"

enum class State
{
	Unknown,
	Ready,
	Running,
	Done,
	Error,
};

class Task
{
public:
	Task(const BuildConfiguration& config,
	     const std::vector<std::string>& depends = {});

	int registerDepTasks(const std::list<std::shared_ptr<Task>>& tasks);

	bool dirty();
	bool ready();
	int run();
	State state() const;
	virtual int clean() = 0 ;
	virtual std::vector<std::string> depends() const = 0;
	virtual std::string target() const = 0;

	virtual std::string toJSON() const { return {}; };

	const BuildConfiguration& buildConfig() const;

	TargetType targetType() const;
	Language language() const;

protected:
	std::atomic<State> task_state{State::Unknown};
	virtual int runInner() { return 0; };
	virtual bool dirtyInner() { return false; }

	std::vector<std::string> dependsStr;
	std::list<std::shared_ptr<Task>> dependsTasks;
	const BuildConfiguration& config;
	TargetType target_type{TargetType::Auto};
	Language _language{Language::Auto};
};