From 5f318b09b5112bbd90fd5115b0d8ab482919db9b Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Wed, 17 Jul 2024 16:56:26 -0400 Subject: [PATCH 1/6] Plugin loader always searches install directory --- src/libraries/JANA/Services/JPluginLoader.cc | 57 ++++++++++++-------- src/libraries/JANA/Services/JPluginLoader.h | 1 + 2 files changed, 36 insertions(+), 22 deletions(-) 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}; From 850a40deb2a3a3b508e6fa4c682a6434846d510b Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Thu, 18 Jul 2024 14:09:58 -0400 Subject: [PATCH 2/6] Fix stderr suppression when generating JVersion.h --- cmake/MakeJVersionH.cmake | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 ) From ed52406a85033471dbbe592961152fc31aff4a1f Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Thu, 18 Jul 2024 15:45:47 -0400 Subject: [PATCH 3/6] Move version printers into JVersion.cc As discussed in #268 --- src/libraries/JANA/CLI/JMain.cc | 18 ++-------- src/libraries/JANA/CMakeLists.txt | 1 + src/libraries/JANA/JVersion.cc | 58 +++++++++++++++++++++++++++++++ src/libraries/JANA/JVersion.h.in | 25 ++++--------- src/programs/jana/jana.cc | 3 +- 5 files changed, 69 insertions(+), 36 deletions(-) create mode 100644 src/libraries/JANA/JVersion.cc diff --git a/src/libraries/JANA/CLI/JMain.cc b/src/libraries/JANA/CLI/JMain.cc index d28085c3a..a00d0fd6f 100644 --- a/src/libraries/JANA/CLI/JMain.cc +++ b/src/libraries/JANA/CLI/JMain.cc @@ -45,15 +45,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 +76,8 @@ 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(); + JVersion::PrintSplash(std::cout); + JVersion::PrintVersionDescription(std::cout); 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/JVersion.cc b/src/libraries/JANA/JVersion.cc new file mode 100644 index 000000000..f6cae06bc --- /dev/null +++ b/src/libraries/JANA/JVersion.cc @@ -0,0 +1,58 @@ +// 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 + + +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..b14e4b6d2 100644 --- a/src/libraries/JANA/JVersion.h.in +++ b/src/libraries/JANA/JVersion.h.in @@ -3,7 +3,7 @@ // Subject to the terms in the LICENSE file found in the top-level directory. #pragma once -#include +#include #define JANA2_HAVE_PODIO @JANA2_HAVE_PODIO@ #define JANA2_HAVE_ROOT @JANA2_HAVE_ROOT@ @@ -36,24 +36,11 @@ struct JVersion { 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 std::string GetVersion(); + static void PrintSplash(std::ostream& os); + static void PrintVersionNumbers(std::ostream& os); + static void PrintVersionDescription(std::ostream& os); + }; 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); From 85f9c2328169aaa5af87acd3d1ce6cb2edd98c84 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Thu, 18 Jul 2024 16:22:53 -0400 Subject: [PATCH 4/6] Add static constexpr JVersion::GetVersionNumber() This addresses the main complaint in issue #268 --- src/libraries/JANA/JVersion.cc | 4 ++++ src/libraries/JANA/JVersion.h.in | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/libraries/JANA/JVersion.cc b/src/libraries/JANA/JVersion.cc index f6cae06bc..1e4b00d2e 100644 --- a/src/libraries/JANA/JVersion.cc +++ b/src/libraries/JANA/JVersion.cc @@ -6,6 +6,10 @@ #include +constexpr size_t JVersion::GetVersionNumber() { + return 1000000*major + 1000*minor + patch; +} + std::string JVersion::GetVersion() { std::stringstream ss; PrintVersionNumbers(ss); diff --git a/src/libraries/JANA/JVersion.h.in b/src/libraries/JANA/JVersion.h.in index b14e4b6d2..def81464f 100644 --- a/src/libraries/JANA/JVersion.h.in +++ b/src/libraries/JANA/JVersion.h.in @@ -37,6 +37,8 @@ struct JVersion { static bool HasXerces() { return JANA2_HAVE_XERCES; } static std::string GetVersion(); + static constexpr size_t GetVersionNumber(); + static void PrintSplash(std::ostream& os); static void PrintVersionNumbers(std::ostream& os); static void PrintVersionDescription(std::ostream& os); From e7f821b8804430ba440747a05727308df12e7dc6 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Thu, 18 Jul 2024 16:29:29 -0400 Subject: [PATCH 5/6] Make remaining JVersion static getters constexpr --- src/libraries/JANA/JVersion.cc | 14 +++++++------- src/libraries/JANA/JVersion.h.in | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/libraries/JANA/JVersion.cc b/src/libraries/JANA/JVersion.cc index 1e4b00d2e..c5482ef7e 100644 --- a/src/libraries/JANA/JVersion.cc +++ b/src/libraries/JANA/JVersion.cc @@ -6,8 +6,8 @@ #include -constexpr size_t JVersion::GetVersionNumber() { - return 1000000*major + 1000*minor + patch; +constexpr uint64_t JVersion::GetVersionNumber() { + return 1000000*GetMajorNumber() + 1000*minor + patch; } std::string JVersion::GetVersion() { @@ -31,7 +31,7 @@ void JVersion::PrintSplash(std::ostream& os) { void JVersion::PrintVersionDescription(std::ostream& os) { - os << "JANA2 version: " << JVersion::GetVersion() << " "; + os << "JANA2 version: " << JVersion::GetVersion() << " "; if (is_unknown) { os << " (unknown git status)"; } @@ -46,12 +46,12 @@ void JVersion::PrintVersionDescription(std::ostream& os) { } os << std::endl; if (!JVersion::is_unknown) { - os << "Commit hash: " << JVersion::GetCommitHash() << std::endl; - os << "Commit date: " << JVersion::GetCommitDate() << std::endl; + os << "Commit hash: " << JVersion::GetCommitHash() << std::endl; + os << "Commit date: " << JVersion::GetCommitDate() << std::endl; } - os << "Install prefix: " << JVersion::GetInstallDir() << std::endl; + os << "Install prefix: " << JVersion::GetInstallDir() << std::endl; if (JVersion::HasPodio() || JVersion::HasROOT() || JVersion::HasXerces()) { - os << "Optional deps: "; + os << "Optional deps: "; if (JVersion::HasPodio()) os << "Podio "; if (JVersion::HasROOT()) os << "ROOT "; if (JVersion::HasXerces()) os << "Xerces "; diff --git a/src/libraries/JANA/JVersion.h.in b/src/libraries/JANA/JVersion.h.in index def81464f..454e3a84c 100644 --- a/src/libraries/JANA/JVersion.h.in +++ b/src/libraries/JANA/JVersion.h.in @@ -3,6 +3,7 @@ // Subject to the terms in the LICENSE file found in the top-level directory. #pragma once +#include #include #define JANA2_HAVE_PODIO @JANA2_HAVE_PODIO@ @@ -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,20 +25,20 @@ 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 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 size_t GetVersionNumber(); + static constexpr uint64_t GetVersionNumber(); static void PrintSplash(std::ostream& os); static void PrintVersionNumbers(std::ostream& os); From 31ef4f060f0c1d989e05bb7c9fbe25e6b1b8c5c6 Mon Sep 17 00:00:00 2001 From: Nathan Brei Date: Fri, 19 Jul 2024 02:07:10 -0400 Subject: [PATCH 6/6] Call version and splash printers from JApplication::Initialize --- src/libraries/JANA/CLI/JMain.cc | 3 --- src/libraries/JANA/JApplication.cc | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libraries/JANA/CLI/JMain.cc b/src/libraries/JANA/CLI/JMain.cc index a00d0fd6f..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 @@ -76,8 +75,6 @@ JApplication* CreateJApplication(UserOptions& options) { int Execute(JApplication* app, UserOptions &options) { - JVersion::PrintSplash(std::cout); - JVersion::PrintVersionDescription(std::cout); JSignalHandler::register_handlers(app); if (options.flags[ShowConfigs]) { 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;