Skip to content

Commit 59bb1cd

Browse files
committed
ParmParse: Prefix to FILE
For CI/CD workflows and out-of-source tests we often want to include dependent inputs files via `FILE = <filename>`. For development, we often want to run in temporary run directories but want to avoid having to copy over the latest inputs file from a source directory. Now, the environment variable `AMREX_INPUTS_FILE_PREFIX` can be set to prefix every `FILE = <filename>` with a custom path. We will use this in the CTests integration of WarpX.
1 parent de4dc97 commit 59bb1cd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Src/Base/AMReX_ParmParse.H

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class RealVect;
6060
// '\n's. The "FILE = <filename>" definition is special. Rather than just
6161
// adding this entry to the database, it reads the contents of <filename>
6262
// into the database.
63+
// For CI/CD workflows and out-of-source tests, the environment variable
64+
// AMREX_INPUTS_FILE_PREFIX can be set to prefix every FILE = <filename>
65+
// with a custom path.
6366
//
6467
// ParmParse stores all entries in a static table which is built the
6568
// first time a ParmParse object is constructed (usually in main()).

Src/Base/AMReX_ParmParse.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <algorithm>
1111
#include <cctype>
12+
#include <cstdlib>
1213
#include <iostream>
1314
#include <limits>
1415
#include <numeric>
@@ -407,6 +408,14 @@ read_file (const char* fname, ParmParse::Table& tab)
407408
//
408409
if ( fname != nullptr && fname[0] != 0 )
409410
{
411+
std::string filename = fname;
412+
413+
// optional prefix to search files in
414+
char const *amrex_inputs_file_prefix = std::getenv("AMREX_INPUTS_FILE_PREFIX");
415+
if (amrex_inputs_file_prefix != nullptr) {
416+
filename = std::string(amrex_inputs_file_prefix) + filename;
417+
}
418+
410419
#ifdef AMREX_USE_MPI
411420
if (ParallelDescriptor::Communicator() == MPI_COMM_NULL)
412421
{
@@ -415,7 +424,6 @@ read_file (const char* fname, ParmParse::Table& tab)
415424
#endif
416425

417426
Vector<char> fileCharPtr;
418-
std::string filename = fname;
419427
ParallelDescriptor::ReadAndBcastFile(filename, fileCharPtr);
420428

421429
std::istringstream is(fileCharPtr.data());

0 commit comments

Comments
 (0)