Browse Source

spdlog is slow to compile. Wrap in a shim

default_compile_flags
vector-of-bool 4 years ago
parent
commit
fae2776f66
27 changed files with 209 additions and 121 deletions
  1. +2
    -1
      package.jsonc
  2. +15
    -14
      src/dds.main.cpp
  3. +10
    -11
      src/dds/build/builder.cpp
  4. +3
    -3
      src/dds/build/file_deps.cpp
  5. +5
    -7
      src/dds/build/plan/archive.cpp
  6. +19
    -19
      src/dds/build/plan/compile_exec.cpp
  7. +0
    -2
      src/dds/build/plan/compile_file.cpp
  8. +6
    -7
      src/dds/build/plan/exe.cpp
  9. +0
    -2
      src/dds/build/plan/full.cpp
  10. +4
    -5
      src/dds/catalog/catalog.cpp
  11. +5
    -5
      src/dds/catalog/get.cpp
  12. +3
    -3
      src/dds/db/database.cpp
  13. +0
    -1
      src/dds/library/manifest.cpp
  14. +2
    -3
      src/dds/library/root.cpp
  15. +2
    -2
      src/dds/package/manifest.cpp
  16. +3
    -4
      src/dds/proc.nix.cpp
  17. +0
    -1
      src/dds/proc.win.cpp
  18. +10
    -11
      src/dds/repo/repo.cpp
  19. +5
    -5
      src/dds/solve/solve.cpp
  20. +5
    -6
      src/dds/source/dist.cpp
  21. +33
    -0
      src/dds/util/log.cpp
  22. +68
    -0
      src/dds/util/log.hpp
  23. +2
    -2
      src/dds/util/parallel.cpp
  24. +2
    -2
      src/dds/util/paths.linux_fbsd.cpp
  25. +2
    -2
      src/dds/util/paths.macos.cpp
  26. +2
    -2
      src/dds/util/paths.win.cpp
  27. +1
    -1
      src/libman/library.cpp

+ 2
- 1
package.jsonc View File

"version": "0.1.0-alpha.4", "version": "0.1.0-alpha.4",
"namespace": "dds", "namespace": "dds",
"depends": { "depends": {
"spdlog": "1.4.2",
"spdlog": "1.7.0",
"ms-wil": "2020.3.16", "ms-wil": "2020.3.16",
"range-v3": "0.10.0", "range-v3": "0.10.0",
"nlohmann-json": "3.7.1", "nlohmann-json": "3.7.1",
"vob-json5": "0.1.5", "vob-json5": "0.1.5",
"vob-semester": "0.2.1", "vob-semester": "0.2.1",
"ctre": "2.8.1", "ctre": "2.8.1",
"fmt": "^7.0.0"
}, },
"test_driver": "Catch-Main" "test_driver": "Catch-Main"
} }

+ 15
- 14
src/dds.main.cpp View File

#include <dds/source/dist.hpp> #include <dds/source/dist.hpp>
#include <dds/toolchain/from_json.hpp> #include <dds/toolchain/from_json.hpp>
#include <dds/util/fs.hpp> #include <dds/util/fs.hpp>
#include <dds/util/log.hpp>
#include <dds/util/paths.hpp> #include <dds/util/paths.hpp>
#include <dds/util/signal.hpp> #include <dds/util/signal.hpp>


#include <range/v3/view/concat.hpp> #include <range/v3/view/concat.hpp>
#include <range/v3/view/group_by.hpp> #include <range/v3/view/group_by.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>


#include <dds/3rd/args.hxx> #include <dds/3rd/args.hxx>
#include <spdlog/spdlog.h>


#include <filesystem> #include <filesystem>
#include <iostream> #include <iostream>
auto tsd = dds::get_package_sdist(*info); auto tsd = dds::get_package_sdist(*info);
auto out_path = out.Get(); auto out_path = out.Get();
auto dest = out_path / id.to_string(); auto dest = out_path / id.to_string();
spdlog::info("Create sdist at {}", dest.string());
dds::log::info("Create sdist at {}", dest.string());
dds::fs::remove_all(dest); dds::fs::remove_all(dest);
dds::safe_rename(tsd.sdist.path, dest); dds::safe_rename(tsd.sdist.path, dest);
} }
auto cat = cat_path.open(); auto cat = cat_path.open();
auto pkg = cat.get(pk_id); auto pkg = cat.get(pk_id);
if (!pkg) { if (!pkg) {
spdlog::error("No package '{}' in the catalog", pk_id.to_string());
dds::log::error("No package '{}' in the catalog", pk_id.to_string());
return 1; return 1;
} }
std::cout << "Name: " << pkg->ident.name << '\n' std::cout << "Name: " << pkg->ident.name << '\n'
}); });


for (const auto& [name, grp] : grp_by_name) { for (const auto& [name, grp] : grp_by_name) {
spdlog::info("{}:", name);
dds::log::info("{}:", name);
for (const dds::sdist& sd : grp) { for (const dds::sdist& sd : grp) {
spdlog::info(" - {}", sd.manifest.pkg_id.version.to_string());
dds::log::info(" - {}", sd.manifest.pkg_id.version.to_string());
} }
} }




auto all_file_deps = deps_files.Get() // auto all_file_deps = deps_files.Get() //
| ranges::views::transform([&](auto dep_fpath) { | ranges::views::transform([&](auto dep_fpath) {
spdlog::info("Reading deps from {}", dep_fpath.string());
dds::log::info("Reading deps from {}", dep_fpath.string());
return dds::dependency_manifest::from_file(dep_fpath).dependencies; return dds::dependency_manifest::from_file(dep_fpath).dependencies;
}) })
| ranges::actions::join; | ranges::actions::join;
dds::repo_flags::write_lock | dds::repo_flags::create_if_absent, dds::repo_flags::write_lock | dds::repo_flags::create_if_absent,
[&](dds::repository repo) { [&](dds::repository repo) {
// Download dependencies // Download dependencies
spdlog::info("Loading {} dependencies", all_deps.size());
dds::log::info("Loading {} dependencies", all_deps.size());
auto deps = repo.solve(all_deps, cat); auto deps = repo.solve(all_deps, cat);
dds::get_all(deps, repo, cat); dds::get_all(deps, repo, cat);
for (const dds::package_id& pk : deps) { for (const dds::package_id& pk : deps) {
assert(sdist_ptr); assert(sdist_ptr);
dds::sdist_build_params deps_params; dds::sdist_build_params deps_params;
deps_params.subdir = sdist_ptr->manifest.pkg_id.to_string(); deps_params.subdir = sdist_ptr->manifest.pkg_id.to_string();
spdlog::info("Dependency: {}", sdist_ptr->manifest.pkg_id.to_string());
dds::log::info("Dependency: {}", sdist_ptr->manifest.pkg_id.to_string());
bd.add(*sdist_ptr, deps_params); bd.add(*sdist_ptr, deps_params);
} }
}); });


int main(int argc, char** argv) { int main(int argc, char** argv) {
#if DDS_DEBUG #if DDS_DEBUG
spdlog::set_level(spdlog::level::debug);
dds::log::current_log_level = dds::log::level::debug;
#endif #endif
spdlog::set_pattern("[%H:%M:%S] [%^%-5l%$] %v"); spdlog::set_pattern("[%H:%M:%S] [%^%-5l%$] %v");
args::ArgumentParser parser("DDS - The drop-dead-simple library manager"); args::ArgumentParser parser("DDS - The drop-dead-simple library manager");
std::terminate(); std::terminate();
} }
} catch (const dds::user_cancelled&) { } catch (const dds::user_cancelled&) {
spdlog::critical("Operation cancelled by user");
dds::log::critical("Operation cancelled by user");
return 2; return 2;
} catch (const dds::error_base& e) { } catch (const dds::error_base& e) {
spdlog::error("{}", e.what());
spdlog::error("{}", e.explanation());
spdlog::error("Refer: {}", e.error_reference());
dds::log::error("{}", e.what());
dds::log::error("{}", e.explanation());
dds::log::error("Refer: {}", e.error_reference());
return 1; return 1;
} catch (const std::exception& e) { } catch (const std::exception& e) {
spdlog::critical(e.what());
dds::log::critical(e.what());
return 2; return 2;
} }
} }

+ 10
- 11
src/dds/build/builder.cpp View File

#include <dds/compdb.hpp> #include <dds/compdb.hpp>
#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/usage_reqs.hpp> #include <dds/usage_reqs.hpp>
#include <dds/util/log.hpp>
#include <dds/util/output.hpp> #include <dds/util/output.hpp>
#include <dds/util/time.hpp> #include <dds/util/time.hpp>


#include <spdlog/spdlog.h>

#include <array> #include <array>
#include <set> #include <set>


}; };


void log_failure(const test_failure& fail) { void log_failure(const test_failure& fail) {
spdlog::error("Test '{}' failed! [exited {}]", fail.executable_path.string(), fail.retc);
log::error("Test '{}' failed! [exited {}]", fail.executable_path.string(), fail.retc);
if (fail.signal) { if (fail.signal) {
spdlog::error("Test execution received signal {}", fail.signal);
log::error("Test execution received signal {}", fail.signal);
} }
if (trim_view(fail.output).empty()) { if (trim_view(fail.output).empty()) {
spdlog::error("(Test executable produced no output");
log::error("(Test executable produced no output");
} else { } else {
spdlog::error("Test output:\n{}[dds - test output end]", fail.output);
log::error("Test output:\n{}[dds - test output end]", fail.output);
} }
} }


auto obj_file = plan.calc_object_file_path(env2); auto obj_file = plan.calc_object_file_path(env2);


if (!fs::exists(obj_file)) { if (!fs::exists(obj_file)) {
spdlog::info("Compiling Catch2 test driver (This will only happen once)...");
log::info("Compiling Catch2 test driver (This will only happen once)...");
compile_all(std::array{plan}, env2, 1); compile_all(std::array{plan}, env2, 1);
} }




dds::stopwatch sw; dds::stopwatch sw;
plan.compile_all(env, params.parallel_jobs); plan.compile_all(env, params.parallel_jobs);
spdlog::info("Compilation completed in {:n}ms", sw.elapsed_ms().count());
log::info("Compilation completed in {:n}ms", sw.elapsed_ms().count());


sw.reset(); sw.reset();
plan.archive_all(env, params.parallel_jobs); plan.archive_all(env, params.parallel_jobs);
spdlog::info("Archiving completed in {:n}ms", sw.elapsed_ms().count());
log::info("Archiving completed in {:n}ms", sw.elapsed_ms().count());


sw.reset(); sw.reset();
plan.link_all(env, params.parallel_jobs); plan.link_all(env, params.parallel_jobs);
spdlog::info("Runtime binary linking completed in {:n}ms", sw.elapsed_ms().count());
log::info("Runtime binary linking completed in {:n}ms", sw.elapsed_ms().count());


sw.reset(); sw.reset();
auto test_failures = plan.run_all_tests(env, params.parallel_jobs); auto test_failures = plan.run_all_tests(env, params.parallel_jobs);
spdlog::info("Test execution finished in {:n}ms", sw.elapsed_ms().count());
log::info("Test execution finished in {:n}ms", sw.elapsed_ms().count());


for (auto& fail : test_failures) { for (auto& fail : test_failures) {
log_failure(fail); log_failure(fail);

+ 3
- 3
src/dds/build/file_deps.cpp View File



#include <dds/db/database.hpp> #include <dds/db/database.hpp>
#include <dds/proc.hpp> #include <dds/proc.hpp>
#include <dds/util/log.hpp>
#include <dds/util/shlex.hpp> #include <dds/util/shlex.hpp>
#include <dds/util/string.hpp> #include <dds/util/string.hpp>


#include <range/v3/view/filter.hpp> #include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>


using namespace dds; using namespace dds;


auto iter = split.begin(); auto iter = split.begin();
auto stop = split.end(); auto stop = split.end();
if (iter == stop) { if (iter == stop) {
spdlog::critical(
log::critical(
"Invalid deps listing. Shell split was empty. This is almost certainly a bug."); "Invalid deps listing. Shell split was empty. This is almost certainly a bug.");
return ret; return ret;
} }
auto& head = *iter; auto& head = *iter;
++iter; ++iter;
if (!ends_with(head, ":")) { if (!ends_with(head, ":")) {
spdlog::critical(
log::critical(
"Invalid deps listing. Leader item is not colon-terminated. This is probably a bug. " "Invalid deps listing. Leader item is not colon-terminated. This is probably a bug. "
"(Are you trying to use C++ Modules? That's not ready yet, sorry. Set `Deps-Mode` to " "(Are you trying to use C++ Modules? That's not ready yet, sorry. Set `Deps-Mode` to "
"`None` in your toolchain file.)"); "`None` in your toolchain file.)");

+ 5
- 7
src/dds/build/plan/archive.cpp View File



#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/proc.hpp> #include <dds/proc.hpp>
#include <dds/util/log.hpp>
#include <dds/util/time.hpp> #include <dds/util/time.hpp>


#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>


using namespace dds; using namespace dds;


fs::create_directories(ar.out_path.parent_path()); fs::create_directories(ar.out_path.parent_path());


// Do it! // Do it!
spdlog::info("[{}] Archive: {}", _qual_name, out_relpath);
log::info("[{}] Archive: {}", _qual_name, out_relpath);
auto&& [dur_ms, ar_res] = timed<std::chrono::milliseconds>([&] { return run_proc(ar_cmd); }); auto&& [dur_ms, ar_res] = timed<std::chrono::milliseconds>([&] { return run_proc(ar_cmd); });
spdlog::info("[{}] Archive: {} - {:n}ms", _qual_name, out_relpath, dur_ms.count());
log::info("[{}] Archive: {} - {:n}ms", _qual_name, out_relpath, dur_ms.count());


// Check, log, and throw // Check, log, and throw
if (!ar_res.okay()) { if (!ar_res.okay()) {
spdlog::error("Creating static library archive [{}] failed for '{}'",
out_relpath,
_qual_name);
spdlog::error("Subcommand FAILED: {}\n{}", quote_command(ar_cmd), ar_res.output);
log::error("Creating static library archive [{}] failed for '{}'", out_relpath, _qual_name);
log::error("Subcommand FAILED: {}\n{}", quote_command(ar_cmd), ar_res.output);
throw_external_error< throw_external_error<
errc::archive_failure>("Creating static library archive [{}] failed for '{}'", errc::archive_failure>("Creating static library archive [{}] failed for '{}'",
out_relpath, out_relpath,

+ 19
- 19
src/dds/build/plan/compile_exec.cpp View File

#include <dds/build/file_deps.hpp> #include <dds/build/file_deps.hpp>
#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/proc.hpp> #include <dds/proc.hpp>
#include <dds/util/log.hpp>
#include <dds/util/parallel.hpp> #include <dds/util/parallel.hpp>
#include <dds/util/string.hpp> #include <dds/util/string.hpp>
#include <dds/util/time.hpp> #include <dds/util/time.hpp>


#include <range/v3/view/filter.hpp> #include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>


#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
fs::relative(source_path, cf.plan.source().basis_path).string()); fs::relative(source_path, cf.plan.source().basis_path).string());


// Do it! // Do it!
spdlog::info(msg);
log::info(msg);
auto&& [dur_ms, proc_res] auto&& [dur_ms, proc_res]
= timed<std::chrono::milliseconds>([&] { return run_proc(cf.cmd_info.command); }); = timed<std::chrono::milliseconds>([&] { return run_proc(cf.cmd_info.command); });
auto nth = counter.n.fetch_add(1); auto nth = counter.n.fetch_add(1);
spdlog::info("{:60} - {:>7n}ms [{:{}}/{}]",
msg,
dur_ms.count(),
nth,
counter.max_digits,
counter.max);
log::info("{:60} - {:>7n}ms [{:{}}/{}]",
msg,
dur_ms.count(),
nth,
counter.max_digits,
counter.max);


const bool compiled_okay = proc_res.okay(); const bool compiled_okay = proc_res.okay();
const auto compile_retc = proc_res.retc; const auto compile_retc = proc_res.retc;
assert(cf.cmd_info.gnu_depfile_path.has_value()); assert(cf.cmd_info.gnu_depfile_path.has_value());
auto& df_path = *cf.cmd_info.gnu_depfile_path; auto& df_path = *cf.cmd_info.gnu_depfile_path;
if (!fs::is_regular_file(df_path)) { if (!fs::is_regular_file(df_path)) {
spdlog::critical(
log::critical(
"The expected Makefile deps were not generated on disk. This is a bug! " "The expected Makefile deps were not generated on disk. This is a bug! "
"(Expected file to exist: [{}])", "(Expected file to exist: [{}])",
df_path.string()); df_path.string());


// Log a compiler failure // Log a compiler failure
if (!compiled_okay) { if (!compiled_okay) {
spdlog::error("Compilation failed: {}", source_path.string());
spdlog::error("Subcommand FAILED [Exitted {}]: {}\n{}",
compile_retc,
quote_command(cf.cmd_info.command),
compiler_output);
log::error("Compilation failed: {}", source_path.string());
log::error("Subcommand FAILED [Exitted {}]: {}\n{}",
compile_retc,
quote_command(cf.cmd_info.command),
compiler_output);
if (compile_signal) { if (compile_signal) {
spdlog::error("Process exited via signal {}", compile_signal);
log::error("Process exited via signal {}", compile_signal);
} }
throw_user_error<errc::compile_failure>("Compilation failed [{}]", source_path.string()); throw_user_error<errc::compile_failure>("Compilation failed [{}]", source_path.string());
} }


// Print any compiler output, sans whitespace // Print any compiler output, sans whitespace
if (!dds::trim_view(compiler_output).empty()) { if (!dds::trim_view(compiler_output).empty()) {
spdlog::warn("While compiling file {} [{}]:\n{}",
source_path.string(),
quote_command(cf.cmd_info.command),
compiler_output);
log::warn("While compiling file {} [{}]:\n{}",
source_path.string(),
quote_command(cf.cmd_info.command),
compiler_output);
} }


// We'll only get here if the compilation was successful, otherwise we throw // We'll only get here if the compilation was successful, otherwise we throw

+ 0
- 2
src/dds/build/plan/compile_file.cpp View File

#include <dds/util/signal.hpp> #include <dds/util/signal.hpp>
#include <dds/util/time.hpp> #include <dds/util/time.hpp>


#include <spdlog/spdlog.h>

#include <string> #include <string>
#include <vector> #include <vector>



+ 6
- 7
src/dds/build/plan/exe.cpp View File

#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/proc.hpp> #include <dds/proc.hpp>
#include <dds/util/algo.hpp> #include <dds/util/algo.hpp>
#include <dds/util/log.hpp>
#include <dds/util/time.hpp> #include <dds/util/time.hpp>


#include <spdlog/spdlog.h>

#include <algorithm> #include <algorithm>
#include <chrono> #include <chrono>


auto msg = fmt::format("[{}] Link: {:30}", auto msg = fmt::format("[{}] Link: {:30}",
lib.qualified_name(), lib.qualified_name(),
fs::relative(spec.output, env.output_root).string()); fs::relative(spec.output, env.output_root).string());
spdlog::info(msg);
log::info(msg);
auto [dur_ms, proc_res] auto [dur_ms, proc_res]
= timed<std::chrono::milliseconds>([&] { return run_proc(link_command); }); = timed<std::chrono::milliseconds>([&] { return run_proc(link_command); });
spdlog::info("{} - {:>6n}ms", msg, dur_ms.count());
log::info("{} - {:>6n}ms", msg, dur_ms.count());


// Check and throw if errant // Check and throw if errant
if (!proc_res.okay()) { if (!proc_res.okay()) {
std::optional<test_failure> link_executable_plan::run_test(build_env_ref env) const { std::optional<test_failure> link_executable_plan::run_test(build_env_ref env) const {
auto exe_path = calc_executable_path(env); auto exe_path = calc_executable_path(env);
auto msg = fmt::format("Run test: {:30}", fs::relative(exe_path, env.output_root).string()); auto msg = fmt::format("Run test: {:30}", fs::relative(exe_path, env.output_root).string());
spdlog::info(msg);
log::info(msg);
using namespace std::chrono_literals; using namespace std::chrono_literals;
auto&& [dur, res] = timed<std::chrono::microseconds>( auto&& [dur, res] = timed<std::chrono::microseconds>(
[&] { return run_proc({.command = {exe_path.string()}, .timeout = 10s}); }); [&] { return run_proc({.command = {exe_path.string()}, .timeout = 10s}); });


if (res.okay()) { if (res.okay()) {
spdlog::info("{} - PASSED - {:>9n}μs", msg, dur.count());
log::info("{} - PASSED - {:>9n}μs", msg, dur.count());
return std::nullopt; return std::nullopt;
} else { } else {
auto exit_msg = fmt::format(res.signal ? "signalled {}" : "exited {}", auto exit_msg = fmt::format(res.signal ? "signalled {}" : "exited {}",
res.signal ? res.signal : res.retc); res.signal ? res.signal : res.retc);
auto fail_str = res.timed_out ? "TIMEOUT" : "FAILED "; auto fail_str = res.timed_out ? "TIMEOUT" : "FAILED ";
spdlog::error("{} - {} - {:>9n}μs [{}]", msg, fail_str, dur.count(), exit_msg);
log::error("{} - {} - {:>9n}μs [{}]", msg, fail_str, dur.count(), exit_msg);
test_failure f; test_failure f;
f.executable_path = exe_path; f.executable_path = exe_path;
f.output = res.output; f.output = res.output;

+ 0
- 2
src/dds/build/plan/full.cpp View File

#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <range/v3/view/zip.hpp> #include <range/v3/view/zip.hpp>


#include <spdlog/spdlog.h>

#include <mutex> #include <mutex>
#include <thread> #include <thread>



+ 4
- 5
src/dds/catalog/catalog.cpp View File

#include <dds/dym.hpp> #include <dds/dym.hpp>
#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/solve/solve.hpp> #include <dds/solve/solve.hpp>
#include <dds/util/log.hpp>


#include <json5/parse_data.hpp> #include <json5/parse_data.hpp>
#include <neo/assert.hpp> #include <neo/assert.hpp>
#include <range/v3/view/join.hpp> #include <range/v3/view/join.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>


#include <spdlog/spdlog.h>

using namespace dds; using namespace dds;


namespace sqlite3 = neo::sqlite3; namespace sqlite3 = neo::sqlite3;
exec(db, "UPDATE dds_cat_meta SET meta=?", std::forward_as_tuple(meta.dump())); exec(db, "UPDATE dds_cat_meta SET meta=?", std::forward_as_tuple(meta.dump()));


if (import_init_packages) { if (import_init_packages) {
spdlog::info(
log::info(
"A new catalog database case been created, and has been populated with some initial " "A new catalog database case been created, and has been populated with some initial "
"contents."); "contents.");
neo::sqlite3::statement_cache stmts{db}; neo::sqlite3::statement_cache stmts{db};
try { try {
ensure_migrated(db); ensure_migrated(db);
} catch (const sqlite3::sqlite3_error& e) { } catch (const sqlite3::sqlite3_error& e) {
spdlog::critical(
log::critical(
"Failed to load the repository database. It appears to be invalid/corrupted. The " "Failed to load the repository database. It appears to be invalid/corrupted. The "
"exception message is: {}", "exception message is: {}",
e.what()); e.what());


void catalog::import_initial() { void catalog::import_initial() {
sqlite3::transaction_guard tr{_db}; sqlite3::transaction_guard tr{_db};
spdlog::info("Restoring built-in initial catalog contents");
log::info("Restoring built-in initial catalog contents");
store_init_packages(_db, _stmt_cache); store_init_packages(_db, _stmt_cache);
} }

+ 5
- 5
src/dds/catalog/get.cpp View File

#include <dds/catalog/catalog.hpp> #include <dds/catalog/catalog.hpp>
#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/repo/repo.hpp> #include <dds/repo/repo.hpp>
#include <dds/util/log.hpp>
#include <dds/util/parallel.hpp> #include <dds/util/parallel.hpp>


#include <neo/assert.hpp> #include <neo/assert.hpp>
#include <range/v3/numeric/accumulate.hpp> #include <range/v3/numeric/accumulate.hpp>
#include <range/v3/view/filter.hpp> #include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>


using namespace dds; using namespace dds;


temporary_sdist do_pull_sdist(const package_info& listing, const git_remote_listing& git) { temporary_sdist do_pull_sdist(const package_info& listing, const git_remote_listing& git) {
auto tmpdir = dds::temporary_dir::create(); auto tmpdir = dds::temporary_dir::create();


spdlog::info("Cloning Git repository: {} [{}] ...", git.url, git.ref);
log::info("Cloning Git repository: {} [{}] ...", git.url, git.ref);
git.clone(tmpdir.path()); git.clone(tmpdir.path());


for (const auto& tr : git.transforms) { for (const auto& tr : git.transforms) {
tr.apply_to(tmpdir.path()); tr.apply_to(tmpdir.path());
} }


spdlog::info("Create sdist from clone ...");
log::info("Create sdist from clone ...");
if (git.auto_lib.has_value()) { if (git.auto_lib.has_value()) {
spdlog::info("Generating library data automatically");
log::info("Generating library data automatically");


auto pkg_strm auto pkg_strm
= dds::open(tmpdir.path() / "package.json5", std::ios::binary | std::ios::out); = dds::open(tmpdir.path() / "package.json5", std::ios::binary | std::ios::out);
}); });


auto okay = parallel_run(absent_pkg_infos, 8, [&](package_info inf) { auto okay = parallel_run(absent_pkg_infos, 8, [&](package_info inf) {
spdlog::info("Download package: {}", inf.ident.to_string());
log::info("Download package: {}", inf.ident.to_string());
auto tsd = get_package_sdist(inf); auto tsd = get_package_sdist(inf);
std::scoped_lock lk{repo_mut}; std::scoped_lock lk{repo_mut};
repo.add_sdist(tsd.sdist, if_exists::throw_exc); repo.add_sdist(tsd.sdist, if_exists::throw_exc);

+ 3
- 3
src/dds/db/database.cpp View File

#include "./database.hpp" #include "./database.hpp"


#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/util/log.hpp>


#include <neo/sqlite3/exec.hpp> #include <neo/sqlite3/exec.hpp>
#include <neo/sqlite3/iter_tuples.hpp> #include <neo/sqlite3/iter_tuples.hpp>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <range/v3/range/conversion.hpp> #include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>


using namespace dds; using namespace dds;


try { try {
ensure_migrated(db); ensure_migrated(db);
} catch (const sqlite3::sqlite3_error& e) { } catch (const sqlite3::sqlite3_error& e) {
spdlog::error(
log::error(
"Failed to load the databsae. It appears to be invalid/corrupted. We'll delete it and " "Failed to load the databsae. It appears to be invalid/corrupted. We'll delete it and "
"create a new one. The exception message is: {}", "create a new one. The exception message is: {}",
e.what()); e.what());
try { try {
ensure_migrated(db); ensure_migrated(db);
} catch (const sqlite3::sqlite3_error& e) { } catch (const sqlite3::sqlite3_error& e) {
spdlog::critical(
log::critical(
"Failed to apply database migrations to recovery database. This is a critical " "Failed to apply database migrations to recovery database. This is a critical "
"error. The exception message is: {}", "error. The exception message is: {}",
e.what()); e.what());

+ 0
- 1
src/dds/library/manifest.cpp View File

#include <json5/parse_data.hpp> #include <json5/parse_data.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <semester/decomp.hpp> #include <semester/decomp.hpp>
#include <spdlog/spdlog.h>


using namespace dds; using namespace dds;



+ 2
- 3
src/dds/library/root.cpp View File

#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/source/root.hpp> #include <dds/source/root.hpp>
#include <dds/util/algo.hpp> #include <dds/util/algo.hpp>
#include <dds/util/log.hpp>


#include <range/v3/view/filter.hpp> #include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>


using namespace dds; using namespace dds;


// Drop any source files we found within `include/` // Drop any source files we found within `include/`
erase_if(sources, [&](auto& info) { erase_if(sources, [&](auto& info) {
if (info.kind != source_kind::header) { if (info.kind != source_kind::header) {
spdlog::warn("Source file in `include` will not be compiled: {}",
info.path.string());
log::warn("Source file in `include` will not be compiled: {}", info.path.string());
return true; return true;
} }
return false; return false;

+ 2
- 2
src/dds/package/manifest.cpp View File



#include <dds/dym.hpp> #include <dds/dym.hpp>
#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/util/log.hpp>
#include <dds/util/string.hpp> #include <dds/util/string.hpp>


#include <range/v3/view/split.hpp> #include <range/v3/view/split.hpp>
#include <range/v3/view/split_when.hpp> #include <range/v3/view/split_when.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <semester/walk.hpp> #include <semester/walk.hpp>
#include <spdlog/spdlog.h>


#include <json5/parse_data.hpp> #include <json5/parse_data.hpp>


if_key{"depends", if_key{"depends",
[&](auto&& dat) { [&](auto&& dat) {
if (dat.is_object()) { if (dat.is_object()) {
spdlog::warn(
log::warn(
"{}: Using a JSON object for 'depends' is deprecated. Use an " "{}: Using a JSON object for 'depends' is deprecated. Use an "
"array of strings instead.", "array of strings instead.",
fpath); fpath);

+ 3
- 4
src/dds/proc.nix.cpp View File

#ifndef _WIN32 #ifndef _WIN32
#include "./proc.hpp" #include "./proc.hpp"


#include <dds/util/log.hpp>
#include <dds/util/signal.hpp> #include <dds/util/signal.hpp>


#include <spdlog/spdlog.h>

#include <poll.h> #include <poll.h>
#include <signal.h> #include <signal.h>
#include <sys/wait.h> #include <sys/wait.h>
} // namespace } // namespace


proc_result dds::run_proc(const proc_options& opts) { proc_result dds::run_proc(const proc_options& opts) {
spdlog::debug("Spawning subprocess: {}", quote_command(opts.command));
log::debug("Spawning subprocess: {}", quote_command(opts.command));
int stdio_pipe[2] = {}; int stdio_pipe[2] = {};
auto rc = ::pipe(stdio_pipe); auto rc = ::pipe(stdio_pipe);
check_rc(rc == 0, "Create stdio pipe for subprocess"); check_rc(rc == 0, "Create stdio pipe for subprocess");
::kill(child, SIGINT); ::kill(child, SIGINT);
timeout = -1ms; timeout = -1ms;
res.timed_out = true; res.timed_out = true;
spdlog::debug("Subprocess [{}] timed out", quote_command(opts.command));
log::debug("Subprocess [{}] timed out", quote_command(opts.command));
continue; continue;
} }
std::string buffer; std::string buffer;

+ 0
- 1
src/dds/proc.win.cpp View File

#include "./proc.hpp" #include "./proc.hpp"


#include <neo/assert.hpp> #include <neo/assert.hpp>
#include <spdlog/spdlog.h>
#include <wil/resource.h> #include <wil/resource.h>


#include <windows.h> #include <windows.h>

+ 10
- 11
src/dds/repo/repo.cpp View File

#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/solve/solve.hpp> #include <dds/solve/solve.hpp>
#include <dds/source/dist.hpp> #include <dds/source/dist.hpp>
#include <dds/util/log.hpp>
#include <dds/util/paths.hpp> #include <dds/util/paths.hpp>
#include <dds/util/string.hpp> #include <dds/util/string.hpp>


#include <spdlog/spdlog.h>

#include <range/v3/action/sort.hpp> #include <range/v3/action/sort.hpp>
#include <range/v3/action/unique.hpp> #include <range/v3/action/unique.hpp>
#include <range/v3/range/conversion.hpp> #include <range/v3/range/conversion.hpp>
try { try {
return sdist::from_directory(p); return sdist::from_directory(p);
} catch (const std::runtime_error& e) { } catch (const std::runtime_error& e) {
spdlog::error("Failed to load source distribution from directory '{}': {}",
p.string(),
e.what());
log::error("Failed to load source distribution from directory '{}': {}",
p.string(),
e.what());
return std::nullopt; return std::nullopt;
} }
}; };
} // namespace } // namespace


void repository::_log_blocking(path_ref dirpath) noexcept { void repository::_log_blocking(path_ref dirpath) noexcept {
spdlog::warn("Another process has the repository directory locked [{}]", dirpath.string());
spdlog::warn("Waiting for repository to be released...");
log::warn("Another process has the repository directory locked [{}]", dirpath.string());
log::warn("Waiting for repository to be released...");
} }


void repository::_init_repo_dir(path_ref dirpath) noexcept { fs::create_directories(dirpath); } void repository::_init_repo_dir(path_ref dirpath) noexcept { fs::create_directories(dirpath); }


void repository::add_sdist(const sdist& sd, if_exists ife_action) { void repository::add_sdist(const sdist& sd, if_exists ife_action) {
if (!_write_enabled) { if (!_write_enabled) {
spdlog::critical(
log::critical(
"DDS attempted to write into a repository that wasn't opened with a write-lock. This " "DDS attempted to write into a repository that wasn't opened with a write-lock. This "
"is a hard bug and should be reported. For the safety and integrity of the local " "is a hard bug and should be reported. For the safety and integrity of the local "
"repository, we'll hard-exit immediately."); "repository, we'll hard-exit immediately.");
if (ife_action == if_exists::throw_exc) { if (ife_action == if_exists::throw_exc) {
throw_user_error<errc::sdist_exists>(msg); throw_user_error<errc::sdist_exists>(msg);
} else if (ife_action == if_exists::ignore) { } else if (ife_action == if_exists::ignore) {
spdlog::warn(msg);
log::warn(msg);
return; return;
} else { } else {
spdlog::info(msg + " - Replacing");
log::info(msg + " - Replacing");
} }
} }
auto tmp_copy = sd_dest; auto tmp_copy = sd_dest;
} }
fs::rename(tmp_copy, sd_dest); fs::rename(tmp_copy, sd_dest);
_sdists.insert(sdist::from_directory(sd_dest)); _sdists.insert(sdist::from_directory(sd_dest));
spdlog::info("Source distribution '{}' successfully exported", sd.manifest.pkg_id.to_string());
log::info("Source distribution '{}' successfully exported", sd.manifest.pkg_id.to_string());
} }


const sdist* repository::find(const package_id& pkg) const noexcept { const sdist* repository::find(const package_id& pkg) const noexcept {

+ 5
- 5
src/dds/solve/solve.cpp View File

#include "./solve.hpp" #include "./solve.hpp"


#include <dds/error/errors.hpp> #include <dds/error/errors.hpp>
#include <dds/util/log.hpp>


#include <pubgrub/solve.hpp> #include <pubgrub/solve.hpp>


#include <range/v3/range/conversion.hpp> #include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>


#include <sstream> #include <sstream>


void operator()(pubgrub::explain::premise<T> pr) { void operator()(pubgrub::explain::premise<T> pr) {
strm.str(""); strm.str("");
put(pr.value); put(pr.value);
spdlog::error("{} {},", at_head ? "┌─ Given that" : "│ and", strm.str());
log::error("{} {},", at_head ? "┌─ Given that" : "│ and", strm.str());
at_head = false; at_head = false;
} }


at_head = true; at_head = true;
strm.str(""); strm.str("");
put(cncl.value); put(cncl.value);
spdlog::error("╘═ then {}.", strm.str());
log::error("╘═ then {}.", strm.str());
} }


void operator()(pubgrub::explain::separator) { spdlog::error(""); }
void operator()(pubgrub::explain::separator) { log::error(""); }
}; };


} // namespace } // namespace
auto solution = pubgrub::solve(wrap_req, solver_provider{pkgs_prov, deps_prov}); auto solution = pubgrub::solve(wrap_req, solver_provider{pkgs_prov, deps_prov});
return solution | ranges::views::transform(as_pkg_id) | ranges::to_vector; return solution | ranges::views::transform(as_pkg_id) | ranges::to_vector;
} catch (const solve_fail_exc& failure) { } catch (const solve_fail_exc& failure) {
spdlog::error("Dependency resolution has failed! Explanation:");
log::error("Dependency resolution has failed! Explanation:");
pubgrub::generate_explaination(failure, explainer()); pubgrub::generate_explaination(failure, explainer());
throw_user_error<errc::dependency_resolve_failure>(); throw_user_error<errc::dependency_resolve_failure>();
} }

+ 5
- 6
src/dds/source/dist.cpp View File

#include <dds/library/root.hpp> #include <dds/library/root.hpp>
#include <dds/temp.hpp> #include <dds/temp.hpp>
#include <dds/util/fs.hpp> #include <dds/util/fs.hpp>
#include <dds/util/log.hpp>


#include <libman/parse.hpp> #include <libman/parse.hpp>


#include <range/v3/algorithm/sort.hpp> #include <range/v3/algorithm/sort.hpp>
#include <range/v3/view/filter.hpp> #include <range/v3/view/filter.hpp>


#include <spdlog/spdlog.h>

using namespace dds; using namespace dds;


namespace { namespace {


void sdist_export_file(path_ref out_root, path_ref in_root, path_ref filepath) { void sdist_export_file(path_ref out_root, path_ref in_root, path_ref filepath) {
auto relpath = fs::relative(filepath, in_root); auto relpath = fs::relative(filepath, in_root);
spdlog::debug("Export file {}", relpath.string());
log::debug("Export file {}", relpath.string());
auto dest = out_root / relpath; auto dest = out_root / relpath;
fs::create_directories(dest.parent_path()); fs::create_directories(dest.parent_path());
fs::copy(filepath, dest); fs::copy(filepath, dest);
} }
sdist_export_file(out_root, params.project_dir, *lib_man_path); sdist_export_file(out_root, params.project_dir, *lib_man_path);


spdlog::info("sdist: Export library from {}", lib.path().string());
log::info("sdist: Export library from {}", lib.path().string());
fs::create_directories(out_root); fs::create_directories(out_root);
for (const auto& source : sources_to_keep) { for (const auto& source : sources_to_keep) {
sdist_export_file(out_root, params.project_dir, source.path); sdist_export_file(out_root, params.project_dir, source.path);
} }
fs::create_directories(dest.parent_path()); fs::create_directories(dest.parent_path());
safe_rename(tempdir.path(), dest); safe_rename(tempdir.path(), dest);
spdlog::info("Source distribution created in {}", dest.string());
log::info("Source distribution created in {}", dest.string());
return sdist::from_directory(dest); return sdist::from_directory(dest);
} }




auto pkg_man = package_manifest::load_from_file(*man_path); auto pkg_man = package_manifest::load_from_file(*man_path);
sdist_export_file(out, params.project_dir, *man_path); sdist_export_file(out, params.project_dir, *man_path);
spdlog::info("Generated export as {}", pkg_man.pkg_id.to_string());
log::info("Generated export as {}", pkg_man.pkg_id.to_string());
return sdist::from_directory(out); return sdist::from_directory(out);
} }



+ 33
- 0
src/dds/util/log.cpp View File

#include "./log.hpp"

#include <neo/assert.hpp>

#include <spdlog/spdlog.h>

void dds::log::log_print(dds::log::level l, std::string_view msg) noexcept {
static auto logger = [] {
auto logger = spdlog::default_logger_raw();
logger->set_level(spdlog::level::trace);
return logger;
}();

const auto lvl = [&] {
switch (l) {
case level::trace:
return spdlog::level::trace;
case level::debug:
return spdlog::level::debug;
case level::info:
return spdlog::level::info;
case level::warn:
return spdlog::level::warn;
case level::error:
return spdlog::level::err;
case level::critical:
return spdlog::level::critical;
}
neo_assert_always(invariant, false, "Invalid log level", msg, int(l));
}();

logger->log(lvl, msg);
}

+ 68
- 0
src/dds/util/log.hpp View File

#pragma once

#include <fmt/core.h>

#include <string_view>

namespace dds::log {

enum class level : int {
trace,
debug,
info,
warn,
error,
critical,
};

inline level current_log_level = level::info;

void log_print(level l, std::string_view s) noexcept;

// clang-format off
template <typename T>
concept formattable = requires (const T item) {
fmt::format("{}", item);
};

template <formattable... Args>
void log(level l, std::string_view s, const Args&... args) {
if (int(l) >= int(current_log_level)) {
auto message = fmt::format(s, args...);
log_print(l, message);
}
}

template <formattable... Args>
void trace(std::string_view s, const Args&... args) {
log(level::trace, s, args...);
}

template <formattable... Args>
void debug(std::string_view s, const Args&... args) {
log(level::debug, s, args...);
}

template <formattable... Args>
void info(std::string_view s, const Args&... args) {
log(level::info, s, args...);
}

template <formattable... Args>
void warn(std::string_view s, const Args&... args) {
log(level::warn, s, args...);
}

template <formattable... Args>
void error(std::string_view s, const Args&... args) {
log(level::error, s, args...);
}

template <formattable... Args>
void critical(std::string_view s, const Args&&... args) {
log(level::critical, s, args...);
}

// clang-format on

} // namespace dds::log

+ 2
- 2
src/dds/util/parallel.cpp View File

#include "./parallel.hpp" #include "./parallel.hpp"


#include <spdlog/spdlog.h>
#include <dds/util/log.hpp>


using namespace dds; using namespace dds;


try { try {
std::rethrow_exception(eptr); std::rethrow_exception(eptr);
} catch (const std::exception& e) { } catch (const std::exception& e) {
spdlog::error(e.what());
log::error(e.what());
} }
} }

+ 2
- 2
src/dds/util/paths.linux_fbsd.cpp View File



#include "./paths.hpp" #include "./paths.hpp"


#include <spdlog/spdlog.h>
#include <dds/util/log.hpp>


#include <cstdlib> #include <cstdlib>


static auto ret = []() -> fs::path { static auto ret = []() -> fs::path {
auto home_env = std::getenv("HOME"); auto home_env = std::getenv("HOME");
if (!home_env) { if (!home_env) {
spdlog::warn("No HOME environment variable set!");
log::error("No HOME environment variable set!");
return "/"; return "/";
} }
return fs::absolute(fs::path(home_env)); return fs::absolute(fs::path(home_env));

+ 2
- 2
src/dds/util/paths.macos.cpp View File



#include "./paths.hpp" #include "./paths.hpp"


#include <spdlog/spdlog.h>
#include <dds/util/log.hpp>


#include <cstdlib> #include <cstdlib>


static auto ret = []() -> fs::path { static auto ret = []() -> fs::path {
auto home_env = std::getenv("HOME"); auto home_env = std::getenv("HOME");
if (!home_env) { if (!home_env) {
spdlog::warn("No HOME environment variable set!");
log::warn("No HOME environment variable set!");
return "/"; return "/";
} }
return fs::absolute(fs::path(home_env)); return fs::absolute(fs::path(home_env));

+ 2
- 2
src/dds/util/paths.win.cpp View File



#include "./paths.hpp" #include "./paths.hpp"


#include <spdlog/spdlog.h>
#include <dds/util/log.hpp>


#include <cstdlib> #include <cstdlib>


static auto ret = []() -> fs::path { static auto ret = []() -> fs::path {
auto userprofile_env = std::getenv("USERPROFILE"); auto userprofile_env = std::getenv("USERPROFILE");
if (!userprofile_env) { if (!userprofile_env) {
spdlog::warn("No USERPROFILE environment variable set!");
log::warn("No USERPROFILE environment variable set!");
return "/"; return "/";
} }
return fs::absolute(fs::path(userprofile_env)); return fs::absolute(fs::path(userprofile_env));

+ 1
- 1
src/libman/library.cpp View File



#include <libman/parse.hpp> #include <libman/parse.hpp>


#include <spdlog/spdlog.h>
#include <fmt/core.h>


using namespace lm; using namespace lm;



Loading…
Cancel
Save