Skip to content

Commit

Permalink
Merge pull request #49 from BU-Tools/release/v3.0
Browse files Browse the repository at this point in the history
Release/v3.0
  • Loading branch information
dgastler authored Dec 16, 2022
2 parents 5836054 + 5afa732 commit 9ec3a80
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ lib/*
## other outputs
#################################################################################
doc/html
bin
bin
src/BUTool/Version.cc
21 changes: 14 additions & 7 deletions include/BUTool/DeviceFactory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include <vector>
#include <map>

#include "CommandList.hh"
#include <BUTool/CommandList.hh>
#include <BUTool/VersionTracker.hh>


#define RegisterDevice(ClassName,ClassNickName,ClassHelp,CLIFlag,CLIFullFlag,CLIDescription) \
#define RegisterDevice(ClassName,ClassNickName,ClassHelp,CLIFlag,CLIFullFlag,CLIDescription,pluginVersion) \
namespace { \
/*make creator function*/ \
BUTool::CommandListBase * creator_function(std::vector<std::string> args){ \
Expand All @@ -21,13 +21,15 @@
const char CLI_flag[] = CLIFlag; \
const char CLI_full_flag[] = CLIFullFlag; \
const char CLI_description[] = CLIDescription; \
const VersionTracker version = pluginVersion; \
const bool registered = BUTool::DeviceFactory::Instance()->Register(type, \
name, \
&creator_function, \
help, \
CLI_flag, \
CLI_full_flag,\
CLI_description); \
CLI_description,\
version); \
}

namespace BUTool{
Expand All @@ -47,7 +49,9 @@ namespace BUTool{
std::string help,
std::string CLI_flag,
std::string CLI_full_flag,
std::string CLI_description);
std::string CLI_description,
VersionTracker pluginVersion
);
void UnRegister(std::string name);


Expand All @@ -56,6 +60,7 @@ namespace BUTool{
std::string Help(std::string);
bool CLIArgs(std::string const & name,std::string & flag, std::string & full_flag, std::string &description);
bool Exists(std::string name);
VersionTracker GetVersion(std::string name = "BUTOOL" );
private:
//Singleton stuff
//Never implement
Expand All @@ -65,15 +70,17 @@ namespace BUTool{

~DeviceFactory();
static DeviceFactory * pInstance;

static VersionTracker const BUToolVersion;

//List stuff
struct device{
std::string type;
CommandListBase * (*fPtr)(std::vector<std::string>);
std::string help;
std::string CLI_flag;
std::string CLI_full_flag;
std::string CLI_description;
std::string CLI_description;
VersionTracker pluginVersion;
};
std::map<std::string,device> deviceMap;
};
Expand Down
2 changes: 2 additions & 0 deletions include/BUTool/Launcher.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace BUTool{
CommandReturn::status UnSetVariable(std::vector<std::string>,std::vector<uint64_t>);
CommandReturn::status ListVariables(std::vector<std::string>,std::vector<uint64_t>);

CommandReturn::status GetVersion(std::vector<std::string>,std::vector<uint64_t>);

//Add new command (sub command) auto-complete files here
std::string autoComplete_Help(std::vector<std::string> const &,std::string const &,int);
std::string autoComplete_AddDevice(std::vector<std::string> const &,std::string const &,int);
Expand Down
28 changes: 28 additions & 0 deletions include/BUTool/VersionTracker.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef __VERSION_TRACKER_HH__
#define __VERSION_TRACKER_HH__ 1

#include <vector>
#include <string>
#include <stdint.h>
class VersionTracker {
public:
VersionTracker(){
sVersion = "Not Initialized";
repositoryURI = "Not Initialized";
};
VersionTracker(std::vector<uint32_t> nVer,
std::string sVer,
std::string repoURI):
nVersion(nVer),
sVersion(sVer),
repositoryURI(repoURI){
};
std::vector<uint32_t> GetNumericVer(){return nVersion;};
std::string GetHumanVer() {return sVersion;};
std::string GetRepositoryURI(){return repositoryURI;};
private:
std::vector<uint32_t> nVersion;
std::string sVersion;
std::string repositoryURI;
};
#endif
10 changes: 7 additions & 3 deletions mk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
default: build
include mk/helpers.mk
include mk/uhal.mk
include mk/version.mk


BUTOOL_PATH=${MAKE_PATH}
Expand All @@ -20,6 +21,7 @@ LIBRARY_BUTEXTIO_OBJECT_FILES = $(patsubst src/%.cc,obj/%.o,${LIBRARY_BUTEXTIO_S

LIBRARY_TOOL = lib/libBUTool.so
LIBRARY_TOOL_SOURCES = $(wildcard src/BUTool/*.cc)
LIBRARY_TOOL_SOURCES += $(VERSION_FILE)
LIBRARY_TOOL_OBJECT_FILES = $(patsubst src/%.cc,obj/%.o,${LIBRARY_TOOL_SOURCES})

LIBRARY_HELPERS = lib/libBUTool_Helpers.so
Expand Down Expand Up @@ -83,13 +85,14 @@ LINK_LIBRARY_FLAGS = -shared -fPIC -Wall -Wl,--no-as-needed -g -O3 -rdynamic ${L
LINK_EXECUTABLE_FLAGS = -Wall -Wl,--no-as-needed -g -O3 -rdynamic ${LIBRARY_PATH} ${EXECUTABLE_LIBRARIES} -Wl,-rpath=${RUNTIME_LDPATH}/lib ${COMPILETIME_ROOT}

### LINTER checking ###
LINTER?=clang-tidy -extra-arg=-Wno-unknown-warning-option
#LINTER?=clang-tidy
LINTER?=:
#second line sets warnings to errors except for certain things
LINTER_DEFAULT_ARGS=-checks=readability-* --warnings-as-errors=readability-*,-readability-implicit-bool-conversion,-readability-else-after-return,-readability-function-cognitive-complexity,-readability-convert-member-functions-to-static,-clang-diagnostic-unknown-warning-option,-readability-make-member-function-const
LINTER_DEFAULT_ARGS=-extra-arg=-Wno-unknown-warning-option -checks=readability-* --warnings-as-errors=readability-*,-readability-implicit-bool-conversion,-readability-else-after-return,-readability-function-cognitive-complexity,-readability-convert-member-functions-to-static,-clang-diagnostic-unknown-warning-option,-readability-make-member-function-const

.PHONY: all _all clean _cleanall build _buildall self plugin init git_remote_to_ssh git_remote_to_https

clean: _cleanall
clean: _cleanall clean_version
_cleanall:
rm -rf obj
rm -rf bin
Expand Down Expand Up @@ -188,3 +191,4 @@ FLAGS = $(ifeq $(MAKEFLAGS) "","",-$(MAKEFLAGS))

plugin: ${LIBRARY_BUEXCEPTION} ${LIBRARY_BUTEXTIO} ${LIBRARY_HELPERS}
${MAKE} ${FLAGS} -C ${PLUGIN_DIR}

20 changes: 20 additions & 0 deletions mk/version.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GIT_VERSION="$(shell git describe --dirty --always --tags )"
GIT_HASH=$(shell git rev-parse --verify HEAD | awk 'BEGIN{line="";comma=""}{for (i=0;i<length($$0);i+=8){line =line comma " 0x" substr($$0,i,8);comma=","}}END{print line}')
GIT_REPO="$(shell git ls-remote --get-url)"

VERSION_FILE=src/BUTool/Version.cc

define VERSION_BODY
#include <BUTool/DeviceFactory.hh>

VersionTracker const BUTool::DeviceFactory::BUToolVersion = VersionTracker({$(GIT_HASH)},
$(GIT_VERSION),
$(GIT_REPO));
endef
export VERSION_BODY

$(VERSION_FILE):
@echo "$$VERSION_BODY">$(VERSION_FILE)

clean_version:
@rm -f $(VERSION_FILE)
25 changes: 22 additions & 3 deletions src/BUTool/DeviceFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//Singleton
BUTool::DeviceFactory * BUTool::DeviceFactory::DeviceFactory::pInstance = NULL;


static bool CLIArgsValid(std::string const & flag,std::string const & full_flag){
return (!flag.empty() && !full_flag.empty());
}
Expand All @@ -15,7 +14,8 @@ bool BUTool::DeviceFactory::Register(std::string type,
std::string help,
std::string CLI_flag,
std::string CLI_full_flag,
std::string CLI_description){
std::string CLI_description,
VersionTracker pluginVersion){
boost::algorithm::to_upper(name);
std::map<std::string,device>::iterator it = deviceMap.find(name);

Expand All @@ -26,6 +26,7 @@ bool BUTool::DeviceFactory::Register(std::string type,
dev.type = type;
dev.fPtr = fPtr;
dev.help = help;
dev.pluginVersion = pluginVersion;

//Check that our registered flags don't conflict with anyone elses
bool registerCLI = true;
Expand All @@ -51,7 +52,7 @@ bool BUTool::DeviceFactory::Register(std::string type,
dev.CLI_full_flag = CLI_full_flag;
dev.CLI_description = CLI_description;
}

printf("Registered device: %s\n",name.c_str());
}else{
//This name is already registered.
Expand Down Expand Up @@ -149,3 +150,21 @@ bool BUTool::DeviceFactory::CLIArgs(std::string const & name,std::string & flag,
description = it->second.CLI_description;
return true;
}


VersionTracker BUTool::DeviceFactory::GetVersion(std::string name){
boost::algorithm::to_upper(name);
//local BUTool version
if(name == "BUTOOL"){
return BUToolVersion;
}else{
//Plugin version
if(Exists(name)){
return deviceMap[name].pluginVersion;
}
}
BUException::BAD_VALUE e;
e.Append("Bad Version name: ");
e.Append(name);
return VersionTracker({0},"Not configured","Not configured");
}
28 changes: 28 additions & 0 deletions src/BUTool/Launcher_addDevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,31 @@ std::string Launcher::autoComplete_AddDevice(std::vector<std::string> const & li
//not found
return std::string("");
}


CommandReturn::status Launcher::GetVersion(std::vector<std::string> iArg,
std::vector<uint64_t> /*asdf*/){
std::vector<std::string> version;

if(iArg.size() > 0){
version.push_back(iArg[0]);
}else{
//Add the tool version to the list
version.push_back(std::string("BUTOOL"));
//Add all the devices to the list
std::vector<std::string> const pluginList = BUTool::DeviceFactory::Instance()->GetDeviceNames();
version.insert(version.end(),pluginList.begin(),pluginList.end());
}

Print(Level::INFO,"Name Version notes\n");
for(auto itVer = version.begin(); itVer != version.end();itVer++){
VersionTracker pluginVersion = BUTool::DeviceFactory::Instance()->GetVersion(*itVer);
Print(Level::INFO,
"%-13s %-27s %s\n",
itVer->c_str(),
pluginVersion.GetHumanVer().c_str(),
pluginVersion.GetRepositoryURI().c_str()
);
}
return CommandReturn::OK;
}
7 changes: 6 additions & 1 deletion src/BUTool/Launcher_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ void Launcher::LoadCommandList()
"Get a list of internal variable.\n"\
" Usage:\n"\
" list_vars\n");

AddCommand("version",&Launcher::GetVersion,
"Get the version(s) of this software.\n"\
" Usage:\n"\
" version <name>\n");
AddCommandAlias("ver","version");
}

#define MAX_VERBOSITY 9
Expand Down Expand Up @@ -511,3 +515,4 @@ CommandReturn::status Launcher::ListVariables(std::vector<std::string> /*args*/,
}
return CommandReturn::OK;
}

0 comments on commit 9ec3a80

Please sign in to comment.