Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc5ad25

Browse files
authored
Toolchain cleanup (#198)
1 parentf8f6427 commitcc5ad25

File tree

34 files changed

+216
-200
lines changed

34 files changed

+216
-200
lines changed

‎buildcc/lib/args/include/args/args.h‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,32 @@ struct ArgToolchainState {
4848
structArgToolchain {
4949
ArgToolchain(){};
5050
ArgToolchain(ToolchainId initial_id,const std::string &initial_name,
51-
const std::string &initial_asm_compiler,
51+
const ToolchainBinaries &initial_binaries)
52+
: id(initial_id), name(initial_name), binaries(initial_binaries) {}
53+
ArgToolchain(ToolchainId initial_id,const std::string &initial_name,
54+
const std::string &initial_assembler,
5255
const std::string &initial_c_compiler,
5356
const std::string &initial_cpp_compiler,
5457
const std::string &initial_archiver,
5558
const std::string &initial_linker)
56-
: id(initial_id), name(initial_name), asm_compiler(initial_asm_compiler),
57-
c_compiler(initial_c_compiler), cpp_compiler(initial_cpp_compiler),
58-
archiver(initial_archiver), linker(initial_linker) {}
59+
: ArgToolchain(initial_id, initial_name,
60+
ToolchainBinaries(initial_assembler, initial_c_compiler,
61+
initial_cpp_compiler, initial_archiver,
62+
initial_linker)) {}
5963

6064
/**
6165
* @brief Construct a BaseToolchain from the arguments supplied through the
6266
* command line information
6367
*/
68+
// TODO, Update this for lock and ToolchainConfig
6469
BaseToolchainConstructToolchain()const {
65-
BaseToolchaintoolchain(id, name, asm_compiler, c_compiler, cpp_compiler,
66-
archiver, linker);
67-
return toolchain;
70+
returnBaseToolchain(id, name, binaries);
6871
}
6972

7073
ArgToolchainState state;
7174
ToolchainId id{ToolchainId::Undefined};
7275
std::string name{""};
73-
std::string asm_compiler{""};
74-
std::string c_compiler{""};
75-
std::string cpp_compiler{""};
76-
std::string archiver{""};
77-
std::string linker{""};
76+
ToolchainBinaries binaries;
7877
};
7978

8079
// NOTE, Incomplete without pch_compile_command

‎buildcc/lib/args/src/args.cpp‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const std::unordered_map<const char *, buildcc::env::LogLevel> kLogLevelMap{
7575
{"critical", buildcc::env::LogLevel::Critical},
7676
};
7777

78-
const std::unordered_map<constchar *, buildcc::Toolchain::Id>kToolchainIdMap{
78+
const std::unordered_map<constchar *, buildcc::ToolchainId>kToolchainIdMap{
7979
{"gcc", buildcc::ToolchainId::Gcc},
8080
{"msvc", buildcc::ToolchainId::Msvc},
8181
{"mingw", buildcc::ToolchainId::MinGW},
@@ -99,16 +99,16 @@ void Args::AddToolchain(const std::string &name, const std::string &description,
9999
->transform(CLI::CheckedTransformer(kToolchainIdMap, CLI::ignore_case))
100100
->default_val(initial.id);
101101
t_user->add_option(kToolchainNameParam, out.name)->default_val(initial.name);
102-
t_user->add_option(kToolchainAsmCompilerParam, out.asm_compiler)
103-
->default_val(initial.asm_compiler);
104-
t_user->add_option(kToolchainCCompilerParam, out.c_compiler)
105-
->default_val(initial.c_compiler);
106-
t_user->add_option(kToolchainCppCompilerParam, out.cpp_compiler)
107-
->default_val(initial.cpp_compiler);
108-
t_user->add_option(kToolchainArchiverParam, out.archiver)
109-
->default_val(initial.archiver);
110-
t_user->add_option(kToolchainLinkerParam, out.linker)
111-
->default_val(initial.linker);
102+
t_user->add_option(kToolchainAsmCompilerParam, out.binaries.assembler)
103+
->default_val(initial.binaries.assembler);
104+
t_user->add_option(kToolchainCCompilerParam, out.binaries.c_compiler)
105+
->default_val(initial.binaries.c_compiler);
106+
t_user->add_option(kToolchainCppCompilerParam, out.binaries.cpp_compiler)
107+
->default_val(initial.binaries.cpp_compiler);
108+
t_user->add_option(kToolchainArchiverParam, out.binaries.archiver)
109+
->default_val(initial.binaries.archiver);
110+
t_user->add_option(kToolchainLinkerParam, out.binaries.linker)
111+
->default_val(initial.binaries.linker);
112112
}
113113

114114
voidArgs::AddTarget(const std::string &name,const std::string &description,

‎buildcc/lib/args/test/test_args.cpp‎

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ TEST(ArgsTestGroup, Args_CustomToolchain) {
6666
// Toolchain
6767
CHECK_TRUE(gcc_toolchain.state.build);
6868
CHECK_FALSE(gcc_toolchain.state.test);
69-
CHECK(gcc_toolchain.id == buildcc::Toolchain::Id::Gcc);
69+
CHECK(gcc_toolchain.id == buildcc::ToolchainId::Gcc);
7070
STRCMP_EQUAL(gcc_toolchain.name.c_str(),"gcc");
71-
STRCMP_EQUAL(gcc_toolchain.asm_compiler.c_str(),"as");
72-
STRCMP_EQUAL(gcc_toolchain.c_compiler.c_str(),"gcc");
73-
STRCMP_EQUAL(gcc_toolchain.cpp_compiler.c_str(),"g++");
74-
STRCMP_EQUAL(gcc_toolchain.archiver.c_str(),"ar");
75-
STRCMP_EQUAL(gcc_toolchain.linker.c_str(),"ld");
71+
STRCMP_EQUAL(gcc_toolchain.binaries.assembler.c_str(),"as");
72+
STRCMP_EQUAL(gcc_toolchain.binaries.c_compiler.c_str(),"gcc");
73+
STRCMP_EQUAL(gcc_toolchain.binaries.cpp_compiler.c_str(),"g++");
74+
STRCMP_EQUAL(gcc_toolchain.binaries.archiver.c_str(),"ar");
75+
STRCMP_EQUAL(gcc_toolchain.binaries.linker.c_str(),"ld");
7676
}
7777

7878
TEST(ArgsTestGroup, Args_MultipleCustomToolchain) {
@@ -104,24 +104,24 @@ TEST(ArgsTestGroup, Args_MultipleCustomToolchain) {
104104
// GCC
105105
CHECK_TRUE(gcc_toolchain.state.build);
106106
CHECK_FALSE(gcc_toolchain.state.test);
107-
CHECK(gcc_toolchain.id == buildcc::Toolchain::Id::Gcc);
107+
CHECK(gcc_toolchain.id == buildcc::ToolchainId::Gcc);
108108
STRCMP_EQUAL(gcc_toolchain.name.c_str(),"gcc");
109-
STRCMP_EQUAL(gcc_toolchain.asm_compiler.c_str(),"as");
110-
STRCMP_EQUAL(gcc_toolchain.c_compiler.c_str(),"gcc");
111-
STRCMP_EQUAL(gcc_toolchain.cpp_compiler.c_str(),"g++");
112-
STRCMP_EQUAL(gcc_toolchain.archiver.c_str(),"ar");
113-
STRCMP_EQUAL(gcc_toolchain.linker.c_str(),"ld");
109+
STRCMP_EQUAL(gcc_toolchain.binaries.assembler.c_str(),"as");
110+
STRCMP_EQUAL(gcc_toolchain.binaries.c_compiler.c_str(),"gcc");
111+
STRCMP_EQUAL(gcc_toolchain.binaries.cpp_compiler.c_str(),"g++");
112+
STRCMP_EQUAL(gcc_toolchain.binaries.archiver.c_str(),"ar");
113+
STRCMP_EQUAL(gcc_toolchain.binaries.linker.c_str(),"ld");
114114

115115
// MSVC
116116
CHECK_TRUE(msvc_toolchain.state.build);
117117
CHECK_TRUE(msvc_toolchain.state.test);
118-
CHECK(msvc_toolchain.id == buildcc::Toolchain::Id::Msvc);
118+
CHECK(msvc_toolchain.id == buildcc::ToolchainId::Msvc);
119119
STRCMP_EQUAL(msvc_toolchain.name.c_str(),"msvc");
120-
STRCMP_EQUAL(msvc_toolchain.asm_compiler.c_str(),"cl");
121-
STRCMP_EQUAL(msvc_toolchain.c_compiler.c_str(),"cl");
122-
STRCMP_EQUAL(msvc_toolchain.cpp_compiler.c_str(),"cl");
123-
STRCMP_EQUAL(msvc_toolchain.archiver.c_str(),"lib");
124-
STRCMP_EQUAL(msvc_toolchain.linker.c_str(),"link");
120+
STRCMP_EQUAL(msvc_toolchain.binaries.assembler.c_str(),"cl");
121+
STRCMP_EQUAL(msvc_toolchain.binaries.c_compiler.c_str(),"cl");
122+
STRCMP_EQUAL(msvc_toolchain.binaries.cpp_compiler.c_str(),"cl");
123+
STRCMP_EQUAL(msvc_toolchain.binaries.archiver.c_str(),"lib");
124+
STRCMP_EQUAL(msvc_toolchain.binaries.linker.c_str(),"link");
125125
}
126126

127127
TEST(ArgsTestGroup, Args_DuplicateCustomToolchain) {
@@ -165,13 +165,13 @@ TEST(ArgsTestGroup, Args_CustomTarget) {
165165
// Toolchain
166166
CHECK_TRUE(gcc_toolchain.state.build);
167167
CHECK_FALSE(gcc_toolchain.state.test);
168-
CHECK(gcc_toolchain.id == buildcc::Toolchain::Id::Gcc);
168+
CHECK(gcc_toolchain.id == buildcc::ToolchainId::Gcc);
169169
STRCMP_EQUAL(gcc_toolchain.name.c_str(),"gcc");
170-
STRCMP_EQUAL(gcc_toolchain.asm_compiler.c_str(),"as");
171-
STRCMP_EQUAL(gcc_toolchain.c_compiler.c_str(),"gcc");
172-
STRCMP_EQUAL(gcc_toolchain.cpp_compiler.c_str(),"g++");
173-
STRCMP_EQUAL(gcc_toolchain.archiver.c_str(),"ar");
174-
STRCMP_EQUAL(gcc_toolchain.linker.c_str(),"ld");
170+
STRCMP_EQUAL(gcc_toolchain.binaries.assembler.c_str(),"as");
171+
STRCMP_EQUAL(gcc_toolchain.binaries.c_compiler.c_str(),"gcc");
172+
STRCMP_EQUAL(gcc_toolchain.binaries.cpp_compiler.c_str(),"g++");
173+
STRCMP_EQUAL(gcc_toolchain.binaries.archiver.c_str(),"ar");
174+
STRCMP_EQUAL(gcc_toolchain.binaries.linker.c_str(),"ld");
175175

176176
// Target
177177
STRCMP_EQUAL(gcc_target.compile_command.c_str(),
@@ -219,13 +219,13 @@ TEST(ArgsTestGroup, Args_MultipleCustomTarget) {
219219
// Toolchain
220220
CHECK_TRUE(gcc_toolchain.state.build);
221221
CHECK_FALSE(gcc_toolchain.state.test);
222-
CHECK(gcc_toolchain.id == buildcc::Toolchain::Id::Gcc);
222+
CHECK(gcc_toolchain.id == buildcc::ToolchainId::Gcc);
223223
STRCMP_EQUAL(gcc_toolchain.name.c_str(),"gcc");
224-
STRCMP_EQUAL(gcc_toolchain.asm_compiler.c_str(),"as");
225-
STRCMP_EQUAL(gcc_toolchain.c_compiler.c_str(),"gcc");
226-
STRCMP_EQUAL(gcc_toolchain.cpp_compiler.c_str(),"g++");
227-
STRCMP_EQUAL(gcc_toolchain.archiver.c_str(),"ar");
228-
STRCMP_EQUAL(gcc_toolchain.linker.c_str(),"ld");
224+
STRCMP_EQUAL(gcc_toolchain.binaries.assembler.c_str(),"as");
225+
STRCMP_EQUAL(gcc_toolchain.binaries.c_compiler.c_str(),"gcc");
226+
STRCMP_EQUAL(gcc_toolchain.binaries.cpp_compiler.c_str(),"g++");
227+
STRCMP_EQUAL(gcc_toolchain.binaries.archiver.c_str(),"ar");
228+
STRCMP_EQUAL(gcc_toolchain.binaries.linker.c_str(),"ld");
229229

230230
// Target
231231
STRCMP_EQUAL(gcc_target.compile_command.c_str(),
@@ -240,13 +240,13 @@ TEST(ArgsTestGroup, Args_MultipleCustomTarget) {
240240
// Toolchain
241241
CHECK_TRUE(msvc_toolchain.state.build);
242242
CHECK_TRUE(msvc_toolchain.state.test);
243-
CHECK(msvc_toolchain.id == buildcc::Toolchain::Id::Msvc);
243+
CHECK(msvc_toolchain.id == buildcc::ToolchainId::Msvc);
244244
STRCMP_EQUAL(msvc_toolchain.name.c_str(),"msvc");
245-
STRCMP_EQUAL(msvc_toolchain.asm_compiler.c_str(),"cl");
246-
STRCMP_EQUAL(msvc_toolchain.c_compiler.c_str(),"cl");
247-
STRCMP_EQUAL(msvc_toolchain.cpp_compiler.c_str(),"cl");
248-
STRCMP_EQUAL(msvc_toolchain.archiver.c_str(),"lib");
249-
STRCMP_EQUAL(msvc_toolchain.linker.c_str(),"link");
245+
STRCMP_EQUAL(msvc_toolchain.binaries.assembler.c_str(),"cl");
246+
STRCMP_EQUAL(msvc_toolchain.binaries.c_compiler.c_str(),"cl");
247+
STRCMP_EQUAL(msvc_toolchain.binaries.cpp_compiler.c_str(),"cl");
248+
STRCMP_EQUAL(msvc_toolchain.binaries.archiver.c_str(),"lib");
249+
STRCMP_EQUAL(msvc_toolchain.binaries.linker.c_str(),"link");
250250

251251
// Target
252252
STRCMP_EQUAL(msvc_target.compile_command.c_str(),

‎buildcc/lib/args/test/test_register.cpp‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ TEST(RegisterTestGroup, Register_Build) {
100100

101101
// Make dummy toolchain and target
102102
buildcc::env::init(fs::current_path(),fs::current_path());
103-
buildcc::Toolchaintoolchain(buildcc::Toolchain::Id::Gcc,"","","","","",
103+
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
104104
"");
105105
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
106106
toolchain,"");
@@ -148,7 +148,7 @@ TEST(RegisterTestGroup, Register_NoBuildAndDep) {
148148

149149
// Make dummy toolchain and target
150150
buildcc::env::init(fs::current_path(),fs::current_path());
151-
buildcc::Toolchaintoolchain(buildcc::Toolchain::Id::Gcc,"","","","","",
151+
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
152152
"");
153153
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
154154
toolchain,"");
@@ -232,7 +232,7 @@ TEST(RegisterTestGroup, Register_BuildAndDep) {
232232

233233
// Make dummy toolchain and target
234234
buildcc::env::init(fs::current_path(),fs::current_path());
235-
buildcc::Toolchaintoolchain(buildcc::Toolchain::Id::Gcc,"","","","","",
235+
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
236236
"");
237237
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
238238
toolchain,"");
@@ -327,7 +327,7 @@ TEST(RegisterTestGroup, Register_DepDuplicate) {
327327

328328
// Make dummy toolchain and target
329329
buildcc::env::init(fs::current_path(),fs::current_path());
330-
buildcc::Toolchaintoolchain(buildcc::Toolchain::Id::Gcc,"","","","","",
330+
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
331331
"");
332332
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
333333
toolchain,"");
@@ -403,7 +403,7 @@ TEST(RegisterTestGroup, Register_DepCyclic) {
403403

404404
// Make dummy toolchain and target
405405
buildcc::env::init(fs::current_path(),fs::current_path());
406-
buildcc::Toolchaintoolchain(buildcc::Toolchain::Id::Gcc,"","","","","",
406+
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
407407
"");
408408
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
409409
toolchain,"");
@@ -479,7 +479,7 @@ TEST(RegisterTestGroup, Register_Test) {
479479

480480
// Make dummy toolchain and target
481481
buildcc::env::init(fs::current_path(),fs::current_path());
482-
buildcc::Toolchaintoolchain(buildcc::Toolchain::Id::Gcc,"","","","","",
482+
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
483483
"");
484484
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
485485
toolchain,"");
@@ -564,7 +564,7 @@ TEST(RegisterTestGroup, Register_TestWithOutput) {
564564

565565
// Make dummy toolchain and target
566566
buildcc::env::init(fs::current_path(),fs::current_path());
567-
buildcc::Toolchaintoolchain(buildcc::Toolchain::Id::Gcc,"","","","","",
567+
buildcc::Toolchaintoolchain(buildcc::ToolchainId::Gcc,"","","","","",
568568
"");
569569
buildcc::BaseTargettarget("dummyT", buildcc::TargetType::Executable,
570570
toolchain,"");

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

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

2525
#include"toolchain/toolchain.h"
2626

27+
#include"target/common/target_config.h"
2728
#include"target/common/target_state.h"
2829

2930
#include"taskflow/taskflow.hpp"
@@ -39,6 +40,9 @@ template <typename T> class TargetGetter {
3940
boolIsBuilt()const;
4041
boolIsLocked()const;
4142

43+
// Target Config
44+
const TargetConfig &GetConfig()const;
45+
4246
const std::string &GetName()const;
4347
const Toolchain &GetToolchain()const;
4448
TargetTypeGetType()const;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include"schema/path.h"
2121

22-
#include"target/common/target_config.h"
2322
#include"target/common/target_state.h"
2423

2524
namespacebuildcc::internal {
@@ -34,9 +33,6 @@ template <typename T> class TargetInfoGetter {
3433
const fs::path &GetTargetRootDir()const;
3534
const fs::path &GetTargetBuildDir()const;
3635

37-
// Target Config
38-
const TargetConfig &GetConfig()const;
39-
4036
// Target Storer
4137
const fs_unordered_set &GetSourceFiles()const;
4238
const fs_unordered_set &GetHeaderFiles()const;

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ class Target : public internal::BuilderInterface,
6969
explicitTarget(const std::string &name, TargetType type,
7070
const Toolchain &toolchain,const TargetEnv &env,
7171
const TargetConfig &config = TargetConfig())
72-
: TargetInfo(
73-
toolchain,
74-
TargetEnv(env.GetTargetRootDir(),
75-
env.GetTargetBuildDir() / toolchain.GetName() / name),
76-
config),
77-
name_(name), type_(type),
72+
: TargetInfo(toolchain, TargetEnv(env.GetTargetRootDir(),
73+
env.GetTargetBuildDir() /
74+
toolchain.GetName() / name)),
75+
name_(name), type_(type), config_(config),
7876
serialization_(env_.GetTargetBuildDir() / fmt::format("{}.bin", name)),
7977
compile_pch_(*this), compile_object_(*this), link_target_(*this) {
8078
Initialize();
@@ -139,6 +137,7 @@ class Target : public internal::BuilderInterface,
139137
private:
140138
std::string name_;
141139
TargetType type_;
140+
TargetConfig config_;
142141
internal::TargetSerialization serialization_;
143142
internal::CompilePch compile_pch_;
144143
internal::CompileObject compile_object_;

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
6161
public internal::SyncApi<TargetInfo>,
6262
public internal::TargetInfoGetter<TargetInfo> {
6363
public:
64-
TargetInfo(const BaseToolchain &toolchain,const TargetEnv &env,
65-
const TargetConfig &config = TargetConfig())
66-
: toolchain_(toolchain), env_(env), config_(config) {
64+
TargetInfo(const BaseToolchain &toolchain,const TargetEnv &env)
65+
: toolchain_(toolchain), env_(env) {
6766
Initialize();
6867
}
6968

@@ -85,11 +84,10 @@ class TargetInfo : public internal::SourceApi<TargetInfo>,
8584
protected:
8685
const BaseToolchain &toolchain_;
8786
TargetEnv env_;
88-
TargetConfig config_;
8987

9088
//
91-
UserTargetSchema user_;
9289
FunctionLock lock_;
90+
UserTargetSchema user_;
9391

9492
private:
9593
voidInitialize();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ template <typename T> bool TargetGetter<T>::IsBuilt() const {
3333
return t.state_.IsBuilt();
3434
}
3535

36+
// Target Config
37+
template<typename T>const TargetConfig &TargetGetter<T>::GetConfig()const {
38+
const T &t =static_cast<const T &>(*this);
39+
40+
return t.config_;
41+
}
42+
3643
template<typename T>bool TargetGetter<T>::IsLocked()const {
3744
const T &t =static_cast<const T &>(*this);
3845

‎buildcc/lib/target/src/api/target_info_getter.cpp‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ const fs::path &TargetInfoGetter<T>::GetTargetBuildDir() const {
3535
return t.env_.GetTargetBuildDir();
3636
}
3737

38-
// Target Config
39-
template<typename T>
40-
const TargetConfig &TargetInfoGetter<T>::GetConfig()const {
41-
const T &t =static_cast<const T &>(*this);
42-
43-
return t.config_;
44-
}
45-
4638
// Target Storer
4739
template<typename T>
4840
const fs_unordered_set &TargetInfoGetter<T>::GetSourceFiles()const {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp