Skip to content

Commit

Permalink
Merge pull request #320 from JeffersonLab/nbrei_jversion_improvements
Browse files Browse the repository at this point in the history
Improvements to JVersion
  • Loading branch information
nathanwbrei authored Jul 19, 2024
2 parents ed591e1 + 31ef4f0 commit c7be03a
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 73 deletions.
12 changes: 8 additions & 4 deletions cmake/MakeJVersionH.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
17 changes: 0 additions & 17 deletions src/libraries/JANA/CLI/JMain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "JMain.h"

#include <JANA/JVersion.h>
#include <JANA/CLI/JBenchmarker.h>
#include <JANA/CLI/JSignalHandler.h>

Expand Down Expand Up @@ -45,15 +44,6 @@ void PrintUsageOptions() {
std::cout << " --inspect-component <name> 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) {

Expand Down Expand Up @@ -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]) {
Expand Down
1 change: 1 addition & 0 deletions src/libraries/JANA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(JANA2_SOURCES
JMultifactory.cc
JMultifactory.h
JService.cc
JVersion.cc

Engine/JArrowProcessingController.cc
Engine/JArrowProcessingController.h
Expand Down
7 changes: 7 additions & 0 deletions src/libraries/JANA/JApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <JANA/Engine/JArrowProcessingController.h>
#include <JANA/Utils/JApplicationInspector.h>

#include <sstream>
#include <unistd.h>

JApplication *japp = nullptr;
Expand Down Expand Up @@ -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;
Expand Down
62 changes: 62 additions & 0 deletions src/libraries/JANA/JVersion.cc
Original file line number Diff line number Diff line change
@@ -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 <JANA/JVersion.h>
#include <sstream>


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


48 changes: 19 additions & 29 deletions src/libraries/JANA/JVersion.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Subject to the terms in the LICENSE file found in the top-level directory.

#pragma once
#include <sstream>
#include <cstdint>
#include <ostream>

#define JANA2_HAVE_PODIO @JANA2_HAVE_PODIO@
#define JANA2_HAVE_ROOT @JANA2_HAVE_ROOT@
Expand All @@ -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@";
Expand All @@ -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);

};


Expand Down
57 changes: 35 additions & 22 deletions src/libraries/JANA/Services/JPluginLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "JPluginLoader.h"
#include "JComponentManager.h"
#include "JParameterManager.h"
#include <JANA/JVersion.h>

#include <dlfcn.h>
#include <iostream>
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions src/libraries/JANA/Services/JPluginLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<JParameterManager> m_params {this};
Expand Down
3 changes: 2 additions & 1 deletion src/programs/jana/jana.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Subject to the terms in the LICENSE file found in the top-level directory.

#include <JANA/CLI/JMain.h>
#include <JANA/JVersion.h>

int main(int argc, char* argv[]) {

Expand All @@ -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);
Expand Down

0 comments on commit c7be03a

Please sign in to comment.