Skip to content

Commit

Permalink
Adding support for passing command line options through the HPX_COMMA…
Browse files Browse the repository at this point in the history
…NDLINE_OPTIONS environment variable
  • Loading branch information
hkaiser committed Mar 2, 2019
1 parent 4377469 commit 5e637f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/util/command_line_handling.cpp
Expand Up @@ -32,6 +32,7 @@
#include <boost/assign/std/vector.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/tokenizer.hpp>

#include <algorithm>
#include <cstddef>
Expand Down Expand Up @@ -1250,6 +1251,19 @@ namespace hpx { namespace util
return options;
}

///////////////////////////////////////////////////////////////////////////
std::vector<std::string> prepend_options(
std::vector<std::string>&& args, std::string&& options)
{
using tokenizer = boost::tokenizer<boost::escaped_list_separator<char>>;
boost::escaped_list_separator<char> sep('\\', ' ', '\"');
tokenizer tok(options, sep);

std::vector<std::string> result(tok.begin(), tok.end());
std::move(args.begin(), args.end(), std::back_inserter(result));
return result;
}

///////////////////////////////////////////////////////////////////////////
int command_line_handling::call(
boost::program_options::options_description const& desc_cmdline,
Expand All @@ -1274,6 +1288,14 @@ namespace hpx { namespace util
error_mode |= util::rethrow_on_error;
}

// The cfg registry may hold command line options to prepend to the
// real command line.
std::string prepend_command_line =
rtcfg_.get_entry("hpx.commandline.prepend_options");

args =
prepend_options(std::move(args), std::move(prepend_command_line));

// Initial analysis of the command line options. This is
// preliminary as it will not take into account any aliases as
// defined in any of the runtime configuration files.
Expand Down
4 changes: 4 additions & 0 deletions src/util/runtime_configuration.cpp
Expand Up @@ -270,6 +270,10 @@ namespace hpx { namespace util
// allow for unknown options to be passed through
"allow_unknown = ${HPX_COMMANDLINE_ALLOW_UNKNOWN:0}",

// allow for command line options to to be passed through the
// environment
"prepend_options = ${HPX_COMMANDLINE_OPTIONS}",

// predefine command line aliases
"[hpx.commandline.aliases]",
"-a = --hpx:agas",
Expand Down

0 comments on commit 5e637f6

Please sign in to comment.