Skip to content
Permalink
Browse files

Merge branch 'version' into develop

  • Loading branch information...
jbakosi committed Jun 17, 2019
2 parents ec1f9e6 + 7744e08 commit 456c2e258ce4ca8397df2a257333becedbf5d420
@@ -449,6 +449,24 @@ class Print {
}
}

//! Print version information
template< Style s = VERBOSE >
void version( const std::string& executable,
const std::string& ver,
const std::string& commit,
const std::string& copyright ) const
{
stream<s>() << m_version_fmt % executable % ver % commit % copyright;
}

//! Print license information
template< Style s = VERBOSE >
void license( const std::string& executable,
const std::string& lic ) const
{
stream<s>() << m_license_fmt % executable % lic;
}

//! Print lower and upper bounds for a keyword if defined
template< Style s = VERBOSE, typename Info >
void bounds( const Info& info ) const {
@@ -773,6 +791,9 @@ class Print {
mutable format m_item_widename_value_fmt = format("%s%-75s : %s\n");
mutable format m_part_underline_fmt = format(" %|=68|\n");
mutable format m_section_underline_fmt = format("%s%s\n");
mutable format m_version_fmt =
format("\nQuinoa::%s, version %s (SHA1: %s)\n%s\n\n");
mutable format m_license_fmt = format("\nQuinoa::%s\n\n%s\n\n");

// Stream objects
std::stringstream m_null; //!< Default verbose stream
@@ -113,6 +113,12 @@ if (NOT ENABLE_TESTS)
message(STATUS "Tests disabled.")
endif()

# Save contents of license file and copyright info in cmake variables
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE" LICENSE)
string(REGEX REPLACE "All rights reserved\.*" "All rights reserved. See --license for details." COPYRIGHT "${LICENSE}")
string(REGEX REPLACE ";" "\\\\n" COPYRIGHT "${COPYRIGHT}")
string(REGEX REPLACE ";" "\\\\n" LICENSE "${LICENSE}")

# Include third-party libraries configuration
include(TPLs)

@@ -529,7 +535,7 @@ set(EXECUTABLES ${INCITER_EXECUTABLE}
configure_file( "${PROJECT_SOURCE_DIR}/Main/QuinoaConfig.hpp.in"
"${PROJECT_BINARY_DIR}/Main/QuinoaConfig.hpp" )
configure_file( "${PROJECT_SOURCE_DIR}/Main/QuinoaConfig.cpp.in"
"${PROJECT_BINARY_DIR}/Main/QuinoaConfig.cpp" )
"${PROJECT_BINARY_DIR}/Main/QuinoaConfig.cpp" ESCAPE_QUOTES)

# Remove build hostname from cmake cache
unset(HOSTNAME CACHE)
@@ -41,6 +41,8 @@ class CmdLine :
tag::help, bool,
tag::quiescence, bool,
tag::trace, bool,
tag::version, bool,
tag::license, bool,
tag::cmdinfo, tk::ctr::HelpFactory,
tag::ctrinfo, tk::ctr::HelpFactory,
tag::helpkw, tk::ctr::HelpKw,
@@ -56,6 +58,8 @@ class CmdLine :
, kw::output
, kw::quiescence
, kw::trace
, kw::version
, kw::license
>;

//! \brief Constructor: set defaults.
@@ -68,6 +72,8 @@ class CmdLine :
set< tag::verbose >( false ); // Use quiet output by default
set< tag::chare >( false ); // No chare state output by default
set< tag::trace >( true ); // Output call and stack trace by default
set< tag::version >( false ); // Do not display version info by default
set< tag::license >( false ); // Do not display license info by default
// Initialize help: fill from own keywords
brigand::for_each< keywords::set >( tk::ctr::Info(get<tag::cmdinfo>()) );
}
@@ -83,6 +89,8 @@ class CmdLine :
tag::help, bool,
tag::quiescence, bool,
tag::trace, bool,
tag::version, bool,
tag::license, bool,
tag::cmdinfo, tk::ctr::HelpFactory,
tag::ctrinfo, tk::ctr::HelpFactory,
tag::helpkw, tk::ctr::HelpKw,
@@ -70,6 +70,16 @@ namespace cmd {
tk::grm::process_cmd_switch< use, kw::trace,
tag::trace > {};

//! Match switch on version output
struct version :
tk::grm::process_cmd_switch< use, kw::version,
tag::version > {};

//! Match switch on license output
struct license :
tk::grm::process_cmd_switch< use, kw::license,
tag::license > {};

//! \brief Match all command line keywords
struct keywords :
pegtl::sor< verbose,
@@ -78,6 +88,8 @@ namespace cmd {
helpkw,
quiescence,
trace,
version,
license,
io< kw::input, tag::input >,
io< kw::output, tag::output > > {};

@@ -11,19 +11,13 @@
*/
// *****************************************************************************

#include <map>
#include <ostream>
#include <string>
#include <type_traits>

#include "NoWarning/pegtl.hpp"

#include "NoWarning/charm.hpp"

#include "QuinoaConfig.hpp"
#include "Exception.hpp"
#include "Print.hpp"
#include "Keywords.hpp"
#include "HelpFactory.hpp"
#include "FileConv/Types.hpp"
#include "FileConv/CmdLine/Parser.hpp"
#include "FileConv/CmdLine/Grammar.hpp"
@@ -82,12 +76,33 @@ CmdLineParser::CmdLineParser( int argc,
// Print out help on all command-line arguments if the executable was invoked
// without arguments or the help was requested
const auto helpcmd = cmdline.get< tag::help >();
if (argc == 1 || helpcmd)
print.help< tk::QUIET >( tk::fileconv_executable(),
cmdline.get< tag::cmdinfo >(),
"Command-line Parameters:", "-" );

// Print out verbose help for a single keyword if requested
const auto helpkw = cmdline.get< tag::helpkw >();
if (!helpkw.keyword.empty())
print.helpkw< tk::QUIET >( tk::fileconv_executable(), helpkw );

// Print out version information if it was requested
const auto version = cmdline.get< tag::version >();
if (version)
print.version< tk::QUIET >( tk::fileconv_executable(),
tk::quinoa_version(),
tk::git_commit(),
tk::copyright() );

// Print out license information if it was requested
const auto license = cmdline.get< tag::license >();
if (license)
print.license< tk::QUIET >( tk::fileconv_executable(), tk::license() );

// Immediately exit if any help was output or was called without any argument
// with zero exit code
if (argc == 1 || helpcmd || !helpkw.keyword.empty()) CkExit();
// or version or license info was requested with zero exit code
if (argc == 1 || helpcmd || !helpkw.keyword.empty() || version || license)
CkExit();

// Make sure mandatory arguments are set
auto ialias = kw::input().alias();
@@ -44,6 +44,8 @@ class CmdLine : public tk::Control<
tag::helpctr, bool,
tag::quiescence, bool,
tag::trace, bool,
tag::version, bool,
tag::license, bool,
tag::cmdinfo, tk::ctr::HelpFactory,
tag::ctrinfo, tk::ctr::HelpFactory,
tag::helpkw, tk::ctr::HelpKw,
@@ -69,6 +71,8 @@ class CmdLine : public tk::Control<
, kw::quiescence
, kw::lbfreq
, kw::trace
, kw::version
, kw::license
>;

//! \brief Constructor: set all defaults.
@@ -114,6 +118,8 @@ class CmdLine : public tk::Control<
set< tag::feedback >( false ); // No detailed feedback by default
set< tag::lbfreq >( 1 ); // Load balancing every time-step by default
set< tag::trace >( true ); // Output call and stack trace by default
set< tag::version >( false ); // Do not display version info by default
set< tag::license >( false ); // Do not display license info by default
// Initialize help: fill from own keywords + add map passed in
brigand::for_each< keywords::set >( tk::ctr::Info(get<tag::cmdinfo>()) );
get< tag::ctrinfo >() = std::move( ctrinfo );
@@ -135,6 +141,8 @@ class CmdLine : public tk::Control<
tag::helpctr, bool,
tag::quiescence, bool,
tag::trace, bool,
tag::version, bool,
tag::license, bool,
tag::cmdinfo, tk::ctr::HelpFactory,
tag::ctrinfo, tk::ctr::HelpFactory,
tag::helpkw, tk::ctr::HelpKw,
@@ -105,6 +105,16 @@ namespace cmd {
tk::grm::process_cmd_switch< use, kw::trace,
tag::trace > {};

//! Match switch on version output
struct version :
tk::grm::process_cmd_switch< use, kw::version,
tag::version > {};

//! Match switch on license output
struct license :
tk::grm::process_cmd_switch< use, kw::license,
tag::license > {};

//! Match all command line keywords
struct keywords :
pegtl::sor< verbose,
@@ -119,6 +129,8 @@ namespace cmd {
quiescence,
lbfreq,
trace,
version,
license,
io< kw::control, tag::control >,
io< kw::input, tag::input >,
io< kw::output, tag::output >,
@@ -11,17 +11,12 @@
*/
// *****************************************************************************

#include <map>
#include <ostream>
#include <type_traits>

#include "NoWarning/pegtl.hpp"
#include "NoWarning/charm.hpp"

#include "Print.hpp"
#include "QuinoaConfig.hpp"
#include "Exception.hpp"
#include "HelpFactory.hpp"
#include "Print.hpp"
#include "Keywords.hpp"
#include "Inciter/Types.hpp"
#include "Inciter/CmdLine/Parser.hpp"
@@ -105,9 +100,26 @@ CmdLineParser::CmdLineParser( int argc, char** argv,
if (!helpkw.keyword.empty())
print.helpkw< tk::QUIET >( tk::inciter_executable(), helpkw );

// Print out version information if it was requested
const auto version = cmdline.get< tag::version >();
if (version)
print.version< tk::QUIET >( tk::inciter_executable(),
tk::quinoa_version(),
tk::git_commit(),
tk::copyright() );

// Print out license information if it was requested
const auto license = cmdline.get< tag::license >();
if (license)
print.license< tk::QUIET >( tk::inciter_executable(), tk::license() );

// Immediately exit if any help was output or was called without any argument
// with zero exit code
if (argc == 1 || helpcmd || helpctr || !helpkw.keyword.empty()) CkExit();
// or version or license info was requested with zero exit code
if (argc == 1 || helpcmd || helpctr || !helpkw.keyword.empty() || version ||
license)
{
CkExit();
}

// Make sure mandatory arguments are set
auto ctralias = kw::control().alias();
@@ -3500,9 +3500,30 @@ struct feedback_info {
}
using alias = Alias< f >;
};

using feedback = keyword< feedback_info, TAOCPP_PEGTL_STRING("feedback") >;

struct version_info {
static std::string name() { return "Show version"; }
static std::string shortDescription() { return "Show version information"; }
static std::string longDescription() { return
R"(This keyword is used to display version information for the
executable/tool on the standard output and exit successfully.)";
}
using alias = Alias< V >;
};
using version = keyword< version_info, TAOCPP_PEGTL_STRING("version") >;

struct license_info {
static std::string name() { return "Show license"; }
static std::string shortDescription() { return "Show license information"; }
static std::string longDescription() { return
R"(This keyword is used to display license information for the
executable/tool on the standard output and exit successfully.)";
}
using alias = Alias< L >;
};
using license = keyword< license_info, TAOCPP_PEGTL_STRING("license") >;

struct trace_info {
static std::string name() { return "trace"; }
static std::string shortDescription()
@@ -3514,7 +3535,6 @@ struct trace_info {
option.)"; }
using alias = Alias< t >;
};

using trace = keyword< trace_info, TAOCPP_PEGTL_STRING("trace") >;

struct quiescence_info {
@@ -3529,7 +3549,6 @@ struct quiescence_info {
}
using alias = Alias< q >;
};

using quiescence =
keyword< quiescence_info, TAOCPP_PEGTL_STRING("quiescence") >;

@@ -42,6 +42,8 @@ class CmdLine :
tag::help, bool,
tag::quiescence, bool,
tag::trace, bool,
tag::version, bool,
tag::license, bool,
tag::cmdinfo, tk::ctr::HelpFactory,
tag::ctrinfo, tk::ctr::HelpFactory,
tag::helpkw, tk::ctr::HelpKw,
@@ -59,6 +61,8 @@ class CmdLine :
, kw::reorder
, kw::quiescence
, kw::trace
, kw::version
, kw::license
>;

//! \brief Constructor: set defaults.
@@ -72,6 +76,8 @@ class CmdLine :
set< tag::chare >( false ); // No chare state output by default
set< tag::reorder >( false ); // Do not reorder by default
set< tag::trace >( true ); // Output call and stack trace by default
set< tag::version >( false ); // Do not display version info by default
set< tag::license >( false ); // Do not display license info by default
// Initialize help: fill from own keywords
brigand::for_each< keywords::set >( tk::ctr::Info(get<tag::cmdinfo>()) );
}
@@ -88,6 +94,8 @@ class CmdLine :
tag::help, bool,
tag::quiescence, bool,
tag::trace, bool,
tag::version, bool,
tag::license, bool,
tag::cmdinfo, tk::ctr::HelpFactory,
tag::ctrinfo, tk::ctr::HelpFactory,
tag::helpkw, tk::ctr::HelpKw,

0 comments on commit 456c2e2

Please sign in to comment.
You can’t perform that action at this time.