30
30
// Interface
31
31
#include " target/builder_interface.h"
32
32
33
+ // API
34
+ #include " target/target_info.h"
35
+
33
36
// Common
34
- #include " target/common/target_config.h"
35
- #include " target/common/target_env.h"
36
- #include " target/common/target_state.h"
37
37
#include " target/common/target_type.h"
38
38
39
- // API
40
- #include " target/api/copy_api.h"
41
- #include " target/api/deps_api.h"
42
- #include " target/api/flag_api.h"
43
- #include " target/api/include_api.h"
44
- #include " target/api/lib_api.h"
45
- #include " target/api/pch_api.h"
46
- #include " target/api/source_api.h"
47
-
48
39
// Friend
49
40
#include " target/friend/compile_object.h"
50
41
#include " target/friend/compile_pch.h"
@@ -70,52 +61,31 @@ namespace buildcc::base {
70
61
// of the inheritance pattern
71
62
// NOTE, base::Target is meant to be a blank slate which can be customized by
72
63
// the specialized target-toolchain classes
73
- class Target : public BuilderInterface ,
74
- public CopyApi<Target>,
75
- public SourceApi<Target>,
76
- public IncludeApi<Target>,
77
- public LibApi<Target>,
78
- public PchApi<Target>,
79
- public FlagApi<Target>,
80
- public DepsApi<Target> {
64
+ class Target : public BuilderInterface , public TargetInfo {
81
65
82
66
public:
83
67
explicit Target (const std::string &name, TargetType type,
84
68
const Toolchain &toolchain, const TargetEnv &env,
85
- const TargetConfig &config = {})
86
- : name_(name), type_(type), toolchain_(toolchain), config_(config),
87
- env_(env.GetTargetRootDir(),
88
- env.GetTargetBuildDir() / toolchain.GetName() / name),
69
+ const TargetConfig &config = TargetConfig())
70
+ : TargetInfo(
71
+ TargetEnv (env.GetTargetRootDir(),
72
+ env.GetTargetBuildDir() / toolchain.GetName() / name),
73
+ config),
74
+ name_(name), type_(type), toolchain_(toolchain),
89
75
loader_(name, env_.GetTargetBuildDir()), compile_pch_(*this ),
90
76
compile_object_(*this ), link_target_(*this ) {
91
77
Initialize ();
92
78
}
93
79
virtual ~Target () {}
94
-
95
80
Target (const Target &target) = delete;
96
81
97
82
// Builders
98
83
void Build () override ;
99
84
100
- // TODO, Add more setters
101
-
102
- //
103
- std::optional<std::string> SelectCompileFlags (TargetFileExt ext) const ;
104
- std::optional<std::string> SelectCompiler (TargetFileExt ext) const ;
105
-
106
85
// Getters (GENERIC)
107
86
108
- // Target state
109
-
110
- // Set during first build or rebuild
111
- // lock == true after Build is called
112
- const TargetState &GetState () const { return state_; }
113
- bool GetBuildState () const { return state_.build ; }
114
- bool GetLockState () const { return state_.lock ; }
115
-
116
87
// NOTE, We are constructing the path
117
88
fs::path GetBinaryPath () const { return loader_.GetBinaryPath (); }
118
-
119
89
const fs::path &GetTargetPath () const { return link_target_.GetOutput (); }
120
90
const fs::path &GetPchHeaderPath () const {
121
91
return compile_pch_.GetHeaderPath ();
@@ -130,62 +100,8 @@ class Target : public BuilderInterface,
130
100
const std::string &GetName () const { return name_; }
131
101
const Toolchain &GetToolchain () const { return toolchain_; }
132
102
TargetType GetType () const { return type_; }
133
- const fs::path &GetTargetRootDir () const { return env_.GetTargetRootDir (); }
134
- const fs::path &GetTargetBuildDir () const { return env_.GetTargetBuildDir (); }
135
- const TargetConfig &GetConfig () const { return config_; }
136
103
137
104
//
138
- const internal::fs_unordered_set &GetCurrentSourceFiles () const {
139
- return storer_.current_source_files .user ;
140
- }
141
- const internal::fs_unordered_set &GetCurrentHeaderFiles () const {
142
- return storer_.current_header_files .user ;
143
- }
144
- const internal::fs_unordered_set &GetCurrentPchFiles () const {
145
- return storer_.current_pch_files .user ;
146
- }
147
- const internal::fs_unordered_set &GetTargetLibDeps () const {
148
- return storer_.current_lib_deps .user ;
149
- }
150
- const std::unordered_set<std::string> &GetCurrentExternalLibDeps () const {
151
- return storer_.current_external_lib_deps ;
152
- }
153
- const internal::fs_unordered_set &GetCurrentIncludeDirs () const {
154
- return storer_.current_include_dirs ;
155
- }
156
- const internal::fs_unordered_set &GetCurrentLibDirs () const {
157
- return storer_.current_lib_dirs ;
158
- }
159
- const std::unordered_set<std::string> &GetCurrentPreprocessorFlags () const {
160
- return storer_.current_preprocessor_flags ;
161
- }
162
- const std::unordered_set<std::string> &GetCurrentCommonCompileFlags () const {
163
- return storer_.current_common_compile_flags ;
164
- }
165
- const std::unordered_set<std::string> &GetCurrentPchCompileFlags () const {
166
- return storer_.current_pch_compile_flags ;
167
- }
168
- const std::unordered_set<std::string> &GetCurrentPchObjectFlags () const {
169
- return storer_.current_pch_object_flags ;
170
- }
171
- const std::unordered_set<std::string> &GetCurrentAsmCompileFlags () const {
172
- return storer_.current_asm_compile_flags ;
173
- }
174
- const std::unordered_set<std::string> &GetCurrentCCompileFlags () const {
175
- return storer_.current_c_compile_flags ;
176
- }
177
- const std::unordered_set<std::string> &GetCurrentCppCompileFlags () const {
178
- return storer_.current_cpp_compile_flags ;
179
- }
180
- const std::unordered_set<std::string> &GetCurrentLinkFlags () const {
181
- return storer_.current_link_flags ;
182
- }
183
- const internal::fs_unordered_set &GetCurrentCompileDependencies () const {
184
- return storer_.current_compile_dependencies .user ;
185
- }
186
- const internal::fs_unordered_set &GetCurrentLinkDependencies () const {
187
- return storer_.current_link_dependencies .user ;
188
- }
189
105
190
106
// Getters (state_.ExpectsLock)
191
107
@@ -221,6 +137,10 @@ class Target : public BuilderInterface,
221
137
private:
222
138
void Initialize ();
223
139
140
+ //
141
+ std::optional<std::string> SelectCompileFlags (TargetFileExt ext) const ;
142
+ std::optional<std::string> SelectCompiler (TargetFileExt ext) const ;
143
+
224
144
// Recompilation checks
225
145
void RecheckPaths (const internal::path_unordered_set &previous_path,
226
146
const internal::path_unordered_set ¤t_path);
@@ -235,7 +155,10 @@ class Target : public BuilderInterface,
235
155
// Fbs
236
156
bool Store () override ;
237
157
238
- // Callbacks
158
+ // Tasks
159
+ void TaskDeps ();
160
+
161
+ // Callbacks for unit tests
239
162
void SourceRemoved ();
240
163
void SourceAdded ();
241
164
void SourceUpdated ();
@@ -247,25 +170,18 @@ class Target : public BuilderInterface,
247
170
void FlagChanged ();
248
171
void ExternalLibChanged ();
249
172
250
- void TaskDeps ();
251
-
252
173
private:
253
- // Constructor defined
254
174
std::string name_;
255
175
TargetType type_;
256
176
const Toolchain &toolchain_;
257
- TargetConfig config_;
258
- TargetEnv env_;
259
177
internal::TargetLoader loader_;
260
178
261
- // Friend
179
+ // Friend classes
262
180
CompilePch compile_pch_;
263
181
CompileObject compile_object_;
264
182
LinkTarget link_target_;
265
183
266
- // Used for serialization
267
- internal::TargetStorer storer_;
268
- TargetState state_;
184
+ //
269
185
Command command_;
270
186
tf::Taskflow tf_;
271
187
};
0 commit comments