@@ -6,10 +6,10 @@ | |||
#include <dds/toolchain.hpp> | |||
#include <algorithm> | |||
#include <sstream> | |||
#include <iomanip> | |||
#include <iostream> | |||
#include <mutex> | |||
#include <sstream> | |||
#include <stdexcept> | |||
#include <thread> | |||
@@ -239,13 +239,11 @@ std::vector<fs::path> compile_sources(source_list sources, | |||
std::unique_lock lk{mut}; | |||
std::vector<std::thread> threads; | |||
int njobs = params.parallel_jobs; | |||
int njobs = params.parallel_jobs; | |||
if (njobs < 1) { | |||
njobs = std::thread::hardware_concurrency() + 2; | |||
} | |||
std::generate_n(std::back_inserter(threads), njobs, [&] { | |||
return std::thread(compile_one); | |||
}); | |||
std::generate_n(std::back_inserter(threads), njobs, [&] { return std::thread(compile_one); }); | |||
spdlog::info("Parallel compile with {} threads", threads.size()); | |||
lk.unlock(); | |||
for (auto& t : threads) { |
@@ -1,8 +1,8 @@ | |||
#ifndef DDS_BUILD_HPP_INCLUDED | |||
#define DDS_BUILD_HPP_INCLUDED | |||
#include <dds/util.hpp> | |||
#include <dds/manifest.hpp> | |||
#include <dds/util.hpp> | |||
#include <optional> | |||
@@ -13,10 +13,10 @@ struct build_params { | |||
fs::path out_root; | |||
fs::path toolchain_file; | |||
std::string export_name; | |||
bool do_export = false; | |||
bool build_tests = false; | |||
bool do_export = false; | |||
bool build_tests = false; | |||
bool enable_warnings = false; | |||
int parallel_jobs = 0; | |||
int parallel_jobs = 0; | |||
}; | |||
void build(const build_params&, const library_manifest& man); |
@@ -1,7 +1,7 @@ | |||
#include <dds/build.hpp> | |||
#include <dds/lm_parse.hpp> | |||
#include <dds/util.hpp> | |||
#include <dds/logging.hpp> | |||
#include <dds/util.hpp> | |||
#include <args.hxx> | |||
@@ -57,24 +57,24 @@ struct cli_build { | |||
"Enable compiler warnings", | |||
{"warnings", 'W'}}; | |||
args::ValueFlag<int> num_jobs{ cmd, | |||
"jobs", | |||
"Set the number of parallel jobs when compiling files", | |||
{ "jobs", 'j' }, | |||
0 }; | |||
args::ValueFlag<int> num_jobs{cmd, | |||
"jobs", | |||
"Set the number of parallel jobs when compiling files", | |||
{"jobs", 'j'}, | |||
0}; | |||
int run() { | |||
dds::build_params params; | |||
params.root = lib_dir.Get(); | |||
params.out_root = out_dir.Get(); | |||
params.toolchain_file = tc_filepath.Get(); | |||
params.export_name = export_name.Get(); | |||
params.do_export = export_.Get(); | |||
params.build_tests = build_tests.Get(); | |||
params.root = lib_dir.Get(); | |||
params.out_root = out_dir.Get(); | |||
params.toolchain_file = tc_filepath.Get(); | |||
params.export_name = export_name.Get(); | |||
params.do_export = export_.Get(); | |||
params.build_tests = build_tests.Get(); | |||
params.enable_warnings = enable_warnings.Get(); | |||
params.parallel_jobs = num_jobs.Get(); | |||
dds::library_manifest man; | |||
const auto man_filepath = params.root / "manifest.dds"; | |||
const auto man_filepath = params.root / "manifest.dds"; | |||
if (exists(man_filepath)) { | |||
man = dds::library_manifest::load_from_file(man_filepath); | |||
} |
@@ -2,8 +2,8 @@ | |||
#include <dds/util.hpp> | |||
#include <fstream> | |||
#include <cctype> | |||
#include <fstream> | |||
namespace fs = std::filesystem; | |||
@@ -5,10 +5,4 @@ | |||
#include <spdlog/sinks/stdout_color_sinks.h> | |||
#include <spdlog/spdlog.h> | |||
namespace dds { | |||
inline auto get_logger() { return spdlog::stdout_color_mt("console"); } | |||
} // namespace dds | |||
#endif // DDS_LOGGING_HPP_INCLUDED | |||
#endif // DDS_LOGGING_HPP_INCLUDED |
@@ -93,4 +93,4 @@ proc_result dds::run_proc(const std::vector<std::string>& command) { | |||
return res; | |||
} | |||
#endif // _WIN32 | |||
#endif // _WIN32 |
@@ -34,12 +34,12 @@ proc_result dds::run_proc(const std::vector<std::string>& cmd) { | |||
auto cmd_str = concat_args(cmd); | |||
::SECURITY_ATTRIBUTES security = {}; | |||
security.bInheritHandle = TRUE; | |||
security.nLength = sizeof security; | |||
security.lpSecurityDescriptor = nullptr; | |||
security.bInheritHandle = TRUE; | |||
security.nLength = sizeof security; | |||
security.lpSecurityDescriptor = nullptr; | |||
wil::unique_hfile reader; | |||
wil::unique_hfile writer; | |||
auto okay = ::CreatePipe(&reader, &writer, &security, 0); | |||
auto okay = ::CreatePipe(&reader, &writer, &security, 0); | |||
if (!okay) { | |||
throw_system_error("Failed to create a stdio pipe"); | |||
} | |||
@@ -51,8 +51,9 @@ proc_result dds::run_proc(const std::vector<std::string>& cmd) { | |||
::STARTUPINFOA startup_info = {}; | |||
::RtlSecureZeroMemory(&startup_info, sizeof startup_info); | |||
startup_info.hStdOutput = startup_info.hStdError = writer.get(); | |||
startup_info.dwFlags = STARTF_USESTDHANDLES; | |||
startup_info.cb = sizeof startup_info; | |||
startup_info.dwFlags = STARTF_USESTDHANDLES; | |||
startup_info.cb = sizeof startup_info; | |||
// DO IT! | |||
okay = ::CreateProcessA(nullptr, // cmd[0].data(), | |||
cmd_str.data(), | |||
nullptr, | |||
@@ -72,9 +73,9 @@ proc_result dds::run_proc(const std::vector<std::string>& cmd) { | |||
std::string output; | |||
while (true) { | |||
const int buffer_size = 256; | |||
char buffer[buffer_size]; | |||
DWORD nread = 0; | |||
okay = ::ReadFile(reader.get(), buffer, buffer_size, &nread, nullptr); | |||
char buffer[buffer_size]; | |||
DWORD nread = 0; | |||
okay = ::ReadFile(reader.get(), buffer, buffer_size, &nread, nullptr); | |||
if (!okay && ::GetLastError() != ERROR_BROKEN_PIPE) { | |||
throw_system_error("Failed while reading from the stdio pipe"); | |||
} | |||
@@ -87,14 +88,14 @@ proc_result dds::run_proc(const std::vector<std::string>& cmd) { | |||
::WaitForSingleObject(proc_info.hProcess, INFINITE); | |||
DWORD rc = 0; | |||
okay = ::GetExitCodeProcess(proc_info.hProcess, &rc); | |||
okay = ::GetExitCodeProcess(proc_info.hProcess, &rc); | |||
if (!okay || rc == STILL_ACTIVE) { | |||
throw_system_error("Failed reading exit code of process"); | |||
} | |||
proc_result res; | |||
res.retc = rc; | |||
res.retc = rc; | |||
res.output = std::move(output); | |||
return res; | |||
} |
@@ -215,9 +215,10 @@ vector<string> toolchain::create_archive_command(const archive_spec& spec) const | |||
vector<string> cmd; | |||
for (auto& arg : _archive_template) { | |||
if (arg == "<OBJECTS>") { | |||
std::transform(spec.input_files.begin(), spec.input_files.end(), std::back_inserter(cmd), [](auto&& p) { | |||
return p.string(); | |||
}); | |||
std::transform(spec.input_files.begin(), | |||
spec.input_files.end(), | |||
std::back_inserter(cmd), | |||
[](auto&& p) { return p.string(); }); | |||
} else { | |||
cmd.push_back(replace(arg, "<ARCHIVE>", spec.out_path.string())); | |||
} |
@@ -19,9 +19,9 @@ enum class language { | |||
struct compile_file_spec { | |||
fs::path source_path; | |||
fs::path out_path; | |||
std::vector<std::string> definitions = {}; | |||
std::vector<fs::path> include_dirs = {}; | |||
language lang = language::automatic; | |||
std::vector<std::string> definitions = {}; | |||
std::vector<fs::path> include_dirs = {}; | |||
language lang = language::automatic; | |||
bool enable_warnings = false; | |||
}; | |||
@@ -17,7 +17,6 @@ std::fstream dds::open(const fs::path& filepath, std::ios::openmode mode, std::e | |||
return ret; | |||
} | |||
std::string dds::slurp_file(const fs::path& path, std::error_code& ec) { | |||
auto file = dds::open(path, std::ios::in, ec); | |||
if (ec) { |
@@ -1,9 +1,9 @@ | |||
#ifndef DDS_UTIL_HPP_INCLUDED | |||
#define DDS_UTIL_HPP_INCLUDED | |||
#include <algorithm> | |||
#include <filesystem> | |||
#include <fstream> | |||
#include <algorithm> | |||
namespace dds { | |||
@@ -38,7 +38,7 @@ struct requirement_failed {}; | |||
std::cerr << "An unhandled exception occured: " << e.what() << '\n'; \ | |||
return 2; \ | |||
} \ | |||
return ::dds::S_failed_checks; \ | |||
return ::dds::S_failed_checks; \ | |||
} \ | |||
static_assert(true) | |||