Skip to content

Commit 3e7382b

Browse files
committed
Used AddDefaultArgument to optimize construction
1 parent 0fdcfc7 commit 3e7382b

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

buildcc/lib/target/include/target.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,9 @@ class Target {
261261
std::unordered_set<std::string> current_cpp_compile_flags_;
262262
std::unordered_set<std::string> current_link_flags_;
263263

264-
// TODO, Make appending to this more efficient
265264
// TODO, Might not need to be persistent
266-
// TODO, aggregates might not need to exist, check `std::insert` APIs over
267-
// vector and unordered_set
268-
std::string aggregated_include_dirs_;
269-
std::string aggregated_lib_dirs_;
270-
// NOTE, This contains current_external_lib_deps_ + current_lib_deps_
271-
std::string aggregated_lib_deps_;
272-
273-
std::string aggregated_preprocessor_flags_;
274265
std::string aggregated_c_compile_flags_;
275266
std::string aggregated_cpp_compile_flags_;
276-
std::string aggregated_link_flags_;
277267

278268
// TODO, Add more internal variables
279269

buildcc/lib/target/src/target/build.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,42 @@ void Target::Build() {
3434
env::log_trace(name_, __FUNCTION__);
3535

3636
// TODO, Optimize these
37-
aggregated_preprocessor_flags_ =
38-
internal::aggregate(current_preprocessor_flags_);
3937
aggregated_c_compile_flags_ = internal::aggregate(current_c_compile_flags_);
4038
aggregated_cpp_compile_flags_ =
4139
internal::aggregate(current_cpp_compile_flags_);
42-
aggregated_link_flags_ = internal::aggregate(current_link_flags_);
4340

44-
aggregated_lib_deps_ =
41+
// TODO, Segregate these if required
42+
const std::string aggregated_lib_deps =
4543
fmt::format("{} {}", internal::aggregate(current_external_lib_deps_),
4644
internal::aggregate(current_lib_deps_));
4745

48-
aggregated_include_dirs_ = internal::aggregate_with_prefix(
46+
const std::string aggregated_preprocessor_flags =
47+
internal::aggregate(current_preprocessor_flags_);
48+
const std::string aggregated_link_flags =
49+
internal::aggregate(current_link_flags_);
50+
51+
const std::string aggregated_include_dirs = internal::aggregate_with_prefix(
4952
prefix_include_dir_, current_include_dirs_);
50-
aggregated_lib_dirs_ =
53+
const std::string aggregated_lib_dirs =
5154
internal::aggregate_with_prefix(prefix_lib_dir_, current_lib_dirs_);
5255

56+
command_.AddDefaultArguments({
57+
fmt::arg("lib_deps", aggregated_lib_deps),
58+
59+
fmt::arg("include_dirs", aggregated_include_dirs),
60+
fmt::arg("lib_dirs", aggregated_lib_dirs),
61+
62+
fmt::arg("preprocessor_flags", aggregated_preprocessor_flags),
63+
fmt::arg("link_flags", aggregated_link_flags),
64+
65+
// Toolchain executables here
66+
fmt::arg("asm_compiler", toolchain_.GetAsmCompiler()),
67+
fmt::arg("c_compiler", toolchain_.GetCCompiler()),
68+
fmt::arg("cpp_compiler", toolchain_.GetCppCompiler()),
69+
fmt::arg("archiver", toolchain_.GetArchiver()),
70+
fmt::arg("linker", toolchain_.GetLinker()),
71+
});
72+
5373
const bool is_loaded = loader_.Load();
5474
// TODO, Add more checks for build files physically present
5575
// NOTE, This can go into the recompile logic
@@ -123,16 +143,7 @@ void Target::LinkTarget() {
123143
const bool success = command_.ConstructAndExecute(
124144
Link(), {
125145
fmt::arg("output", output_target),
126-
fmt::arg("link_flags", aggregated_link_flags_),
127146
fmt::arg("compiled_sources", aggregated_compiled_sources),
128-
fmt::arg("lib_dirs", aggregated_lib_dirs_),
129-
fmt::arg("lib_deps", aggregated_lib_deps_),
130-
// Toolchain executables here
131-
fmt::arg("asm_compiler", toolchain_.GetAsmCompiler()),
132-
fmt::arg("c_compiler", toolchain_.GetCCompiler()),
133-
fmt::arg("cpp_compiler", toolchain_.GetCppCompiler()),
134-
fmt::arg("archiver", toolchain_.GetArchiver()),
135-
fmt::arg("linker", toolchain_.GetLinker()),
136147
});
137148
env::assert_fatal(success, fmt::format("Compilation failed for: {}", name_));
138149
}

buildcc/lib/target/src/target/source.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,12 @@ std::string Target::CompileCommand(const fs::path &current_source) const {
195195
: "";
196196

197197
return command_.Construct(
198-
CompileCommand(),
199-
{
200-
fmt::arg("compiler", compiler),
201-
fmt::arg("compile_flags", aggregated_compile_flags),
202-
fmt::arg("output", output),
203-
fmt::arg("input", input),
204-
205-
fmt::arg("preprocessor_flags", aggregated_preprocessor_flags_),
206-
fmt::arg("include_dirs", aggregated_include_dirs_),
207-
});
198+
CompileCommand(), {
199+
fmt::arg("compiler", compiler),
200+
fmt::arg("compile_flags", aggregated_compile_flags),
201+
fmt::arg("output", output),
202+
fmt::arg("input", input),
203+
});
208204
}
209205

210206
std::string_view Target::CompileCommand() const {

0 commit comments

Comments
 (0)