Skip to content

Commit

Permalink
Adapt the code to use the new 'cli' sub-project.
Browse files Browse the repository at this point in the history
  • Loading branch information
kouchy committed Oct 14, 2019
1 parent 6fd2daf commit 4a1ed40
Show file tree
Hide file tree
Showing 196 changed files with 744 additions and 4,397 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "lib/date"]
path = lib/date
url = https://github.com/HowardHinnant/date.git
[submodule "lib/cli"]
path = lib/cli
url = ../cli
35 changes: 30 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ macro(aff3ct_target_link_libraries privacy lib)
endif(AFF3CT_COMPILE_STATIC_LIB)
endmacro()

macro(aff3ct_target_include_directories privacy dir)
macro(aff3ct_target_include_directories2 privacy dir)
if(AFF3CT_COMPILE_OBJ)
target_include_directories(aff3ct-obj ${privacy} $<BUILD_INTERFACE:${dir}> $<INSTALL_INTERFACE:${dir}>)
endif()
Expand All @@ -414,14 +414,14 @@ if(AFF3CT_SYSTEMC_SIMU OR AFF3CT_SYSTEMC_MODULE)
find_package(SystemC REQUIRED QUIET)
if(SystemC_FOUND)
message(STATUS "AFF3CT - Library found: SystemC")
aff3ct_target_include_directories(PUBLIC "${SystemC_INCLUDE_DIRS}")
aff3ct_target_include_directories2(PUBLIC "${SystemC_INCLUDE_DIRS}")
aff3ct_target_link_libraries(PUBLIC "${SystemC_LIBRARIES}")
endif(SystemC_FOUND)

find_package(TLM REQUIRED QUIET)
if(TLM_FOUND)
message(STATUS "AFF3CT - Library found: TLM")
aff3ct_target_include_directories(PUBLIC "${TLM_INCLUDE_DIRS}")
aff3ct_target_include_directories2(PUBLIC "${TLM_INCLUDE_DIRS}")
endif(TLM_FOUND)
endif()

Expand All @@ -444,7 +444,7 @@ if(AFF3CT_LINK_MKL)
find_package(MKL REQUIRED QUIET)
if(MKL_FOUND)
message(STATUS "AFF3CT - Library found: MKL")
aff3ct_target_include_directories(PUBLIC "${MKL_INCLUDE_DIRS}")
aff3ct_target_include_directories2(PUBLIC "${MKL_INCLUDE_DIRS}")
aff3ct_target_link_libraries(PUBLIC "${MKL_MINIMAL_LIBRARIES}")
endif(MKL_FOUND)
endif(AFF3CT_LINK_MKL)
Expand All @@ -458,7 +458,7 @@ if(AFF3CT_MPI)

message(STATUS "AFF3CT - Library found: MPI")
if(${CMAKE_VERSION} VERSION_LESS "3.9.6")
aff3ct_target_include_directories(PUBLIC "${MPI_CXX_INCLUDE_PATH}")
aff3ct_target_include_directories2(PUBLIC "${MPI_CXX_INCLUDE_PATH}")
aff3ct_target_link_libraries(PUBLIC "${MPI_CXX_LIBRARIES}")

if(MPI_CXX_COMPILE_FLAGS)
Expand All @@ -485,6 +485,23 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
aff3ct_target_link_libraries(PUBLIC Threads::Threads)

# ---------------------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------- SUB-PROJECT
# ---------------------------------------------------------------------------------------------------------------------

# cli
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/cli/src/cli.hpp")
option(CLI_COMPILE_STATIC_LIB "" ON)
option(CLI_STATUS_MESSAGE_QUIET "" ON)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cli/ EXCLUDE_FROM_ALL)
aff3ct_target_include_directories(PUBLIC "lib/cli/src" "cli")
aff3ct_target_link_libraries(PRIVATE cli-static-lib)
message(STATUS "AFF3CT - Sub-project found: cli")
else()
message(FATAL_ERROR "AFF3CT - cli can't be found, try to init the submodule with the following cmd:\n"
"$ git submodule update --init --recursive")
endif()

# ---------------------------------------------------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------------------- EXPORT
# ---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -590,6 +607,14 @@ if (AFF3CT_COMPILE_SHARED_LIB OR AFF3CT_COMPILE_STATIC_LIB)
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aff3ct-${AFF3CT_VERSION_FULL}/rang
COMPONENT headers
FILES_MATCHING PATTERN "*.hpp")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib/cli/src/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aff3ct-${AFF3CT_VERSION_FULL}/cli
COMPONENT headers
FILES_MATCHING PATTERN "*.hpp")
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib/cli/src/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/aff3ct-${AFF3CT_VERSION_FULL}/cli
COMPONENT headers
FILES_MATCHING PATTERN "*.hxx")
endif()

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doc/sphinx/build/latex/AFF3CT.pdf")
Expand Down
2 changes: 1 addition & 1 deletion ci/deploy-sonarqube-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sed -i "s:{{ROOT_DIR}}:$PWD:g" $REPORTS_DIR/scan-build-*/*.plist

# list of standard C++ includes in the system
STD_CXX_INC=$(echo | gcc -xc++ -E -Wp,-v - 2>&1 | grep "^ " | sed -e :a -e '$!N; s/\n/,/; ta')
PROJECT_CXX_INC="./src/, ./lib/date/include/date, ./lib/MIPP/src/, ./lib/MSVC/include/, ./lib/rang/include/"
PROJECT_CXX_INC="./src/, ./lib/date/include/date, ./lib/MIPP/src/, ./lib/MSVC/include/, ./lib/rang/include/, ./lib/cli/src/"
GCC_REGEX='(?<file>.*):(?<line>[0-9]+):[0-9]+:\\x20warning:\\x20(?<message>.*)\\x20\\[(?<id>.*)\\]'

# Create the sonar config file on the fly
Expand Down
1 change: 1 addition & 0 deletions lib/cli
Submodule cli added at a8be0f
6 changes: 3 additions & 3 deletions src/Factory/Command_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using namespace aff3ct;
using namespace factory;

const tools::Argument_tag aff3ct::factory::Command_parser::help_tag = {"help", "h"};
const cli::Argument_tag aff3ct::factory::Command_parser::help_tag = {"help", "h"};

Command_parser
::Command_parser(int argc, char** argv,
Expand All @@ -27,7 +27,7 @@ ::parse(bool add_help_tag)

if (add_help_tag && !args.exist(Command_parser::help_tag))
{
args.add(Command_parser::help_tag, tools::None(), "print this help.");
args.add(Command_parser::help_tag, cli::None(), "print this help.");
}

// parse the argument from the command line
Expand Down Expand Up @@ -66,7 +66,7 @@ ::print_help()
else if (args.exist(Command_parser::help_tag))
{
std::string message = "For more information please display the help (\"";
message += tools::Argument_handler::print_tag(Command_parser::help_tag) += "\").";
message += cli::Argument_handler::print_tag(Command_parser::help_tag) += "\").";

err_stream << rang::tag::info << message << std::endl << std::endl;
}
Expand Down
10 changes: 4 additions & 6 deletions src/Factory/Command_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
#include <iostream>
#include <vector>
#include <string>
#include <cli.hpp>

#include "Tools/Arguments/Argument_handler.hpp"
#include "Tools/Arguments/Maps/Argument_map_info.hpp"
#include "Tools/Arguments/Maps/Argument_tag.hpp"
#include "Factory/Factory.hpp"

namespace aff3ct
Expand All @@ -18,13 +16,13 @@ namespace factory
class Command_parser
{
private:
tools::Argument_handler ahandler;
cli::Argument_handler ahandler;
std::vector<Factory::parameters*> &params;
std::ostream& err_stream;
std::vector<std::string> warnings;
std::vector<std::string> errors;
tools::Argument_map_info args;
static const tools::Argument_tag help_tag;
cli::Argument_map_info args;
static const cli::Argument_tag help_tag;
bool help_asked;

public:
Expand Down
12 changes: 6 additions & 6 deletions src/Factory/Factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,35 @@ ::get_prefixes() const
return p;
}

tools::Argument_map_info Factory
cli::Argument_map_info Factory
::get_description(const std::vector<Factory::parameters*> &params)
{
tools::Argument_map_info args;
cli::Argument_map_info args;

get_description(params, args);

return args;
}

void Factory
::get_description(const std::vector<Factory::parameters*> &params, tools::Argument_map_info &args)
::get_description(const std::vector<Factory::parameters*> &params, cli::Argument_map_info &args)
{
for (auto *p : params)
p->get_description(args);
}

void Factory
::store(std::vector<Factory::parameters*> &params, const tools::Argument_map_value &vals)
::store(std::vector<Factory::parameters*> &params, const cli::Argument_map_value &vals)
{
for (auto *p : params)
p->store(vals);
}

tools::Argument_map_group Factory
cli::Argument_map_group Factory
::create_groups(const std::vector<Factory::parameters*> &params)
{
// create groups of arguments
tools::Argument_map_group grps;
cli::Argument_map_group grps;
for (auto *p : params)
{
auto prefixes = p->get_prefixes ();
Expand Down
15 changes: 7 additions & 8 deletions src/Factory/Factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#include <vector>
#include <string>
#include <map>

#include "Tools/Arguments/Argument_tools.hpp"
#include <cli.hpp>

namespace aff3ct
{
Expand Down Expand Up @@ -54,8 +53,8 @@ struct Factory
virtual std::vector<std::string> get_short_names() const;
virtual std::vector<std::string> get_prefixes () const;

virtual void get_description(tools::Argument_map_info &args) const = 0;
virtual void store (const tools::Argument_map_value &vals ) = 0;
virtual void get_description(cli::Argument_map_info &args) const = 0;
virtual void store (const cli::Argument_map_value &vals ) = 0;
virtual void get_headers (std::map<std::string,header_list>& headers, const bool full = true) const = 0;

private:
Expand All @@ -64,11 +63,11 @@ struct Factory
const std::string prefix;
};

static tools::Argument_map_info get_description(const std::vector<Factory::parameters*> &params);
static void get_description(const std::vector<Factory::parameters*> &params, tools::Argument_map_info &args);
static cli::Argument_map_info get_description(const std::vector<Factory::parameters*> &params);
static void get_description(const std::vector<Factory::parameters*> &params, cli::Argument_map_info &args);

static void store (std::vector<Factory::parameters*> &params, const tools::Argument_map_value &vals);
static tools::Argument_map_group create_groups(const std::vector<Factory::parameters*> &params);
static void store (std::vector<Factory::parameters*> &params, const cli::Argument_map_value &vals);
static cli::Argument_map_group create_groups(const std::vector<Factory::parameters*> &params);
};

struct Header
Expand Down
52 changes: 29 additions & 23 deletions src/Factory/Launcher/Launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <typeindex>
#include <unordered_map>
#include <rang.hpp>
#include <cli.hpp>
#include <date.h>

#include "Tools/general_utils.h"
Expand Down Expand Up @@ -64,71 +65,71 @@ ::clone() const
}

void factory::Launcher::parameters
::get_description(tools::Argument_map_info &args) const
::get_description(cli::Argument_map_info &args) const
{
auto p = this->get_prefix();
const std::string class_name = "factory::Launcher::parameters::";

tools::add_arg(args, p, class_name+"p+cde-type,C",
tools::Text(tools::Including_set("POLAR", "TURBO", "TURBO_DB", "TPC", "LDPC", "REP", "RA", "RSC", "RSC_DB",
"BCH", "UNCODED", "RS")),
tools::arg_rank::REQ);
cli::Text(cli::Including_set("POLAR", "TURBO", "TURBO_DB", "TPC", "LDPC", "REP", "RA", "RSC", "RSC_DB", "BCH",
"UNCODED", "RS")),
cli::arg_rank::REQ);

tools::add_arg(args, p, class_name+"p+type",
#if !defined(AFF3CT_8BIT_PREC) && !defined(AFF3CT_16BIT_PREC)
tools::Text(tools::Including_set("BFER", "BFERI", "EXIT")));
cli::Text(cli::Including_set("BFER", "BFERI", "EXIT")));
#else
tools::Text(tools::Including_set("BFER", "BFERI")));
cli::Text(cli::Including_set("BFER", "BFERI")));
#endif

#ifdef AFF3CT_MULTI_PREC
tools::add_arg(args, p, class_name+"p+prec,p",
tools::Integer(tools::Including_set(8, 16, 32, 64)));
cli::Integer(cli::Including_set(8, 16, 32, 64)));
#endif

tools::add_arg(args, p, class_name+"help,h",
tools::None());
cli::None());

tools::add_arg(args, p, class_name+"Help,H",
tools::None());
cli::None());

tools::add_arg(args, p, class_name+"version,v",
tools::None());
cli::None());

#ifdef AFF3CT_BACKTRACE
tools::add_arg(args, p, class_name+"except-no-bt",
tools::None(),
tools::arg_rank::ADV);
cli::None(),
cli::arg_rank::ADV);
#endif

#ifndef NDEBUG
tools::add_arg(args, p, class_name+"except-a2l",
tools::None(),
tools::arg_rank::ADV);
cli::None(),
cli::arg_rank::ADV);
#endif

tools::add_arg(args, p, class_name+"no-legend",
tools::None(),
tools::arg_rank::ADV);
cli::None(),
cli::arg_rank::ADV);

tools::add_arg(args, p, class_name+"full-legend",
tools::None(),
tools::arg_rank::ADV);
cli::None(),
cli::arg_rank::ADV);

args.add_link({"no-legend"}, {"full-legend"});

#ifdef AFF3CT_COLORS
tools::add_arg(args, p, class_name+"no-colors",
tools::None());
cli::None());
#endif

tools::add_arg(args, p, class_name+"keys,k",
tools::None(),
tools::arg_rank::ADV);
cli::None(),
cli::arg_rank::ADV);
}

void factory::Launcher::parameters
::store(const tools::Argument_map_value &vals)
::store(const cli::Argument_map_value &vals)
{
auto p = this->get_prefix();

Expand Down Expand Up @@ -159,9 +160,14 @@ ::store(const tools::Argument_map_value &vals)
tools::exception::no_addr_to_line = !vals.exist({"except-a2l" });

#ifdef AFF3CT_COLORS
if (vals.exist({"no-colors"})) rang::setControlMode(rang::control::Off);
if (vals.exist({"no-colors"}))
{
rang::setControlMode(rang::control::Off);
cli::disable_colors();
}
#else
rang::setControlMode(rang::control::Off);
cli::disable_colors();
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions src/Factory/Launcher/Launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include <string>
#include <map>
#include <cli.hpp>

#include "Tools/Arguments/Argument_tools.hpp"
#include "Factory/Factory.hpp"

namespace aff3ct
Expand Down Expand Up @@ -46,8 +46,8 @@ struct Launcher : public Factory
virtual Launcher::parameters* clone() const;

// parameters construction
virtual void get_description(tools::Argument_map_info &args) const;
virtual void store (const tools::Argument_map_value &vals);
virtual void get_description(cli::Argument_map_info &args) const;
virtual void store (const cli::Argument_map_value &vals);
virtual void get_headers (std::map<std::string,header_list>& headers, const bool full = true) const;

// builder
Expand Down
Loading

0 comments on commit 4a1ed40

Please sign in to comment.