diff --git a/cpp/build-packages.cpp b/cpp/build-packages.cpp index 5980744..358b297 100644 --- a/cpp/build-packages.cpp +++ b/cpp/build-packages.cpp @@ -66,7 +66,7 @@ static std::ofstream log_file_stream; static void log_all(const std::string &msg, bool is_error=false) { if (is_error) { std::cerr << msg; - } else if (verbose) { + } else { std::cout << msg; } if (log_file_stream.is_open()) { @@ -87,6 +87,13 @@ static void log_error(const std::string &msg) { log_all("[ERROR] " + msg + "\n", true); } +// New function for verbose logging +static void log_verbose(const std::string &msg) { + if (verbose) { + log_all("[VERBOSE] " + msg + "\n"); + } +} + static void print_help(const std::string &prog_name) { std::cout << "Usage: " << prog_name << " [OPTIONS] \n" << "Options:\n" @@ -98,7 +105,6 @@ static void print_help(const std::string &prog_name) { << " --help, -h Display this help message.\n"; } -// Adjusted run_command_silent_on_success with conditional logging static void run_command_silent_on_success(const std::vector &cmd, const std::optional &cwd = std::nullopt) { log_info("Running command: " + std::accumulate(cmd.begin(), cmd.end(), std::string(), [](const std::string &a, const std::string &b) -> std::string { return a + (a.empty() ? "" : " ") + b; })); @@ -129,7 +135,7 @@ static void run_command_silent_on_success(const std::vector &cmd, c log_error("Output:\n" + ss.str()); throw std::runtime_error("Command execution failed"); } else { - log_info("Command executed successfully: " + full_cmd); + log_verbose("Command executed successfully: " + full_cmd); } } @@ -278,7 +284,7 @@ static void publish_lintian() { if(ec) { log_error("Failed to copy Lintian file: " + p.path().string() + " to " + dest.string() + ". Error: " + ec.message()); } else { - log_info("Copied Lintian file: " + p.path().string() + " to " + dest.string()); + log_verbose("Copied Lintian file: " + p.path().string() + " to " + dest.string()); } } } @@ -316,7 +322,7 @@ static std::vector get_exclusions(const fs::path &packaging) { std::string token; while(iss>>token) { exclusions.push_back(token); - log_info("Exclusion added: " + token); + log_verbose("Exclusion added: " + token); } } found = true; @@ -330,7 +336,7 @@ static std::vector get_exclusions(const fs::path &packaging) { } int main(int argc, char** argv) { - // Parse command-line arguments + // Parse command-line arguments first to set verbosity std::string prog_name = fs::path(argv[0]).filename().string(); for(int i=1; i&1"; FILE* pipe = popen(cmd.c_str(),"r"); std::stringstream ss; @@ -507,7 +513,7 @@ int main(int argc, char** argv) { } int ret = pclose(pipe); fs::remove(temp_file); - log_info("Lintian command exited with code: " + std::to_string(ret)); + log_verbose("Lintian command exited with code: " + std::to_string(ret)); if(ret!=0) { log_error("Lintian reported issues for " + name + ":\n"+ss.str()); if(!ss.str().empty()) { @@ -528,7 +534,7 @@ int main(int argc, char** argv) { fs::remove(temp_file); log_error("Failed to run Lintian for package: " + name); } - log_info("Completed Lintian run for package: " + name); + log_verbose("Completed Lintian run for package: " + name); }; auto dput_source = [&](const std::string &name, const std::string &upload_target, const std::vector &changes_files, const std::vector &devel_changes_files){ @@ -559,7 +565,13 @@ int main(int argc, char** argv) { auto update_changelog = [&](const fs::path &packaging_dir, const std::string &release, const std::string &version_with_epoch){ std::string name = packaging_dir.filename().string(); log_info("Updating changelog for " + name + " to version " + version_with_epoch + "-0ubuntu1~ppa1"); - run_command_silent_on_success({"git","checkout","debian/changelog"}, packaging_dir); + try { + run_command_silent_on_success({"git","checkout","debian/changelog"}, packaging_dir); + log_verbose("Checked out debian/changelog for " + name); + } catch (const std::exception &e) { + log_error("Failed to checkout debian/changelog for " + name + ": " + e.what()); + throw; + } std::vector cmd={ "dch","--distribution",release,"--package",name,"--newversion",version_with_epoch+"-0ubuntu1~ppa1","--urgency",urgency_level_override,"CI upload." }; @@ -578,7 +590,7 @@ int main(int argc, char** argv) { } else { temp_dir = fs::temp_directory_path()/("tmp_build_"+name+"_"+env_vars.at("VERSION")); fs::create_directories(temp_dir); - log_info("Created temporary build directory: " + temp_dir.string()); + log_verbose("Created temporary build directory: " + temp_dir.string()); } std::error_code ec; @@ -588,14 +600,14 @@ int main(int argc, char** argv) { log_error("Failed to create temporary packaging directory: " + temp_packaging_dir.string()); throw std::runtime_error("Temporary packaging directory creation failed"); } - log_info("Temporary packaging directory created at: " + temp_packaging_dir.string()); + log_verbose("Temporary packaging directory created at: " + temp_packaging_dir.string()); fs::copy(packaging_dir/"debian", temp_packaging_dir/"debian", fs::copy_options::recursive, ec); if(ec) { log_error("Failed to copy debian directory to temporary packaging directory: " + ec.message()); throw std::runtime_error("Failed to copy debian directory"); } - log_info("Copied debian directory to temporary packaging directory."); + log_verbose("Copied debian directory to temporary packaging directory."); std::string tarball_name = name+"_"+env_vars.at("VERSION")+".orig.tar.gz"; fs::path tarball_source = fs::path(BASE_DIR)/(name+"_MAIN.orig.tar.gz"); @@ -605,11 +617,11 @@ int main(int argc, char** argv) { log_error("Failed to copy tarball from " + tarball_source.string() + " to " + tarball_dest.string()); throw std::runtime_error("Failed to copy tarball"); } - log_info("Copied tarball to " + tarball_dest.string()); + log_verbose("Copied tarball to " + tarball_dest.string()); for (auto &e: env_vars) { setenv(e.first.c_str(), e.second.c_str(),1); - log_info("Set environment variable: " + e.first + " = " + e.second); + log_verbose("Set environment variable: " + e.first + " = " + e.second); } std::vector cmd_build={"debuild","--no-lintian","-S","-d","-sa","-nc"}; @@ -625,7 +637,7 @@ int main(int argc, char** argv) { fs::path dest=fs::path(OUTPUT_DIR)/fname; fs::copy_file(entry.path(), dest, fs::copy_options::overwrite_existing, ec); if(!ec) { - log_info("Copied built package " + fname + " to " + OUTPUT_DIR); + log_verbose("Copied built package " + fname + " to " + OUTPUT_DIR); } } } @@ -642,7 +654,7 @@ int main(int argc, char** argv) { if(ec) { log_warning("Failed to remove temporary directory: " + temp_dir.string()); } else { - log_info("Removed temporary build directory: " + temp_dir.string()); + log_verbose("Removed temporary build directory: " + temp_dir.string()); } if(changes_file.empty()) { @@ -693,10 +705,10 @@ int main(int argc, char** argv) { log_error("Failed to copy tarball for " + name + " to " + tarball_dest.string()); continue; } - log_info("Copied tarball to " + tarball_dest.string()); + log_verbose("Copied tarball to " + tarball_dest.string()); std::string version_for_dch = epoch.empty()? release_version_no_epoch : (epoch+":"+release_version_no_epoch); - log_info("Version for dch: " + version_for_dch); + log_verbose("Version for dch: " + version_for_dch); std::map env_map; env_map["DEBFULLNAME"]=DEBFULLNAME; @@ -718,7 +730,7 @@ int main(int argc, char** argv) { if(ec) { log_warning("Failed to remove tarball: " + tarball_dest.string()); } else { - log_info("Removed tarball: " + tarball_dest.string()); + log_verbose("Removed tarball: " + tarball_dest.string()); } }