aboutsummaryrefslogtreecommitdiff
path: root/src/target.h
blob: 25af1f41018cf3fa1fc11967a61fd1e492e1f05d (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
88
89
90
91
92
93
94
95
#ifndef TARGET_H
#define TARGET_H

#include "types.h"
#include <bu/formatter.h>

class Target
{
	friend Bu::Formatter &operator<<( Bu::Formatter &f, const Target &t );
public:
	Target( bool bExplicit );
	Target( const Bu::FString &sOutput, bool bExplicit );
	virtual ~Target();

	void addInput( const Bu::FString &sInput );
	const StrList &getInputList() const;
	void resetInputList( const StrList &lInputs );

	void addRequires( const Bu::FString &sReq );
	void addRequires( const AstBranch *pBr );
	const StrList &getRequiresList() const;
	/**
	 * This function will get the cached requires if they exist, build them
	 * if they don't.  Use this is conditions, but use buildRequires to force
	 * a rebuild even if cached data exists.
	 */
	void gatherRequires( class Runner &r );
	void buildRequires( class Runner &r );

	void addOutput( const Bu::FString &sOutput );
	const StrList &getOutputList() const;

	void setPrefix( const Bu::FString &sPrefix );
	const Bu::FString &getPrefix() const;

	void setRule( const Bu::FString &sRule );
	const Bu::FString &getRule() const;
	bool hasRule() const;

	bool isExplicit() const;

	void addDep( Target *pDep );
	const TargetList &getDepList() const;

	void addProfile( const class AstBranch *pProfRoot );
	void addProfile( const class Profile *pSrc );
	bool hasProfile( const Bu::FString &sName ) const;
	const class Profile *getProfile( const Bu::FString &sName ) const;

	void setVars( const VarHash &hNewVars );
	const VarHash &getVars() const;

	void setDisplay( const Bu::FString &sNewDisplay );
	const Bu::FString &getDisplay() const;

	void process( class Runner &r, const Bu::FString &sProfile );

	void mergeUnder( const Target *pSrc );

	bool hasRun();

	void resetRun( bool bHasRun=true );
	void setDepCount();
	int getDepCount() const;

	void collapseDeps();

private:
	void mergeUnder( const VarHash &hVars );
	void merge( StrList &lOut, const StrList &lIn );

private:
	bool bExplicit;
	StrList lsInput;
	StrList lsRequires;
	StrList lsOutput;
	Bu::FString sPrefix;
	Bu::FString sRule;
	VarHash hVars;
	TargetList lDeps;
	ProfileHash hProfiles;
	Bu::FString sDisplay;
	bool bRun;
	AstBranchList lbRequires;
	int iDepCount;
};

Bu::Formatter &operator<<( Bu::Formatter &f, const Target &t );

namespace Bu
{
	template<> Bu::Formatter &operator<< <Target>( Bu::Formatter &f, const Target *t );
};

#endif