diff --git a/Src/Base/AMReX_ParmParse.H b/Src/Base/AMReX_ParmParse.H index cc9588793d..802997b6e9 100644 --- a/Src/Base/AMReX_ParmParse.H +++ b/Src/Base/AMReX_ParmParse.H @@ -60,6 +60,9 @@ class RealVect; // '\n's. The "FILE = " definition is special. Rather than just // adding this entry to the database, it reads the contents of // into the database. +// For CI/CD workflows and out-of-source tests, the environment variable +// AMREX_INPUTS_FILE_PREFIX can be set to prefix every FILE = +// with a custom path. // // ParmParse stores all entries in a static table which is built the // first time a ParmParse object is constructed (usually in main()). diff --git a/Src/Base/AMReX_ParmParse.cpp b/Src/Base/AMReX_ParmParse.cpp index df1e18e9b0..2e3efff7a6 100644 --- a/Src/Base/AMReX_ParmParse.cpp +++ b/Src/Base/AMReX_ParmParse.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -407,6 +408,19 @@ read_file (const char* fname, ParmParse::Table& tab) // if ( fname != nullptr && fname[0] != 0 ) { + std::string filename = fname; + + // optional prefix to search files in + char const *amrex_inputs_file_prefix_c = std::getenv("AMREX_INPUTS_FILE_PREFIX"); + if (amrex_inputs_file_prefix_c != nullptr) { + // we expect a directory path as the prefix: append a trailing "/" if missing + auto amrex_inputs_file_prefix = std::string(amrex_inputs_file_prefix_c); + if (amrex_inputs_file_prefix.back() != '/') { + amrex_inputs_file_prefix += "/"; + } + filename = amrex_inputs_file_prefix + filename; + } + #ifdef AMREX_USE_MPI if (ParallelDescriptor::Communicator() == MPI_COMM_NULL) { @@ -415,7 +429,6 @@ read_file (const char* fname, ParmParse::Table& tab) #endif Vector fileCharPtr; - std::string filename = fname; ParallelDescriptor::ReadAndBcastFile(filename, fileCharPtr); std::istringstream is(fileCharPtr.data());