Skip to content

Commit

Permalink
Add a --show-copyable-inputs CLI flag
Browse files Browse the repository at this point in the history
The --show-copyable-inputs flag shows a list of installable directories
to end users in case there are several or the lists are complicated.

Also applied some drive-by const-correctness in a few related methods.

refs idaholab#19022
  • Loading branch information
permcody committed Apr 4, 2022
1 parent 21be14e commit ce067fe
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 23 deletions.
19 changes: 15 additions & 4 deletions framework/include/base/MooseApp.h
Expand Up @@ -1215,20 +1215,31 @@ class MooseApp : public ConsoleStreamInterface,
*/
PerfGraph & createRecoverablePerfGraph();

/**
* Prints a message showing the installable inputs for a given application (if
* getInstallableInputs has been overridden for an application).
*/
bool showInputs() const;

/**
* Method to retrieve the installable inputs from a given applications <app>Revision.h file.
*/
virtual std::string getInstallableInputs() const;

/**
* Handles the copy_inputs input parameter logic: Checks to see whether the passed argument is
* valid (a readable installed directory) and recursively copies those files into a read/writable
* location for the user.
* valid (a readable installed directory) and recursively copies those files into a
* read/writable location for the user.
* @return a Boolean value used to indicate whether the application should exit early
*/
bool copyInputs();
bool copyInputs() const;

/**
* Handles the run input parameter logic: Checks to see whether a directory exists in user space
* and launches the TestHarness to process the given directory.
* @return a Boolean value used to indicate whether the application should exit early
*/
bool runInputs();
bool runInputs() const;

/// General storage for custom RestartableData that can be added to from outside applications
std::unordered_map<RestartableDataMapName, std::pair<RestartableDataMap, std::string>>
Expand Down
5 changes: 5 additions & 0 deletions framework/include/parser/CommandLine.h
Expand Up @@ -104,6 +104,11 @@ class CommandLine
// Return an iterator to the beginning of the container of CLI options
std::vector<std::string>::const_iterator end() const;

/**
* Get the executable name.
*/
std::string getExecutableName() const;

/**
* Print the usage info for this command line
*/
Expand Down
4 changes: 2 additions & 2 deletions framework/include/utils/InputParameters.h
Expand Up @@ -264,12 +264,12 @@ class InputParameters : public Parameters
/**
* Get the syntax for a command-line parameter
*/
std::vector<std::string> getSyntax(const std::string & name);
std::vector<std::string> getSyntax(const std::string & name) const;

/**
* Get the documentation string for a parameter
*/
const std::string & getDescription(const std::string & name);
const std::string & getDescription(const std::string & name) const;

/**
* This method takes a space delimited list of parameter names and adds them to the specified
Expand Down
4 changes: 3 additions & 1 deletion framework/include/utils/MooseUtils.h
Expand Up @@ -98,7 +98,9 @@ std::string runTestsExecutable();
std::string findTestRoot();

/// Returns the directory of any installed inputs or the empty string if none are found.
std::string installedInputsDir(const std::string & app_name, const std::string & dir_name);
std::string installedInputsDir(const std::string & app_name,
const std::string & dir_name,
const std::string & extra_error_msg = "");

/// Returns the directory of any installed docs/site.
std::string docsDir(const std::string & app_name);
Expand Down
1 change: 0 additions & 1 deletion framework/moose.mk
Expand Up @@ -39,7 +39,6 @@ pcre_deps := $(patsubst %.cc, %.$(obj-suffix).d, $(pcre_srcfiles)) \
# hit (new getpot parser)
#
HIT_DIR ?= $(MOOSE_DIR)/framework/contrib/hit
#$(info Using HIT from $(HIT_DIR))
hit_CONTENT := $(shell ls $(HIT_DIR) 2> /dev/null)
ifeq ($(hit_CONTENT),)
$(error The HIT input file parser does not seem to be available. If set, make sure the HIT_DIR environment variable is set to the correct location of your HIT parser.)
Expand Down
61 changes: 57 additions & 4 deletions framework/src/base/MooseApp.C
Expand Up @@ -153,6 +153,11 @@ MooseApp::validParams()
"--check-input",
false,
"Check the input file (i.e. requires -i <filename>) and quit.");
params.addCommandLineParam<std::string>(
"show_inputs",
"--show-copyable-inputs",
"Shows the directories able to be installed (copied) into a user-writable location");

params.addCommandLineParam<std::string>("copy_inputs",
"--copy-inputs <dir>",
"Copies installed inputs (e.g. tests, examples, etc.) to "
Expand Down Expand Up @@ -1377,7 +1382,7 @@ MooseApp::run()
return;
}

if (copyInputs() || runInputs())
if (showInputs() || copyInputs() || runInputs())
{
_ready_to_exit = true;
return;
Expand Down Expand Up @@ -1408,18 +1413,64 @@ MooseApp::run()
}

bool
MooseApp::copyInputs()
MooseApp::showInputs() const
{
if (isParamValid("show_inputs"))
{
auto copy_syntax = _pars.getSyntax("copy_inputs");
std::vector<std::string> dirs;
const auto installable_inputs = getInstallableInputs();

if (installable_inputs == "")
{
Moose::out
<< "Show inputs has not been overriden in this application.\nContact the developers of "
"this appication and request that they override \"MooseApp::getInstallableInputs\".\n";
}
else
{
mooseAssert(!copy_syntax.empty(), "copy_inputs sytnax should not be empty");

MooseUtils::tokenize(installable_inputs, dirs, 1, " ");
Moose::out << "The following directories are installable into a user-writeable directory:\n\n"
<< installable_inputs << '\n'
<< "\nTo install one or more directories of inputs, execute the binary with the \""
<< copy_syntax[0] << "\" flag. e.g.:\n$ " << _command_line->getExecutableName()
<< ' ' << copy_syntax[0] << ' ' << dirs[0] << '\n';
}
return true;
}
return false;
}

std::string
MooseApp::getInstallableInputs() const
{
return "";
}

bool
MooseApp::copyInputs() const
{
if (isParamValid("copy_inputs"))
{
// Get command line argument following --copy-inputs on command line
auto dir_to_copy = getParam<std::string>("copy_inputs");

if (dir_to_copy.empty())
mooseError("Error retrieving directory to copy");
if (dir_to_copy.back() != '/')
dir_to_copy += '/';

auto binname = appBinaryName();
if (binname == "")
mooseError("could not locate installed tests to run (unresolved binary/app name)");

auto src_dir = MooseUtils::installedInputsDir(binname, dir_to_copy) + "/";
auto src_dir =
MooseUtils::installedInputsDir(binname,
dir_to_copy,
"Rerun binary with " + _pars.getSyntax("show_inputs")[0] +
" to get a list of installable directories.");
auto dst_dir = binname + "/" + dir_to_copy;
auto cmdname = Moose::getExecutableName();
if (cmdname.find_first_of("/") != std::string::npos)
Expand All @@ -1441,6 +1492,8 @@ MooseApp::copyInputs()

std::string cmd = "mkdir -p " + dst_dir + "; cp -R " + src_dir + " " + dst_dir;

TIME_SECTION("copy_inputs", 2, "Copying Inputs");

// Only perform the copy on the root processor
int return_value = 0;
if (processor_id() == 0)
Expand All @@ -1456,7 +1509,7 @@ MooseApp::copyInputs()
}

bool
MooseApp::runInputs()
MooseApp::runInputs() const
{
if (isParamValid("run"))
{
Expand Down
11 changes: 8 additions & 3 deletions framework/src/parser/CommandLine.C
Expand Up @@ -247,14 +247,19 @@ CommandLine::search(const std::string & option_name)
mooseError("Unrecognized option name: ", option_name);
}

void
CommandLine::printUsage() const
std::string
CommandLine::getExecutableName() const
{
// Grab the first item out of argv
std::string command(_args[0]);
command.substr(command.find_last_of("/\\") + 1);
return command;
}

Moose::out << "Usage: " << command << " [<options>]\n\n"
void
CommandLine::printUsage() const
{
Moose::out << "Usage: " << getExecutableName() << " [<options>]\n\n"
<< "Options:\n"
<< std::left;

Expand Down
14 changes: 9 additions & 5 deletions framework/src/utils/InputParameters.C
Expand Up @@ -688,9 +688,12 @@ InputParameters::addParamNamesToGroup(const std::string & space_delim_names,
}

std::vector<std::string>
InputParameters::getSyntax(const std::string & name)
InputParameters::getSyntax(const std::string & name) const
{
return _params[name]._cli_flag_names;
auto it = _params.find(name);
if (it == _params.end())
mooseError("No parameter exists with the name ", name);
return it->second._cli_flag_names;
}

std::string
Expand Down Expand Up @@ -855,11 +858,12 @@ InputParameters::isParamSetByUser(const std::string & name) const
}

const std::string &
InputParameters::getDescription(const std::string & name)
InputParameters::getDescription(const std::string & name) const
{
if (_params.count(name) == 0)
auto it = _params.find(name);
if (it == _params.end())
mooseError("No parameter exists with the name ", name);
return _params[name]._doc_string;
return it->second._doc_string;
}

template <>
Expand Down
9 changes: 7 additions & 2 deletions framework/src/utils/MooseUtils.C
Expand Up @@ -95,7 +95,9 @@ findTestRoot()
}

std::string
installedInputsDir(const std::string & app_name, const std::string & dir_name)
installedInputsDir(const std::string & app_name,
const std::string & dir_name,
const std::string & extra_error_msg)
{
// See moose.mk for a detailed explanation of the assumed installed application
// layout. Installed inputs are expected to be installed in "share/<app_name>/<folder>".
Expand All @@ -105,7 +107,10 @@ installedInputsDir(const std::string & app_name, const std::string & dir_name)

auto test_root = pathjoin(installed_path, "testroot");
if (!pathExists(installed_path))
mooseError("Couldn't locate any installed inputs to copy in path: ", installed_path);
mooseError("Couldn't locate any installed inputs to copy in path: ",
installed_path,
'\n',
extra_error_msg);

checkFileReadable(test_root);
return installed_path;
Expand Down
8 changes: 8 additions & 0 deletions modules/doc/content/application_development/build_system.md
Expand Up @@ -259,6 +259,14 @@ $ cd <directory>
$ bison-opt --run -j8 # Note: Command line parameters appearing after --run are passed to the TestHarness
```

For a complete list of the directories that may be copied use the `--show-copyable-inputs` flag.

Example:

```
$ bison-opt --show-copyable-inputs
```

When using INL HPC systems to run your input, you will load a module that will set your path correctly.

Example:
Expand Down
1 change: 0 additions & 1 deletion test/Makefile
Expand Up @@ -22,7 +22,6 @@ APPLICATION_NAME := moose_test
BUILD_EXEC := yes
BUILD_TEST_OBJECTS_LIB := no
GEN_REVISION := no
INSTALLABLE_DIRS := tests/misc
include $(FRAMEWORK_DIR)/app.mk

###############################################################################
Expand Down
1 change: 1 addition & 0 deletions test/include/base/MooseTestApp.h
Expand Up @@ -20,6 +20,7 @@ class MooseTestApp : public MooseApp
virtual ~MooseTestApp();

virtual void executeExecutioner() override;
virtual std::string getInstallableInputs() const override;

static void registerAll(Factory & f, ActionFactory & af, Syntax & s, bool use_test_objs = false);
static void registerApps();
Expand Down
7 changes: 7 additions & 0 deletions test/src/base/MooseTestApp.C
Expand Up @@ -18,6 +18,7 @@
#include "EigenProblem.h"

#include "MooseTestApp.h"
#include "MooseRevision.h"

InputParameters
MooseTestApp::validParams()
Expand Down Expand Up @@ -83,6 +84,12 @@ MooseTestApp::executeExecutioner()
MooseApp::executeExecutioner();
}

std::string
MooseTestApp::getInstallableInputs() const
{
return MOOSE_INSTALLABLE_DIRS;
}

void
MooseTestApp::registerAll(Factory & f, ActionFactory & af, Syntax & s, bool use_test_objs)
{
Expand Down
9 changes: 9 additions & 0 deletions test/tests/make_install/tests
Expand Up @@ -10,6 +10,15 @@
issues = '#19022'
design = 'MooseApp.md'

[show_copyable_inputs]
type = 'RunApp'
cli_args = "--show-copyable-inputs"
no_additional_cli_args = True
expect_out = 'The following directories are installable.*tests'

requirement = 'The system shall support the ability to report installable inputs on the command line.'
[]

[test_copy_install]
requirement = 'The system shall support the ability to "install" inputs:'
[setup_fake_test_structure]
Expand Down

0 comments on commit ce067fe

Please sign in to comment.