aboutsummaryrefslogtreecommitdiff
path: root/src/target.h
blob: 2eda3bf4a9724f4d3cdefee36a8fefd4f690f0bd (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
96
97
98
99
100
101
102
/*
 * 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.
 */

#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::String &sOutput, bool bExplicit );
    virtual ~Target();

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

    void addRequires( const Bu::String &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::String &sOutput );
    const StrList &getOutputList() const;

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

    void setRule( const Bu::String &sRule );
    const Bu::String &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::String &sName ) const;
    const class Profile *getProfile( const Bu::String &sName ) const;

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

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

    void process( class Runner &r, const Bu::String &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::String sPrefix;
    Bu::String sRule;
    VarHash hVars;
    TargetList lDeps;
    ProfileHash hProfiles;
    Bu::String 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