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

Replace hocload.sh with std::filesystem utils #3293

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

JCGoran
Copy link
Collaborator

@JCGoran JCGoran commented Dec 16, 2024

hoc_load seems to be doing the following:

  • takes as arg a hoc keyword like proc, func, begintemplate
  • looks up whether the current hoc argument (from gargstr) is a defined symbol in the current scope
  • if the symbols is not defined, call hocload.sh with 3 args: the keyword, the symbol name, and hoc_pid. This script seems to grep all HOC files in ${PWD}, ${HOC_LIBRARY_PATH} for the pattern func|proc|begintemplate, stores them in the temp file names, then uses sed to find out whether there is a matching symbol in some file. If there is, it echoes the first match, and returns 0, and if there aren't any matches, it returns 1.
  • this is followed by a bunch of logic to see whether the file containing the definition actually exists, followed by a call to hoc_Load_file

I've replaced most of the above using std::filesystem, though I am not sure whether the logic of returning the first match is right in the first place, but nevertheless I tried replicating the existing behavior as closely as possible.

Comment on lines +24 to +28
#if defined(WIN32)
static const auto os_pathsep = std::string(";");
#else
static const auto os_pathsep = std::string(":");
#endif
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if the scope of this var should be placed at the level of split_paths (see below) or left as-is at file level scope.

const std::vector<std::string>& paths) {
namespace fs = std::filesystem;
for (const auto& path: paths) {
for (const auto& entry: fs::directory_iterator(path)) {
Copy link
Collaborator Author

@JCGoran JCGoran Dec 16, 2024

Choose a reason for hiding this comment

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

Not sure if this returns the same ordering as egrep '^func|^proc|^begintemplate' $p/*.oc $p/*.hoc (the C++ standard does not specify ordering, so I guess it depends on the library?).

Copy link
Collaborator

Choose a reason for hiding this comment

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

The entries may not be sorted at all, whereas the shell bit you point out first goes through all .oc files, followed by all .hoc.

Since only the first match is used, would one expect multiple definitions of the same entity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The entries may not be sorted at all

Indeed! I changed the implementation so it's actually sorted, it should even respect the locale now since that's what the POSIX glob does (had a whole rant ready about locales, but it turns out it's surprisingly simple to use, at least for this usecase :)

Since only the first match is used, would one expect multiple definitions of the same entity?

I'd expect it to throw an error in case of multiple definitions, or provide some mechanism to disambiguate, but I don't think there is anything of the sort, so I just sought to replicate the existing behavior.

Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 3.70370% with 52 lines in your changes missing coverage. Please review.

Project coverage is 67.05%. Comparing base (6ab042f) to head (253637f).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/oc/fileio.cpp 3.70% 52 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3293      +/-   ##
==========================================
- Coverage   67.07%   67.05%   -0.02%     
==========================================
  Files         571      571              
  Lines      111055   111097      +42     
==========================================
+ Hits        74486    74492       +6     
- Misses      36569    36605      +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bbpbuildbot

This comment has been minimized.

Copy link

✔️ 6a3f8d8 -> Azure artifacts URL

@JCGoran
Copy link
Collaborator Author

JCGoran commented Dec 17, 2024

Model 150245 from modelDB fails (see https://github.com/neuronsimulator/nrn-modeldb-ci/actions/runs/12369627580/job/34521930207), but I am 99.99% sure it's not related since it fails on the nightly as well (see https://github.com/neuronsimulator/nrn-modeldb-ci/actions/runs/12361469702/job/34498702435).

@JCGoran JCGoran marked this pull request as ready for review December 17, 2024 11:02
Copy link

✔️ 253637f -> Azure artifacts URL

@JCGoran JCGoran requested a review from matz-e December 18, 2024 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants