diff --git a/cmake/MakeJVersionH.cmake b/cmake/MakeJVersionH.cmake index 5737485ef..fcde1c652 100644 --- a/cmake/MakeJVersionH.cmake +++ b/cmake/MakeJVersionH.cmake @@ -15,31 +15,35 @@ set_property( ) execute_process( - COMMAND git log -1 --format=%H 2>/dev/null + COMMAND git log -1 --format=%H WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE JVERSION_GIT_RESULT OUTPUT_VARIABLE JVERSION_COMMIT_HASH + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND git log -1 --format=%aD 2>/dev/null + COMMAND git log -1 --format=%aD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE JVERSION_COMMIT_DATE + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND git show-ref -s v${jana2_VERSION_MAJOR}.${jana2_VERSION_MINOR}.${jana2_VERSION_PATCH} 2>/dev/null + COMMAND git show-ref -s v${jana2_VERSION_MAJOR}.${jana2_VERSION_MINOR}.${jana2_VERSION_PATCH} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE JVERSION_RELEASE_COMMIT_HASH + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) execute_process( - COMMAND git status --porcelain 2>/dev/null + COMMAND git status --porcelain WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} OUTPUT_VARIABLE JVERSION_MODIFIED_FILES + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) diff --git a/src/libraries/JANA/CLI/JMain.cc b/src/libraries/JANA/CLI/JMain.cc index d28085c3a..7ca832b04 100644 --- a/src/libraries/JANA/CLI/JMain.cc +++ b/src/libraries/JANA/CLI/JMain.cc @@ -4,7 +4,6 @@ #include "JMain.h" -#include #include #include @@ -45,15 +44,6 @@ void PrintUsageOptions() { std::cout << " --inspect-component Inspect a component" << std::endl; } -void PrintVersion() { - /// Prints JANA version information to stdout, for use by the CLI. - - std::cout << "JANA2 version: " << JVersion::GetVersion() << std::endl; - if (!JVersion::is_unknown) { - std::cout << "Commit hash: " << JVersion::GetCommitHash() << std::endl; - std::cout << "Commit date: " << JVersion::GetCommitDate() << std::endl; - } -} JApplication* CreateJApplication(UserOptions& options) { @@ -85,13 +75,6 @@ JApplication* CreateJApplication(UserOptions& options) { int Execute(JApplication* app, UserOptions &options) { - std::cout << std::endl; - std::cout << " | \\ \\ | \\ ___ \\ " << std::endl; - std::cout << " | _ \\ \\ | _ \\ ) |" << std::endl; - std::cout << " \\ | ___ \\ |\\ | ___ \\ __/" << std::endl; - std::cout << " \\___/ _/ _\\ _| \\_| _/ _\\ _____|" << std::endl; - std::cout << std::endl; - PrintVersion(); JSignalHandler::register_handlers(app); if (options.flags[ShowConfigs]) { diff --git a/src/libraries/JANA/CMakeLists.txt b/src/libraries/JANA/CMakeLists.txt index 89390b67d..3909bc6c7 100644 --- a/src/libraries/JANA/CMakeLists.txt +++ b/src/libraries/JANA/CMakeLists.txt @@ -23,6 +23,7 @@ set(JANA2_SOURCES JMultifactory.cc JMultifactory.h JService.cc + JVersion.cc Engine/JArrowProcessingController.cc Engine/JArrowProcessingController.h diff --git a/src/libraries/JANA/JApplication.cc b/src/libraries/JANA/JApplication.cc index 4b288dca1..6ac368ee9 100644 --- a/src/libraries/JANA/JApplication.cc +++ b/src/libraries/JANA/JApplication.cc @@ -17,6 +17,7 @@ #include #include +#include #include JApplication *japp = nullptr; @@ -108,6 +109,12 @@ void JApplication::Initialize() { // Only run this once if (m_initialized) return; + std::ostringstream oss; + oss << "Initializing..." << std::endl; + JVersion::PrintSplash(oss); + JVersion::PrintVersionDescription(oss); + LOG_INFO(m_logger) << oss.str() << LOG_END; + // Now that all parameters, components, plugin names, etc have been set, // we can expose our builtin services to the user via GetService() m_services_available = true; diff --git a/src/libraries/JANA/JVersion.cc b/src/libraries/JANA/JVersion.cc new file mode 100644 index 000000000..c5482ef7e --- /dev/null +++ b/src/libraries/JANA/JVersion.cc @@ -0,0 +1,62 @@ +// Copyright 2024, Jefferson Science Associates, LLC. +// Subject to the terms in the LICENSE file found in the top-level directory. +// Author: Nathan Brei + +#include +#include + + +constexpr uint64_t JVersion::GetVersionNumber() { + return 1000000*GetMajorNumber() + 1000*minor + patch; +} + +std::string JVersion::GetVersion() { + std::stringstream ss; + PrintVersionNumbers(ss); + return ss.str(); +} + +void JVersion::PrintVersionNumbers(std::ostream& os) { + os << major << "." << minor << "." << patch; +} + +void JVersion::PrintSplash(std::ostream& os) { + os << std::endl; + os << " | \\ \\ | \\ ___ \\ " << std::endl; + os << " | _ \\ \\ | _ \\ ) |" << std::endl; + os << " \\ | ___ \\ |\\ | ___ \\ __/" << std::endl; + os << " \\___/ _/ _\\ _| \\_| _/ _\\ _____|" << std::endl; + os << std::endl; +} + +void JVersion::PrintVersionDescription(std::ostream& os) { + + os << "JANA2 version: " << JVersion::GetVersion() << " "; + if (is_unknown) { + os << " (unknown git status)"; + } + else if (is_release) { + os << " (release)"; + } + else if (is_modified) { + os << " (uncommitted changes)"; + } + else { + os << " (committed changes)"; + } + os << std::endl; + if (!JVersion::is_unknown) { + os << "Commit hash: " << JVersion::GetCommitHash() << std::endl; + os << "Commit date: " << JVersion::GetCommitDate() << std::endl; + } + os << "Install prefix: " << JVersion::GetInstallDir() << std::endl; + if (JVersion::HasPodio() || JVersion::HasROOT() || JVersion::HasXerces()) { + os << "Optional deps: "; + if (JVersion::HasPodio()) os << "Podio "; + if (JVersion::HasROOT()) os << "ROOT "; + if (JVersion::HasXerces()) os << "Xerces "; + os << std::endl; + } +} + + diff --git a/src/libraries/JANA/JVersion.h.in b/src/libraries/JANA/JVersion.h.in index 8745a8834..454e3a84c 100644 --- a/src/libraries/JANA/JVersion.h.in +++ b/src/libraries/JANA/JVersion.h.in @@ -3,7 +3,8 @@ // Subject to the terms in the LICENSE file found in the top-level directory. #pragma once -#include +#include +#include #define JANA2_HAVE_PODIO @JANA2_HAVE_PODIO@ #define JANA2_HAVE_ROOT @JANA2_HAVE_ROOT@ @@ -12,9 +13,9 @@ struct JVersion { - static const int major = @jana2_VERSION_MAJOR@; - static const int minor = @jana2_VERSION_MINOR@; - static const int patch = @jana2_VERSION_PATCH@; + static const uint64_t major = @jana2_VERSION_MAJOR@; + static const uint64_t minor = @jana2_VERSION_MINOR@; + static const uint64_t patch = @jana2_VERSION_PATCH@; inline static const std::string last_commit_hash = "@JVERSION_COMMIT_HASH@"; inline static const std::string last_commit_date = "@JVERSION_COMMIT_DATE@"; @@ -24,36 +25,25 @@ struct JVersion { static const bool is_release = @JVERSION_RELEASE@; static const bool is_modified = @JVERSION_MODIFIED@; - static unsigned int GetMajorNumber() { return major; } - static unsigned int GetMinorNumber() { return minor; } - static unsigned int GetPatchNumber() { return patch; } + static constexpr uint64_t GetMajorNumber() { return major; } + static constexpr uint64_t GetMinorNumber() { return minor; } + static constexpr uint64_t GetPatchNumber() { return patch; } static std::string GetCommitHash() { return last_commit_hash; } static std::string GetCommitDate() { return last_commit_date; } static std::string GetInstallDir() { return installdir; } - static bool HasPodio() { return JANA2_HAVE_PODIO; } - static bool HasROOT() { return JANA2_HAVE_ROOT; } - static bool HasXerces() { return JANA2_HAVE_XERCES; } - - static std::string GetVersion() { - std::stringstream ss; - ss << major << "." << minor << "." << patch; - if (is_unknown) { - // ss << " (git status unknown)"; - // If .git is not present, degrade gracefully. Don't lead the user to believe that there is an error - } - else if (is_modified) { - ss << " (uncommitted changes)"; - } - else if (is_release) { - ss << " (release)"; - } - else { - ss << " (development)"; - } - return ss.str(); - } + static constexpr bool HasPodio() { return JANA2_HAVE_PODIO; } + static constexpr bool HasROOT() { return JANA2_HAVE_ROOT; } + static constexpr bool HasXerces() { return JANA2_HAVE_XERCES; } + + static std::string GetVersion(); + static constexpr uint64_t GetVersionNumber(); + + static void PrintSplash(std::ostream& os); + static void PrintVersionNumbers(std::ostream& os); + static void PrintVersionDescription(std::ostream& os); + }; diff --git a/src/libraries/JANA/Services/JPluginLoader.cc b/src/libraries/JANA/Services/JPluginLoader.cc index 78c3881b2..70169d0a5 100644 --- a/src/libraries/JANA/Services/JPluginLoader.cc +++ b/src/libraries/JANA/Services/JPluginLoader.cc @@ -6,6 +6,7 @@ #include "JPluginLoader.h" #include "JComponentManager.h" #include "JParameterManager.h" +#include #include #include @@ -55,6 +56,39 @@ void JPluginLoader::add_plugin(std::string plugin_name) { m_plugins_to_include.push_back(plugin_name); } +void JPluginLoader::resolve_plugin_paths() { + // Build our list of plugin search paths. + + // 1. First we look for plugins in the local directory + add_plugin_path("."); + + // 2. Next we look for plugins in locations specified via parameters. (Colon-separated) + std::stringstream param_ss(m_plugin_paths_str); + std::string path; + while (getline(param_ss, path, ':')) add_plugin_path(path); + + // 3. Next we look for plugins in locations specified via environment variable. (Colon-separated) + const char* jpp = getenv("JANA_PLUGIN_PATH"); + if (jpp) { + std::stringstream envvar_ss(jpp); + while (getline(envvar_ss, path, ':')) add_plugin_path(path); + } + + // 4. Next we look in the plugin directories relative to $JANA_HOME + if (const char* jana_home = getenv("JANA_HOME")) { + add_plugin_path(std::string(jana_home) + "/plugins/JANA"); // In case we did a system install and want to avoid conflicts. + add_plugin_path(std::string(jana_home) + "/plugins"); + } + + // 5. Finally we look in the JANA install directory. + // By checking here, the user no longer needs to set JANA_HOME in order to run built-in plugins + // such as janadot and JTest. The install directory is supposed to be the same as JANA_HOME, + // but we can't guarantee that because the user can set JANA_HOME to be anything they want. + // It would be nice if nothing in the JANA codebase itself relied on JANA_HOME, although we + // won't be removing it anytime soon because of build_scripts. + add_plugin_path(JVersion::GetInstallDir() + "/plugins"); +} + void JPluginLoader::add_plugin_path(std::string path) { @@ -84,28 +118,7 @@ void JPluginLoader::attach_plugins(JComponentManager* jcm) { /// Loop over list of plugin names added via AddPlugin() and /// actually attach and initialize them. See AddPlugin method /// for more. - - // Build our list of plugin search paths. - // 1. First we look for plugins in the local directory - add_plugin_path("."); - - // 2. Next we look for plugins in locations specified via parameters. (Colon-separated) - std::stringstream param_ss(m_plugin_paths_str); - std::string path; - while (getline(param_ss, path, ':')) add_plugin_path(path); - - // 3. Next we look for plugins in locations specified via environment variable. (Colon-separated) - const char* jpp = getenv("JANA_PLUGIN_PATH"); - if (jpp) { - std::stringstream envvar_ss(jpp); - while (getline(envvar_ss, path, ':')) add_plugin_path(path); - } - - // 4. Finally we look in the plugin directories relative to $JANA_HOME - if (const char* jana_home = getenv("JANA_HOME")) { - add_plugin_path(std::string(jana_home) + "/plugins/JANA"); // In case we did a system install and want to avoid conflicts. - add_plugin_path(std::string(jana_home) + "/plugins"); - } + resolve_plugin_paths(); // Add plugins specified via PLUGINS configuration parameter // (comma separated list). diff --git a/src/libraries/JANA/Services/JPluginLoader.h b/src/libraries/JANA/Services/JPluginLoader.h index 7078a6206..3f6958a3b 100644 --- a/src/libraries/JANA/Services/JPluginLoader.h +++ b/src/libraries/JANA/Services/JPluginLoader.h @@ -28,6 +28,7 @@ class JPluginLoader : public JService { void add_plugin_path(std::string path); void attach_plugins(JComponentManager* jcm); void attach_plugin(std::string plugin_name); + void resolve_plugin_paths(); private: Service m_params {this}; diff --git a/src/programs/jana/jana.cc b/src/programs/jana/jana.cc index d283b3cfd..2eb65a887 100644 --- a/src/programs/jana/jana.cc +++ b/src/programs/jana/jana.cc @@ -3,6 +3,7 @@ // Subject to the terms in the LICENSE file found in the top-level directory. #include +#include int main(int argc, char* argv[]) { @@ -15,7 +16,7 @@ int main(int argc, char* argv[]) { } if (options.flags[jana::ShowVersion]) { // Show version information and exit immediately - jana::PrintVersion(); + JVersion::PrintVersionDescription(std::cout); return -1; } auto app = jana::CreateJApplication(options);