Skip to content

Commit

Permalink
Improve debug outputs (#904)
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui authored Feb 2, 2024
1 parent 50d4531 commit 878532e
Show file tree
Hide file tree
Showing 22 changed files with 222 additions and 168 deletions.
13 changes: 7 additions & 6 deletions poac.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ lto = true

[lint.cpplint]
filters = [
"-legal/copyright",
"-whitespace",
"+whitespace/ending_newline",
"-build/c++11",
"-readability/nolint", # Unknown NOLINT error category: bugprone-branch-clone # This is for clang-tidy
"-runtime/references", # non-const reference rather than a pointer
"-readability/braces", # prioritize clang-format
"-build/include_order", # prioritize clang-format
"-build/include_subdir",
"-legal/copyright",
"-readability/braces", # prioritize clang-format
"-readability/nolint", # handle NOLINT comments for clang-tidy
"-readability/todo",
"-runtime/indentation_namespace", # inner namespace should be indented
"-runtime/references", # non-const reference rather than a pointer
"-whitespace",
"+whitespace/ending_newline",
]
4 changes: 2 additions & 2 deletions src/Algos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ toMacroName(StringRef name) noexcept {

int
execCmd(const StringRef cmd) noexcept {
Logger::debug("Running `", cmd, '`');
logger::debug("Running `", cmd, '`');
const int status = std::system(cmd.data());
const int exitCode = status >> 8;
return exitCode;
Expand Down Expand Up @@ -67,7 +67,7 @@ getCmdOutputImpl(const StringRef cmd) {

String
getCmdOutput(const StringRef cmd, const usize retry) {
Logger::debug("Running `", cmd, '`');
logger::debug("Running `", cmd, '`');

int exitCode = EXIT_SUCCESS;
for (usize i = 0; i < retry; ++i) {
Expand Down
18 changes: 9 additions & 9 deletions src/BuildConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ containsTestCode(const String& sourceFile) {
// file.
const bool containsTest = src != testSrc;
if (containsTest) {
Logger::debug("Found test code: ", sourceFile);
logger::debug("Found test code: ", sourceFile);
}
return containsTest;
}
Expand All @@ -436,7 +436,7 @@ containsTestCode(const String& sourceFile) {
static String
printfCmd(const StringRef header, const StringRef body) {
std::ostringstream oss;
Logger::info(oss, header, body);
logger::info(oss, header, body);
String msg = oss.str();

// Replace all occurrences of '\n' with "\\n" to escape newlines
Expand Down Expand Up @@ -548,8 +548,8 @@ installDeps() {
INCLUDES += ' ' + dep.includes;
LIBS += ' ' + dep.libs;
}
Logger::debug("INCLUDES: ", INCLUDES);
Logger::debug("LIBS: ", LIBS);
logger::debug("INCLUDES: ", INCLUDES);
logger::debug("LIBS: ", LIBS);
}

static void
Expand Down Expand Up @@ -593,7 +593,7 @@ setVariables(BuildConfig& config, const bool isDebug) {
commitShortHash = commitHash.substr(0, git2::SHORT_HASH_LEN);
commitDate = git2::Commit().lookup(repo, oid).time().toString();
} catch (const git2::Exception& e) {
Logger::debug("No git repository found");
logger::debug("No git repository found");
}

// Variables Poac sets for the user.
Expand Down Expand Up @@ -824,10 +824,10 @@ emitMakefile(const bool isDebug) {
const String outDir = getOutDir();
const String makefilePath = outDir + "/Makefile";
if (isUpToDate(makefilePath)) {
Logger::debug("Makefile is up to date");
logger::debug("Makefile is up to date");
return outDir;
}
Logger::debug("Makefile is NOT up to date");
logger::debug("Makefile is NOT up to date");

const BuildConfig config = configureBuild(isDebug);
std::ofstream ofs(makefilePath);
Expand All @@ -846,10 +846,10 @@ emitCompdb(const bool isDebug) {
const String outDir = getOutDir();
const String compdbPath = outDir + "/compile_commands.json";
if (isUpToDate(compdbPath)) {
Logger::debug("compile_commands.json is up to date");
logger::debug("compile_commands.json is up to date");
return outDir;
}
Logger::debug("compile_commands.json is NOT up to date");
logger::debug("compile_commands.json is NOT up to date");

const BuildConfig config = configureBuild(isDebug);
std::ofstream ofs(compdbPath);
Expand Down
4 changes: 2 additions & 2 deletions src/Cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Subcmd::noSuchArg(StringRef arg) const {
suggestion = bold(cyan(" Tip:")) + " did you mean '"
+ bold(yellow(similar.value())) + "'?\n\n";
}
Logger::error(
logger::error(
"unexpected argument '", bold(yellow(arg)), "' found\n\n", suggestion,
getUsage(), "\n\n", "For more information, try '", bold(cyan("--help")),
'\''
Expand Down Expand Up @@ -321,7 +321,7 @@ Command::noSuchArg(StringRef arg) const {
suggestion = bold(cyan(" Tip:")) + " did you mean '"
+ bold(yellow(similar.value())) + "'?\n\n";
}
Logger::error(
logger::error(
"unexpected argument '", bold(yellow(arg)), "' found\n\n", suggestion,
"For a list of commands, try '", bold(cyan("poac help")), '\''
);
Expand Down
6 changes: 3 additions & 3 deletions src/Cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
if (arg == "-h" || arg == "--help") { \
return getCmd().printHelp(HELP_ARGS); \
} else if (arg == "-v" || arg == "--verbose") { \
Logger::setLevel(LogLevel::Debug); \
logger::setLevel(logger::Level::Debug); \
} else if (arg == "-q" || arg == "--quiet") { \
Logger::setLevel(LogLevel::Off); \
logger::setLevel(logger::Level::Off); \
} else if (arg == "--color") { \
if (i + 1 < args.size()) { \
setColorMode(args[++i]); \
} else { \
Logger::error("missing argument for `--color`"); \
logger::error("missing argument for `--color`"); \
return EXIT_FAILURE; \
} \
}
Expand Down
4 changes: 2 additions & 2 deletions src/Cmd/Build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ buildImpl(String& outDir, const bool isDebug) {
const std::chrono::duration<double> elapsed = end - start;

if (exitCode == EXIT_SUCCESS) {
Logger::info(
logger::info(
"Finished", modeString(isDebug), " target(s) in ", elapsed.count(), "s"
);
}
Expand Down Expand Up @@ -79,6 +79,6 @@ buildMain(const std::span<const StringRef> args) {

// Build compilation database
const String outDir = emitCompdb(isDebug);
Logger::info("Generated", outDir, "/compile_commands.json");
logger::info("Generated", outDir, "/compile_commands.json");
return EXIT_SUCCESS;
}
6 changes: 3 additions & 3 deletions src/Cmd/Clean.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ cleanMain(const std::span<const StringRef> args) noexcept {

else if (arg == "-p" || arg == "--profile") {
if (i + 1 >= args.size()) {
Logger::error("Missing argument for ", arg);
logger::error("Missing argument for ", arg);
return EXIT_FAILURE;
}

++i;

if (!(args[i] == "debug" || args[i] == "release")) {
Logger::error("Invalid argument for ", arg, ": ", args[i]);
logger::error("Invalid argument for ", arg, ": ", args[i]);
return EXIT_FAILURE;
}

Expand All @@ -48,7 +48,7 @@ cleanMain(const std::span<const StringRef> args) noexcept {
}

if (fs::exists(outDir)) {
Logger::info("Removing", fs::canonical(outDir).string());
logger::info("Removing", fs::canonical(outDir).string());
fs::remove_all(outDir);
}
return EXIT_SUCCESS;
Expand Down
10 changes: 5 additions & 5 deletions src/Cmd/Fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ collectFormatTargetFiles(const Path& manifestDir, String& clangFormatArgs) {
repo.open(manifestDir.string());
hasGitRepo = true;
} catch (const git2::Exception& e) {
Logger::debug("No git repository found");
logger::debug("No git repository found");
}

// Automatically collects format-target files
Expand All @@ -40,14 +40,14 @@ collectFormatTargetFiles(const Path& manifestDir, String& clangFormatArgs) {
if (entry->is_directory()) {
const String path = fs::relative(entry->path(), manifestDir).string();
if (hasGitRepo && repo.isIgnored(path)) {
Logger::debug("Ignore: ", path);
logger::debug("Ignore: ", path);
entry.disable_recursion_pending();
continue;
}
} else if (entry->is_regular_file()) {
const Path path = fs::relative(entry->path(), manifestDir);
if (hasGitRepo && repo.isIgnored(path.string())) {
Logger::debug("Ignore: ", path.string());
logger::debug("Ignore: ", path.string());
continue;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ fmtMain(const std::span<const StringRef> args) {
}

if (!commandExists("clang-format")) {
Logger::error(
logger::error(
"fmt command requires clang-format; try installing it by:\n"
" apt/brew install clang-format"
);
Expand All @@ -92,7 +92,7 @@ fmtMain(const std::span<const StringRef> args) {
clangFormatArgs += " --dry-run";
} else {
clangFormatArgs += " -i";
Logger::info("Formatting", packageName);
logger::info("Formatting", packageName);
}

const Path& manifestDir = getManifestPath().parent_path();
Expand Down
6 changes: 3 additions & 3 deletions src/Cmd/Init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ initMain(const std::span<const StringRef> args) {
}

if (fs::exists("poac.toml")) {
Logger::error("cannot initialize an existing poac package");
logger::error("cannot initialize an existing poac package");
return EXIT_FAILURE;
}

const String packageName = fs::current_path().stem().string();
if (const auto err = validatePackageName(packageName)) {
Logger::error("package names ", err.value(), ": `", packageName, '`');
logger::error("package names ", err.value(), ": `", packageName, '`');
return EXIT_FAILURE;
}

std::ofstream ofs("poac.toml");
ofs << createPoacToml(packageName);

Logger::info(
logger::info(
"Created", isBin ? "binary (application) `" : "library `", packageName,
"` package"
);
Expand Down
12 changes: 6 additions & 6 deletions src/Cmd/Lint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct LintArgs {

static int
lint(const StringRef name, const StringRef cpplintArgs) {
Logger::info("Linting", name);
logger::info("Linting", name);

String cpplintCmd = "cpplint";
cpplintCmd += cpplintArgs;
Expand Down Expand Up @@ -59,7 +59,7 @@ lintMain(const std::span<const StringRef> args) {

else if (arg == "--exclude") {
if (i + 1 >= args.size()) {
Logger::error("Missing argument for ", arg);
logger::error("Missing argument for ", arg);
return EXIT_FAILURE;
}

Expand All @@ -73,7 +73,7 @@ lintMain(const std::span<const StringRef> args) {
}

if (!commandExists("cpplint")) {
Logger::error(
logger::error(
"lint command requires cpplint; try installing it by:\n"
" pip install cpplint"
);
Expand All @@ -83,7 +83,7 @@ lintMain(const std::span<const StringRef> args) {
String cpplintArgs = lintArgs.excludes;
const String& packageName = getPackageName();
if (fs::exists("CPPLINT.cfg")) {
Logger::debug("Using CPPLINT.cfg for lint ...");
logger::debug("Using CPPLINT.cfg for lint ...");
return lint(packageName, cpplintArgs);
}

Expand All @@ -95,7 +95,7 @@ lintMain(const std::span<const StringRef> args) {

const Vec<String>& cpplintFilters = getLintCpplintFilters();
if (!cpplintFilters.empty()) {
Logger::debug("Using Poac manifest file for lint ...");
logger::debug("Using Poac manifest file for lint ...");
cpplintArgs += " --filter=";
for (const StringRef filter : cpplintFilters) {
cpplintArgs += filter;
Expand All @@ -105,7 +105,7 @@ lintMain(const std::span<const StringRef> args) {
cpplintArgs.pop_back();
return lint(packageName, cpplintArgs);
} else {
Logger::debug("Using default arguments for lint ...");
logger::debug("Using default arguments for lint ...");
if (Edition::Cpp11 < getPackageEdition()) {
// Disable C++11-related lints
cpplintArgs += " --filter=-build/c++11";
Expand Down
10 changes: 5 additions & 5 deletions src/Cmd/New.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ getAuthor() noexcept {
return config.getString("user.name") + " <" + config.getString("user.email")
+ ">";
} catch (const git2::Exception& e) {
Logger::debug(e.what());
logger::debug(e.what());
return "";
}
}
Expand Down Expand Up @@ -104,7 +104,7 @@ createTemplateFiles(const bool isBin, const StringRef projectName) {
writeToFile(ofs, projectName / ".gitignore"_path, "/poac-out");
writeToFile(ofs, projectName / "src"_path / "main.cc", MAIN_CC);

Logger::info("Created", "binary (application) `", projectName, "` package");
logger::info("Created", "binary (application) `", projectName, "` package");
} else {
fs::create_directories(projectName / "include"_path / projectName);
writeToFile(
Expand All @@ -118,7 +118,7 @@ createTemplateFiles(const bool isBin, const StringRef projectName) {
getHeader(projectName)
);

Logger::info("Created", "library `", projectName, "` package");
logger::info("Created", "library `", projectName, "` package");
}
}

Expand Down Expand Up @@ -146,12 +146,12 @@ newMain(const std::span<const StringRef> args) {
}

if (const auto err = validatePackageName(packageName)) {
Logger::error("package names ", err.value(), ": `", packageName, '`');
logger::error("package names ", err.value(), ": `", packageName, '`');
return EXIT_FAILURE;
}

if (fs::exists(packageName)) {
Logger::error("directory `", packageName, "` already exists");
logger::error("directory `", packageName, "` already exists");
return EXIT_FAILURE;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Cmd/Search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ searchPackages(const SearchArgs& args) {

CURL* curl = curl_easy_init();
if (!curl) {
Logger::error("curl_easy_init() failed");
logger::error("curl_easy_init() failed");
return EXIT_FAILURE;
}

Expand Down Expand Up @@ -104,15 +104,15 @@ searchMain(const std::span<const StringRef> args) {
if (i + 1 < args.size()) {
searchArgs.perPage = std::stoul(String(args[++i]));
} else {
Logger::error("missing argument for `--per-page`");
logger::error("missing argument for `--per-page`");
return EXIT_FAILURE;
}
}
else if (arg == "--page") {
if (i + 1 < args.size()) {
searchArgs.page = std::stoul(String(args[++i]));
} else {
Logger::error("missing argument for `--page`");
logger::error("missing argument for `--page`");
return EXIT_FAILURE;
}
}
Expand All @@ -125,13 +125,13 @@ searchMain(const std::span<const StringRef> args) {
}

if (searchArgs.name.empty()) {
Logger::error("missing package name");
logger::error("missing package name");
return EXIT_FAILURE;
}

const nlohmann::json packages = searchPackages(searchArgs);
if (packages.empty()) {
Logger::warn("no packages found");
logger::warn("no packages found");
return EXIT_SUCCESS;
}

Expand Down
Loading

0 comments on commit 878532e

Please sign in to comment.