Generate zoslib env hook#236
Conversation
MikeFultonDev
left a comment
There was a problem hiding this comment.
we discussed this and the recommendation is to go with a solution that binds this information into the programs rather than using a side file
The latest commits address this. The related zoslib PR is: ibmruntimes/zoslib#13 |
| cd - | ||
| } | ||
|
|
||
| generateZOSLIBHooks() |
There was a problem hiding this comment.
Can you add a comment block to describe what this is doing?
For the C code, does this pre-req CLANG or will other compilers work?
| echo "$zoslib_env" | while read line; do | ||
| var=$(echo $line | cut -d '|' -f 1) | ||
| action=$(echo $line | cut -d '|' -f 2) | ||
| value=$(echo $line | cut -d '|' -f 3) |
There was a problem hiding this comment.
should describe the format of the environment 'hooks' - what are the valid values (PREPEND and APPEND ?) What are the supported 'well-known' variables (just PROJECT_ROOT ?) Why is PATH required? if the program isn't in the PATH then they must have explicitly executed it via relative or absolute specification in which case, it can be determined? Why is LIBPATH required? Can't it be determined from the location of the program (e.g. <program absolute location>/../lib ?
There was a problem hiding this comment.
Should check for var/action/value being valid and that the line is a valid line
| // Substitute PROJECT_ROOT with root_dir | ||
| pos = strstr(value_str, "PROJECT_ROOT"); | ||
| if (pos != NULL) { | ||
| int len = pos - value_str; |
There was a problem hiding this comment.
maybe something more descriptive than len? This is the length of the prefix before the PROJECT_ROOT correct?
| int len = pos - value_str; | ||
| strncat(envar_value, value_str, len); | ||
| strcat(envar_value, root_dir); | ||
| strcat(envar_value, pos + strlen("PROJECT_ROOT")); |
There was a problem hiding this comment.
since PROJECT_ROOT is a hard-coded string, why not have a macro with that string and then you can have a PROJECT_ROOT_LEN that is just sizeof(PROJECT_ROOT)-1 ? That saves a strlen call...
| #endif | ||
| if (!getenv("$var")) { | ||
| if (setenv("$var", envar_value, 1) != 0) { | ||
| fprintf(stderr, "Error: Setting environment variable %s=%s\n", "$var", envar_value); |
There was a problem hiding this comment.
shouldn't this be a hard failure if the env var can't be set?
| zz | ||
| elif [ "$action" = "prepend" ]; then | ||
| cat <<zz >>$output | ||
| value_str = "$value"; |
There was a problem hiding this comment.
similar comments as for set
| echo "}" >> $output | ||
|
|
||
| if [ "$CC" = "xlclang" ]; then | ||
| extraOptions="-qexportall" |
There was a problem hiding this comment.
Why does xlclang need exportall? Why doesn't clang? Does everything have to be exported, or could you use a #pragma export directive ?
Works with zoslib PR: ibmruntimes/zoslib#13.
For git, this allows it to run without having to source the .env: