瀏覽代碼

spdlog is slow to compile. Wrap in a shim

default_compile_flags
vector-of-bool 4 年之前
父節點
當前提交
fae2776f66
共有 27 個檔案被更改,包括 209 行新增121 行删除
  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 查看文件

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

+ 15
- 14
src/dds.main.cpp 查看文件

@@ -7,6 +7,7 @@
#include <dds/source/dist.hpp>
#include <dds/toolchain/from_json.hpp>
#include <dds/util/fs.hpp>
#include <dds/util/log.hpp>
#include <dds/util/paths.hpp>
#include <dds/util/signal.hpp>

@@ -14,9 +15,9 @@
#include <range/v3/view/concat.hpp>
#include <range/v3/view/group_by.hpp>
#include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>

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

#include <filesystem>
#include <iostream>
@@ -226,7 +227,7 @@ struct cli_catalog {
auto tsd = dds::get_package_sdist(*info);
auto out_path = out.Get();
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::safe_rename(tsd.sdist.path, dest);
}
@@ -341,7 +342,7 @@ struct cli_catalog {
auto cat = cat_path.open();
auto pkg = cat.get(pk_id);
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;
}
std::cout << "Name: " << pkg->ident.name << '\n'
@@ -418,9 +419,9 @@ struct cli_repo {
});

for (const auto& [name, grp] : grp_by_name) {
spdlog::info("{}:", name);
dds::log::info("{}:", name);
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());
}
}

@@ -691,7 +692,7 @@ struct cli_build_deps {

auto all_file_deps = deps_files.Get() //
| 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;
})
| ranges::actions::join;
@@ -708,7 +709,7 @@ struct cli_build_deps {
dds::repo_flags::write_lock | dds::repo_flags::create_if_absent,
[&](dds::repository repo) {
// Download dependencies
spdlog::info("Loading {} dependencies", all_deps.size());
dds::log::info("Loading {} dependencies", all_deps.size());
auto deps = repo.solve(all_deps, cat);
dds::get_all(deps, repo, cat);
for (const dds::package_id& pk : deps) {
@@ -716,7 +717,7 @@ struct cli_build_deps {
assert(sdist_ptr);
dds::sdist_build_params deps_params;
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);
}
});
@@ -740,7 +741,7 @@ struct cli_build_deps {

int main(int argc, char** argv) {
#if DDS_DEBUG
spdlog::set_level(spdlog::level::debug);
dds::log::current_log_level = dds::log::level::debug;
#endif
spdlog::set_pattern("[%H:%M:%S] [%^%-5l%$] %v");
args::ArgumentParser parser("DDS - The drop-dead-simple library manager");
@@ -783,15 +784,15 @@ int main(int argc, char** argv) {
std::terminate();
}
} catch (const dds::user_cancelled&) {
spdlog::critical("Operation cancelled by user");
dds::log::critical("Operation cancelled by user");
return 2;
} 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;
} catch (const std::exception& e) {
spdlog::critical(e.what());
dds::log::critical(e.what());
return 2;
}
}

+ 10
- 11
src/dds/build/builder.cpp 查看文件

@@ -6,11 +6,10 @@
#include <dds/compdb.hpp>
#include <dds/error/errors.hpp>
#include <dds/usage_reqs.hpp>
#include <dds/util/log.hpp>
#include <dds/util/output.hpp>
#include <dds/util/time.hpp>

#include <spdlog/spdlog.h>

#include <array>
#include <set>

@@ -24,14 +23,14 @@ struct state {
};

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) {
spdlog::error("Test execution received signal {}", fail.signal);
log::error("Test execution received signal {}", fail.signal);
}
if (trim_view(fail.output).empty()) {
spdlog::error("(Test executable produced no output");
log::error("(Test executable produced no output");
} else {
spdlog::error("Test output:\n{}[dds - test output end]", fail.output);
log::error("Test output:\n{}[dds - test output end]", fail.output);
}
}

@@ -84,7 +83,7 @@ prepare_catch2_driver(test_lib test_driver, const build_params& params, build_en
auto obj_file = plan.calc_object_file_path(env2);

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);
}

@@ -242,19 +241,19 @@ void builder::build(const build_params& params) const {

dds::stopwatch sw;
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();
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();
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();
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) {
log_failure(fail);

+ 3
- 3
src/dds/build/file_deps.cpp 查看文件

@@ -2,12 +2,12 @@

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

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

using namespace dds;

@@ -26,14 +26,14 @@ file_deps_info dds::parse_mkfile_deps_str(std::string_view str) {
auto iter = split.begin();
auto stop = split.end();
if (iter == stop) {
spdlog::critical(
log::critical(
"Invalid deps listing. Shell split was empty. This is almost certainly a bug.");
return ret;
}
auto& head = *iter;
++iter;
if (!ends_with(head, ":")) {
spdlog::critical(
log::critical(
"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 "
"`None` in your toolchain file.)");

+ 5
- 7
src/dds/build/plan/archive.cpp 查看文件

@@ -2,10 +2,10 @@

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

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

using namespace dds;

@@ -40,16 +40,14 @@ void create_archive_plan::archive(const build_env& env) const {
fs::create_directories(ar.out_path.parent_path());

// 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); });
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
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<
errc::archive_failure>("Creating static library archive [{}] failed for '{}'",
out_relpath,

+ 19
- 19
src/dds/build/plan/compile_exec.cpp 查看文件

@@ -3,13 +3,13 @@
#include <dds/build/file_deps.hpp>
#include <dds/error/errors.hpp>
#include <dds/proc.hpp>
#include <dds/util/log.hpp>
#include <dds/util/parallel.hpp>
#include <dds/util/string.hpp>
#include <dds/util/time.hpp>

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

#include <algorithm>
#include <atomic>
@@ -54,16 +54,16 @@ do_compile(const compile_file_full& cf, build_env_ref env, compile_counter& coun
fs::relative(source_path, cf.plan.source().basis_path).string());

// Do it!
spdlog::info(msg);
log::info(msg);
auto&& [dur_ms, proc_res]
= timed<std::chrono::milliseconds>([&] { return run_proc(cf.cmd_info.command); });
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 auto compile_retc = proc_res.retc;
@@ -78,7 +78,7 @@ do_compile(const compile_file_full& cf, build_env_ref env, compile_counter& coun
assert(cf.cmd_info.gnu_depfile_path.has_value());
auto& df_path = *cf.cmd_info.gnu_depfile_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! "
"(Expected file to exist: [{}])",
df_path.string());
@@ -121,23 +121,23 @@ do_compile(const compile_file_full& cf, build_env_ref env, compile_counter& coun

// Log a compiler failure
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) {
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());
}

// Print any compiler output, sans whitespace
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

+ 0
- 2
src/dds/build/plan/compile_file.cpp 查看文件

@@ -5,8 +5,6 @@
#include <dds/util/signal.hpp>
#include <dds/util/time.hpp>

#include <spdlog/spdlog.h>

#include <string>
#include <vector>


+ 6
- 7
src/dds/build/plan/exe.cpp 查看文件

@@ -4,10 +4,9 @@
#include <dds/error/errors.hpp>
#include <dds/proc.hpp>
#include <dds/util/algo.hpp>
#include <dds/util/log.hpp>
#include <dds/util/time.hpp>

#include <spdlog/spdlog.h>

#include <algorithm>
#include <chrono>

@@ -49,10 +48,10 @@ void link_executable_plan::link(build_env_ref env, const library_plan& lib) cons
auto msg = fmt::format("[{}] Link: {:30}",
lib.qualified_name(),
fs::relative(spec.output, env.output_root).string());
spdlog::info(msg);
log::info(msg);
auto [dur_ms, proc_res]
= 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
if (!proc_res.okay()) {
@@ -77,19 +76,19 @@ bool link_executable_plan::is_test() const noexcept {
std::optional<test_failure> link_executable_plan::run_test(build_env_ref env) const {
auto exe_path = calc_executable_path(env);
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;
auto&& [dur, res] = timed<std::chrono::microseconds>(
[&] { return run_proc({.command = {exe_path.string()}, .timeout = 10s}); });

if (res.okay()) {
spdlog::info("{} - PASSED - {:>9n}μs", msg, dur.count());
log::info("{} - PASSED - {:>9n}μs", msg, dur.count());
return std::nullopt;
} else {
auto exit_msg = fmt::format(res.signal ? "signalled {}" : "exited {}",
res.signal ? res.signal : res.retc);
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;
f.executable_path = exe_path;
f.output = res.output;

+ 0
- 2
src/dds/build/plan/full.cpp 查看文件

@@ -12,8 +12,6 @@
#include <range/v3/view/transform.hpp>
#include <range/v3/view/zip.hpp>

#include <spdlog/spdlog.h>

#include <mutex>
#include <thread>


+ 4
- 5
src/dds/catalog/catalog.cpp 查看文件

@@ -6,6 +6,7 @@
#include <dds/dym.hpp>
#include <dds/error/errors.hpp>
#include <dds/solve/solve.hpp>
#include <dds/util/log.hpp>

#include <json5/parse_data.hpp>
#include <neo/assert.hpp>
@@ -18,8 +19,6 @@
#include <range/v3/view/join.hpp>
#include <range/v3/view/transform.hpp>

#include <spdlog/spdlog.h>

using namespace dds;

namespace sqlite3 = neo::sqlite3;
@@ -218,7 +217,7 @@ void ensure_migrated(sqlite3::database& db) {
exec(db, "UPDATE dds_cat_meta SET meta=?", std::forward_as_tuple(meta.dump()));

if (import_init_packages) {
spdlog::info(
log::info(
"A new catalog database case been created, and has been populated with some initial "
"contents.");
neo::sqlite3::statement_cache stmts{db};
@@ -242,7 +241,7 @@ catalog catalog::open(const std::string& db_path) {
try {
ensure_migrated(db);
} catch (const sqlite3::sqlite3_error& e) {
spdlog::critical(
log::critical(
"Failed to load the repository database. It appears to be invalid/corrupted. The "
"exception message is: {}",
e.what());
@@ -412,6 +411,6 @@ void catalog::import_json_str(std::string_view content) {

void catalog::import_initial() {
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);
}

+ 5
- 5
src/dds/catalog/get.cpp 查看文件

@@ -3,6 +3,7 @@
#include <dds/catalog/catalog.hpp>
#include <dds/error/errors.hpp>
#include <dds/repo/repo.hpp>
#include <dds/util/log.hpp>
#include <dds/util/parallel.hpp>

#include <neo/assert.hpp>
@@ -13,7 +14,6 @@
#include <range/v3/numeric/accumulate.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>

using namespace dds;

@@ -32,16 +32,16 @@ temporary_sdist do_pull_sdist(const package_info& listing, std::monostate) {
temporary_sdist do_pull_sdist(const package_info& listing, const git_remote_listing& git) {
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());

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

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

auto pkg_strm
= dds::open(tmpdir.path() / "package.json5", std::ios::binary | std::ios::out);
@@ -99,7 +99,7 @@ void dds::get_all(const std::vector<package_id>& pkgs, repository& repo, const c
});

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);
std::scoped_lock lk{repo_mut};
repo.add_sdist(tsd.sdist, if_exists::throw_exc);

+ 3
- 3
src/dds/db/database.cpp 查看文件

@@ -1,6 +1,7 @@
#include "./database.hpp"

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

#include <neo/sqlite3/exec.hpp>
#include <neo/sqlite3/iter_tuples.hpp>
@@ -10,7 +11,6 @@
#include <nlohmann/json.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>

using namespace dds;

@@ -87,7 +87,7 @@ database database::open(const std::string& db_path) {
try {
ensure_migrated(db);
} 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 "
"create a new one. The exception message is: {}",
e.what());
@@ -96,7 +96,7 @@ database database::open(const std::string& db_path) {
try {
ensure_migrated(db);
} catch (const sqlite3::sqlite3_error& e) {
spdlog::critical(
log::critical(
"Failed to apply database migrations to recovery database. This is a critical "
"error. The exception message is: {}",
e.what());

+ 0
- 1
src/dds/library/manifest.cpp 查看文件

@@ -7,7 +7,6 @@
#include <json5/parse_data.hpp>
#include <range/v3/view/transform.hpp>
#include <semester/decomp.hpp>
#include <spdlog/spdlog.h>

using namespace dds;


+ 2
- 3
src/dds/library/root.cpp 查看文件

@@ -4,10 +4,10 @@
#include <dds/error/errors.hpp>
#include <dds/source/root.hpp>
#include <dds/util/algo.hpp>
#include <dds/util/log.hpp>

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

using namespace dds;

@@ -28,8 +28,7 @@ auto collect_pf_sources(path_ref path) {
// Drop any source files we found within `include/`
erase_if(sources, [&](auto& info) {
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 false;

+ 2
- 2
src/dds/package/manifest.cpp 查看文件

@@ -2,13 +2,13 @@

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

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

#include <json5/parse_data.hpp>

@@ -63,7 +63,7 @@ package_manifest parse_json(const json5::data& data, std::string_view fpath) {
if_key{"depends",
[&](auto&& dat) {
if (dat.is_object()) {
spdlog::warn(
log::warn(
"{}: Using a JSON object for 'depends' is deprecated. Use an "
"array of strings instead.",
fpath);

+ 3
- 4
src/dds/proc.nix.cpp 查看文件

@@ -1,10 +1,9 @@
#ifndef _WIN32
#include "./proc.hpp"

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

#include <spdlog/spdlog.h>

#include <poll.h>
#include <signal.h>
#include <sys/wait.h>
@@ -63,7 +62,7 @@ spawn_child(const std::vector<std::string>& command, int stdout_pipe, int close_
} // namespace

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] = {};
auto rc = ::pipe(stdio_pipe);
check_rc(rc == 0, "Create stdio pipe for subprocess");
@@ -101,7 +100,7 @@ proc_result dds::run_proc(const proc_options& opts) {
::kill(child, SIGINT);
timeout = -1ms;
res.timed_out = true;
spdlog::debug("Subprocess [{}] timed out", quote_command(opts.command));
log::debug("Subprocess [{}] timed out", quote_command(opts.command));
continue;
}
std::string buffer;

+ 0
- 1
src/dds/proc.win.cpp 查看文件

@@ -2,7 +2,6 @@
#include "./proc.hpp"

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

#include <windows.h>

+ 10
- 11
src/dds/repo/repo.cpp 查看文件

@@ -4,11 +4,10 @@
#include <dds/error/errors.hpp>
#include <dds/solve/solve.hpp>
#include <dds/source/dist.hpp>
#include <dds/util/log.hpp>
#include <dds/util/paths.hpp>
#include <dds/util/string.hpp>

#include <spdlog/spdlog.h>

#include <range/v3/action/sort.hpp>
#include <range/v3/action/unique.hpp>
#include <range/v3/range/conversion.hpp>
@@ -33,9 +32,9 @@ auto load_sdists(path_ref root) {
try {
return sdist::from_directory(p);
} 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;
}
};
@@ -54,8 +53,8 @@ auto load_sdists(path_ref root) {
} // namespace

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); }
@@ -69,7 +68,7 @@ repository repository::_open_for_directory(bool writeable, path_ref dirpath) {

void repository::add_sdist(const sdist& sd, if_exists ife_action) {
if (!_write_enabled) {
spdlog::critical(
log::critical(
"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 "
"repository, we'll hard-exit immediately.");
@@ -82,10 +81,10 @@ void repository::add_sdist(const sdist& sd, if_exists ife_action) {
if (ife_action == if_exists::throw_exc) {
throw_user_error<errc::sdist_exists>(msg);
} else if (ife_action == if_exists::ignore) {
spdlog::warn(msg);
log::warn(msg);
return;
} else {
spdlog::info(msg + " - Replacing");
log::info(msg + " - Replacing");
}
}
auto tmp_copy = sd_dest;
@@ -100,7 +99,7 @@ void repository::add_sdist(const sdist& sd, if_exists ife_action) {
}
fs::rename(tmp_copy, 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 {

+ 5
- 5
src/dds/solve/solve.cpp 查看文件

@@ -1,12 +1,12 @@
#include "./solve.hpp"

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

#include <pubgrub/solve.hpp>

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

#include <sstream>

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

@@ -138,10 +138,10 @@ struct explainer {
at_head = true;
strm.str("");
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
@@ -156,7 +156,7 @@ std::vector<package_id> dds::solve(const std::vector<dependency>& deps,
auto solution = pubgrub::solve(wrap_req, solver_provider{pkgs_prov, deps_prov});
return solution | ranges::views::transform(as_pkg_id) | ranges::to_vector;
} 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());
throw_user_error<errc::dependency_resolve_failure>();
}

+ 5
- 6
src/dds/source/dist.cpp 查看文件

@@ -4,6 +4,7 @@
#include <dds/library/root.hpp>
#include <dds/temp.hpp>
#include <dds/util/fs.hpp>
#include <dds/util/log.hpp>

#include <libman/parse.hpp>

@@ -11,15 +12,13 @@
#include <range/v3/algorithm/sort.hpp>
#include <range/v3/view/filter.hpp>

#include <spdlog/spdlog.h>

using namespace dds;

namespace {

void sdist_export_file(path_ref out_root, path_ref in_root, path_ref filepath) {
auto relpath = fs::relative(filepath, in_root);
spdlog::debug("Export file {}", relpath.string());
log::debug("Export file {}", relpath.string());
auto dest = out_root / relpath;
fs::create_directories(dest.parent_path());
fs::copy(filepath, dest);
@@ -53,7 +52,7 @@ void sdist_copy_library(path_ref out_root, const library_root& lib, const sdist_
}
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);
for (const auto& source : sources_to_keep) {
sdist_export_file(out_root, params.project_dir, source.path);
@@ -78,7 +77,7 @@ sdist dds::create_sdist(const sdist_params& params) {
}
fs::create_directories(dest.parent_path());
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);
}

@@ -99,7 +98,7 @@ sdist dds::create_sdist_in_dir(path_ref out, const sdist_params& params) {

auto pkg_man = package_manifest::load_from_file(*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);
}


+ 33
- 0
src/dds/util/log.cpp 查看文件

@@ -0,0 +1,33 @@
#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 查看文件

@@ -0,0 +1,68 @@
#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 查看文件

@@ -1,6 +1,6 @@
#include "./parallel.hpp"

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

using namespace dds;

@@ -8,6 +8,6 @@ void dds::log_exception(std::exception_ptr eptr) noexcept {
try {
std::rethrow_exception(eptr);
} catch (const std::exception& e) {
spdlog::error(e.what());
log::error(e.what());
}
}

+ 2
- 2
src/dds/util/paths.linux_fbsd.cpp 查看文件

@@ -2,7 +2,7 @@

#include "./paths.hpp"

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

#include <cstdlib>

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

+ 2
- 2
src/dds/util/paths.macos.cpp 查看文件

@@ -2,7 +2,7 @@

#include "./paths.hpp"

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

#include <cstdlib>

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

+ 2
- 2
src/dds/util/paths.win.cpp 查看文件

@@ -2,7 +2,7 @@

#include "./paths.hpp"

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

#include <cstdlib>

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

+ 1
- 1
src/libman/library.cpp 查看文件

@@ -2,7 +2,7 @@

#include <libman/parse.hpp>

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

using namespace lm;


Loading…
取消
儲存