Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with shared lib file not found failures due to OS file extension mismatch #430

Merged
merged 2 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/module_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ jobs:
- name: Run surfacebmi plus cfebmi
run: |
inputfile='data/example_bmi_multi_realization_config.json'
if [ ${{ runner.os }} == 'macOS' ]
then
inputfile=data/example_bmi_multi_realization_config__macos.json
fi
./cmake_build/ngen data/catchment_data.geojson "cat-27" data/nexus_data.geojson "nex-26" $inputfile

# Run t-route/pybind integration test
Expand Down
4 changes: 2 additions & 2 deletions data/example_bmi_multi_realization_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "bmi_fortran",
"params": {
"model_type_name": "bmi_fortran_noahowp",
"library_file": "./extern/noah-owp-modular/cmake_build/libsurfacebmi.so",
"library_file": "./extern/noah-owp-modular/cmake_build/libsurfacebmi",
"forcing_file": "",
"init_config": "./data/bmi/fortran/noah-owp-modular-init-{{id}}.namelist.input",
"allow_exceed_end_time": true,
Expand All @@ -36,7 +36,7 @@
"name": "bmi_c",
"params": {
"model_type_name": "bmi_c_cfe",
"library_file": "./extern/cfe/cmake_build/libcfebmi.so",
"library_file": "./extern/cfe/cmake_build/libcfebmi",
"forcing_file": "",
"init_config": "./data/bmi/c/cfe/{{id}}_bmi_config.ini",
"allow_exceed_end_time": true,
Expand Down
29 changes: 26 additions & 3 deletions include/realizations/catchment/AbstractCLibBmiAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,32 @@ namespace models {
return;
}
if (!utils::FileChecker::file_is_readable(bmi_lib_file)) {
this->init_exception_msg =
"Can't init " + this->model_name + "; unreadable shared library file '" + bmi_lib_file + "'";
throw std::runtime_error(this->init_exception_msg);
//Try alternative extension...
size_t idx = bmi_lib_file.rfind(".");
std::string alt_bmi_lib_file;
if(bmi_lib_file.substr(idx) == ".so"){
alt_bmi_lib_file = bmi_lib_file.substr(0,idx) + ".dylib";
} else if(bmi_lib_file.substr(idx) == ".dylib"){
alt_bmi_lib_file = bmi_lib_file.substr(0,idx) + ".so";
} else {
// Try appending instead of replacing...
#ifdef __APPLE__
alt_bmi_lib_file = bmi_lib_file + ".dylib";
#else
#ifdef __GNUC__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that windows compiling with Cygwin or mingw could get here. Would it be worth checking for and warning that Windows is not currently supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly... I have a feeling it wouldn't get that far. Maybe we should consider this: https://github.com/cygwin/cygwin-install-action ... someday.

alt_bmi_lib_file = bmi_lib_file + ".so";
#endif // __GNUC__
#endif // __APPLE__
}
//TODO: Try looking in e.g. /usr/lib, /usr/local/lib, $LD_LIBRARY_PATH... try pre-pending "lib"...
if (utils::FileChecker::file_is_readable(alt_bmi_lib_file)) {
bmi_lib_file = alt_bmi_lib_file;
} else {
this->init_exception_msg =
"Can't init " + this->model_name + "; unreadable shared library file '" + bmi_lib_file + "'";
throw std::runtime_error(this->init_exception_msg);
}

}

// Call first to ensure any previous error is cleared before trying to load the symbol
Expand Down