Skip to content

Commit f8f6427

Browse files
authored
Toolchain flags api (#197)
1 parent 06bed39 commit f8f6427

38 files changed

+362
-160
lines changed

bootstrap/src/build_buildcc.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
6363
// TOOLCHAIN
6464
target.GlobSources("lib/toolchain/src/api");
6565
target.GlobSources("lib/toolchain/src/common");
66+
target.GlobSources("lib/toolchain/src/toolchain");
6667
target.AddIncludeDir("lib/toolchain/include");
6768
target.GlobHeaders("lib/toolchain/include/toolchain");
6869
target.GlobHeaders("lib/toolchain/include/toolchain/api");
@@ -72,6 +73,7 @@ void buildcc_cb(BaseTarget &target, const BaseGenerator &schema_gen,
7273
target.GlobSources("lib/target/src/common");
7374
target.GlobSources("lib/target/src/generator");
7475
target.GlobSources("lib/target/src/api");
76+
target.GlobSources("lib/target/src/target_info");
7577
target.GlobSources("lib/target/src/target");
7678
target.GlobSources("lib/target/src/target/friend");
7779

buildcc/lib/args/test/test_persistent_storage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ TEST_GROUP(PersistentStorageTestGroup)
1616
};
1717
// clang-format on
1818

19-
buildcc::BaseToolchain gcc(buildcc::ToolchainId::Gcc, "gcc", "as", "gcc", "g++",
20-
"ar", "ld");
19+
static buildcc::BaseToolchain gcc(buildcc::ToolchainId::Gcc, "gcc", "as", "gcc",
20+
"g++", "ar", "ld");
2121

2222
TEST(PersistentStorageTestGroup, BasicUsage) {
2323
buildcc::PersistentStorage persistent;

buildcc/lib/target/cmake/common_target_src.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ set(COMMON_TARGET_SRCS
2323
include/target/api/include_api.h
2424
include/target/api/lib_api.h
2525
include/target/api/pch_api.h
26-
include/target/api/flag_api.h
2726
include/target/api/deps_api.h
2827

2928
src/api/sync_api.cpp
@@ -38,6 +37,10 @@ set(COMMON_TARGET_SRCS
3837
src/generator/generator.cpp
3938
include/target/generator.h
4039

40+
# Target Info
41+
src/target_info/target_info.cpp
42+
include/target/target_info.h
43+
4144
# Target friend
4245
src/target/friend/compile_pch.cpp
4346
src/target/friend/compile_object.cpp
@@ -49,6 +52,5 @@ set(COMMON_TARGET_SRCS
4952
# Target
5053
src/target/target.cpp
5154
src/target/build.cpp
52-
include/target/target_info.h
5355
include/target/target.h
5456
)

buildcc/lib/target/include/target/api/deps_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace buildcc::internal {
2525

2626
// Requires
2727
// - TargetStorer
28-
// - TargetState
2928
// - TargetEnv
3029
template <typename T> class DepsApi {
3130
public:

buildcc/lib/target/include/target/api/include_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace buildcc::internal {
2525

2626
// Requires
2727
// - TargetStorer
28-
// - TargetState
2928
// - TargetConfig
3029
// - TargetEnv
3130
template <typename T> class IncludeApi {

buildcc/lib/target/include/target/api/lib_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace buildcc::internal {
3232

3333
// Requires
3434
// - TargetStorer
35-
// - TargetState
3635
// - TargetEnv
3736
// T::GetTargetPath
3837
template <typename T> class LibApi {

buildcc/lib/target/include/target/api/pch_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace buildcc::internal {
2525

2626
// Requires
2727
// - TargetStorer
28-
// - TargetState
2928
// - TargetConfig
3029
// - TargetEnv
3130
template <typename T> class PchApi {

buildcc/lib/target/include/target/api/source_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ namespace buildcc::internal {
2525

2626
// Requires
2727
// - TargetStorer
28-
// - TargetState
2928
// - TargetConfig
3029
// - TargetEnv
3130
template <typename T> class SourceApi {

buildcc/lib/target/include/target/api/sync_api.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ enum class SyncOption {
4343

4444
// Requires
4545
// - TargetStorer
46-
// - TargetState
4746
template <typename T> class SyncApi {
4847
public:
4948
/**

buildcc/lib/target/include/target/api/target_getter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include "toolchain/toolchain.h"
2626

27+
#include "target/common/target_state.h"
28+
2729
#include "taskflow/taskflow.hpp"
2830

2931
namespace fs = std::filesystem;
@@ -32,6 +34,11 @@ namespace buildcc::internal {
3234

3335
template <typename T> class TargetGetter {
3436
public:
37+
// Target State
38+
const TargetState &GetState() const;
39+
bool IsBuilt() const;
40+
bool IsLocked() const;
41+
3542
const std::string &GetName() const;
3643
const Toolchain &GetToolchain() const;
3744
TargetType GetType() const;

buildcc/lib/target/include/target/api/target_info_getter.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,10 @@ namespace buildcc::internal {
2626

2727
// Requires
2828
// - TargetStorer
29-
// - TargetState
3029
// - TargetEnv
3130
// - TargetConfig
3231
template <typename T> class TargetInfoGetter {
3332
public:
34-
// Target State
35-
const TargetState &GetState() const;
36-
bool IsBuilt() const;
37-
bool IsLocked() const;
38-
3933
// Target Env
4034
const fs::path &GetTargetRootDir() const;
4135
const fs::path &GetTargetBuildDir() const;
@@ -51,14 +45,7 @@ template <typename T> class TargetInfoGetter {
5145
const std::vector<std::string> &GetExternalLibDeps() const;
5246
const fs_unordered_set &GetIncludeDirs() const;
5347
const fs_unordered_set &GetLibDirs() const;
54-
const std::unordered_set<std::string> &GetPreprocessorFlags() const;
55-
const std::unordered_set<std::string> &GetCommonCompileFlags() const;
56-
const std::unordered_set<std::string> &GetPchCompileFlags() const;
57-
const std::unordered_set<std::string> &GetPchObjectFlags() const;
58-
const std::unordered_set<std::string> &GetAsmCompileFlags() const;
59-
const std::unordered_set<std::string> &GetCCompileFlags() const;
60-
const std::unordered_set<std::string> &GetCppCompileFlags() const;
61-
const std::unordered_set<std::string> &GetLinkFlags() const;
48+
6249
const fs_unordered_set &GetCompileDependencies() const;
6350
const fs_unordered_set &GetLinkDependencies() const;
6451
};

buildcc/lib/target/include/target/generator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
namespace buildcc {
4141

42+
// TODO, Make this private
4243
struct UserGeneratorSchema : public internal::GeneratorSchema {
4344
fs_unordered_set inputs;
4445
};

buildcc/lib/target/include/target/target.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,20 @@ class Target : public internal::BuilderInterface,
140140
std::string name_;
141141
TargetType type_;
142142
internal::TargetSerialization serialization_;
143-
144-
// Friend classes
145143
internal::CompilePch compile_pch_;
146144
internal::CompileObject compile_object_;
147145
internal::LinkTarget link_target_;
148146

147+
//
148+
TargetState state_;
149+
env::Command command_;
150+
tf::Taskflow tf_;
151+
149152
// Task states
150153
tf::Task target_start_task_;
151154
tf::Task target_end_task_;
152-
153155
std::mutex task_state_mutex_;
154156
env::TaskState task_state_{env::TaskState::SUCCESS};
155-
156-
//
157-
env::Command command_;
158-
tf::Taskflow tf_;
159157
};
160158

161159
typedef Target BaseTarget;

buildcc/lib/target/include/target/target_info.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121

2222
#include "toolchain/toolchain.h"
2323

24-
#include "target/common/function_lock.h"
2524
#include "target/common/target_config.h"
2625
#include "target/common/target_env.h"
27-
#include "target/common/target_state.h"
2826

2927
#include "target/api/deps_api.h"
30-
#include "target/api/flag_api.h"
3128
#include "target/api/include_api.h"
3229
#include "target/api/lib_api.h"
3330
#include "target/api/pch_api.h"
@@ -39,6 +36,7 @@
3936

4037
namespace buildcc {
4138

39+
// TODO, Make this private
4240
struct UserTargetSchema : public internal::TargetSchema {
4341
fs_unordered_set sources;
4442
fs_unordered_set headers;
@@ -65,7 +63,9 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
6563
public:
6664
TargetInfo(const BaseToolchain &toolchain, const TargetEnv &env,
6765
const TargetConfig &config = TargetConfig())
68-
: toolchain_(toolchain), env_(env), config_(config) {}
66+
: toolchain_(toolchain), env_(env), config_(config) {
67+
Initialize();
68+
}
6969

7070
private:
7171
// Inputs
@@ -87,10 +87,12 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
8787
TargetEnv env_;
8888
TargetConfig config_;
8989

90+
//
9091
UserTargetSchema user_;
91-
9292
FunctionLock lock_;
93-
TargetState state_;
93+
94+
private:
95+
void Initialize();
9496
};
9597

9698
typedef TargetInfo BaseTargetInfo;

buildcc/lib/target/src/api/flag_api.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "target/api/flag_api.h"
17+
#include "toolchain/api/flag_api.h"
1818

1919
#include "target/target_info.h"
2020

@@ -76,6 +76,50 @@ template <typename T> void FlagApi<T>::AddLinkFlag(const std::string &flag) {
7676
t.user_.link_flags.insert(flag);
7777
}
7878

79+
template <typename T>
80+
const std::unordered_set<std::string> &
81+
FlagApi<T>::GetPreprocessorFlags() const {
82+
const T &t = static_cast<const T &>(*this);
83+
return t.user_.preprocessor_flags;
84+
}
85+
template <typename T>
86+
const std::unordered_set<std::string> &
87+
FlagApi<T>::GetCommonCompileFlags() const {
88+
const T &t = static_cast<const T &>(*this);
89+
return t.user_.common_compile_flags;
90+
}
91+
template <typename T>
92+
const std::unordered_set<std::string> &FlagApi<T>::GetPchCompileFlags() const {
93+
const T &t = static_cast<const T &>(*this);
94+
return t.user_.pch_compile_flags;
95+
}
96+
template <typename T>
97+
const std::unordered_set<std::string> &FlagApi<T>::GetPchObjectFlags() const {
98+
const T &t = static_cast<const T &>(*this);
99+
return t.user_.pch_object_flags;
100+
}
101+
template <typename T>
102+
const std::unordered_set<std::string> &FlagApi<T>::GetAsmCompileFlags() const {
103+
const T &t = static_cast<const T &>(*this);
104+
return t.user_.asm_compile_flags;
105+
}
106+
template <typename T>
107+
const std::unordered_set<std::string> &FlagApi<T>::GetCCompileFlags() const {
108+
const T &t = static_cast<const T &>(*this);
109+
return t.user_.c_compile_flags;
110+
}
111+
template <typename T>
112+
const std::unordered_set<std::string> &FlagApi<T>::GetCppCompileFlags() const {
113+
const T &t = static_cast<const T &>(*this);
114+
return t.user_.cpp_compile_flags;
115+
}
116+
template <typename T>
117+
const std::unordered_set<std::string> &FlagApi<T>::GetLinkFlags() const {
118+
const T &t = static_cast<const T &>(*this);
119+
return t.user_.link_flags;
120+
}
121+
79122
template class FlagApi<TargetInfo>;
123+
template class FlagApi<Toolchain>;
80124

81125
} // namespace buildcc::internal

buildcc/lib/target/src/api/target_getter.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@
2020

2121
namespace buildcc::internal {
2222

23+
// Target State
24+
template <typename T> const TargetState &TargetGetter<T>::GetState() const {
25+
const T &t = static_cast<const T &>(*this);
26+
27+
return t.state_;
28+
}
29+
30+
template <typename T> bool TargetGetter<T>::IsBuilt() const {
31+
const T &t = static_cast<const T &>(*this);
32+
33+
return t.state_.IsBuilt();
34+
}
35+
36+
template <typename T> bool TargetGetter<T>::IsLocked() const {
37+
const T &t = static_cast<const T &>(*this);
38+
39+
return t.lock_.IsLocked();
40+
}
41+
2342
template <typename T> const fs::path &TargetGetter<T>::GetBinaryPath() const {
2443
const T &t = static_cast<const T &>(*this);
2544

0 commit comments

Comments
 (0)