Closed ITMentalist closed 4 months ago
Thank you, that is a very useful observation. A little bit distracted with other priorities, can anyone please suggest a PR on this.
Thanks @edmundreinhardt , is the PR a thing that I can perhaps assist with ? (any pointers, I might be able to assist where possible).
Another thing perhaps that if I may ask, is there a debug flag that I can set on to see what makefile is generated on for debugging the sequence / or what will run ?
Yes please @ITMentalist Marius
So look at the def_rules.mk you will see the recipe follows the form
define ILESRVPGM_TO_SRVPGM_RECIPE =
$(SRVPGM_VARIABLES)
$(eval d = $($@_d))
@$(call echo_cmd,"=== Creating service program [$(tgt)] from [$(notdir $<)]")
$(eval crtcmd := $(shell $(SCRIPTSPATH)/extractPseudoSrc $< $(OBJLIB) $(basename $(@F))))
@$(PRESETUP) \
$(SCRIPTSPATH)/extractAndLaunch "$(JOBLOGFILE)" "$<" $(OBJLIB) $(basename $(@F)) >> $(LOGFILE) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@)
endef
The extractAndLaunch
is a shell script and it is this script that has to accurately return the error code
https://github.com/IBM/ibmi-bob/blob/109affd27b8364e25d96ae257b2014aff9c3dca0/src/scripts/extractAndLaunch
#!/usr/bin/env bash
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
joblog_json=$1
pseudoSrcFile=$2
objlib=$3
objname=$4
cmd=""
while read -r line; do
line=$(echo "$line" | sed 's/\r//')
if [[ $line = '/*'* ]]; then continue; fi
if [[ $line = '' ]]; then continue; fi
if [[ $line =~ .*\+\S* ]]; then
linetmp=$(echo "$line" | sed 's/\+\S*$//')
cmd="${cmd} ${linetmp}"
continue
fi
cmd+=$line
if [ -n "$cmd" ]; then
cmd=$(echo "$cmd" | sed "s/&O/$objlib/g" | sed "s/&N/$objname/g")
"$SCRIPT_DIR"/launch "$joblog_json" "$cmd" </dev/null
# echo "Running $cmd"
cmd=""
fi
done < <(grep "" $pseudoSrcFile)
as you can see the return value of the launch
script is not being returned
the following code might be helpful
result=$("$SCRIPT_DIR"/launch "$joblog_json" "$cmd" </dev/null)
echo "Result: $result"
if [ "$result" -ne 0 ]; then
exit 1
fi
we don't have debug flags, but you can put echo statements temporarily in these bash script
hi @edmundreinhardt
ok if I follow correctly : |
this unfortunately also doesnt return the "return code" correctly.
looking abit deeper now at how this is invoked, is there a way to run each command without the build on a sort of sequence? (to clarify the build process abit more in a streamlined manner perhaps)
intend is from my side to "execute" the script on its own to see what effect the patch code does.
thank you
Yes please @ITMentalist Marius
So look at the def_rules.mk you will see the recipe follows the form
define ILESRVPGM_TO_SRVPGM_RECIPE = $(SRVPGM_VARIABLES) $(eval d = $($@_d)) @$(call echo_cmd,"=== Creating service program [$(tgt)] from [$(notdir $<)]") $(eval crtcmd := $(shell $(SCRIPTSPATH)/extractPseudoSrc $< $(OBJLIB) $(basename $(@F)))) @$(PRESETUP) \ $(SCRIPTSPATH)/extractAndLaunch "$(JOBLOGFILE)" "$<" $(OBJLIB) $(basename $(@F)) >> $(LOGFILE) 2>&1 && $(call logSuccess,$@) || $(call logFail,$@) endef
The
extractAndLaunch
is a shell script and it is this script that has to accurately return the error code https://github.com/IBM/ibmi-bob/blob/109affd27b8364e25d96ae257b2014aff9c3dca0/src/scripts/extractAndLaunch#!/usr/bin/env bash SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) joblog_json=$1 pseudoSrcFile=$2 objlib=$3 objname=$4 cmd="" while read -r line; do line=$(echo "$line" | sed 's/\r//') if [[ $line = '/*'* ]]; then continue; fi if [[ $line = '' ]]; then continue; fi if [[ $line =~ .*\+\S* ]]; then linetmp=$(echo "$line" | sed 's/\+\S*$//') cmd="${cmd} ${linetmp}" continue fi cmd+=$line if [ -n "$cmd" ]; then cmd=$(echo "$cmd" | sed "s/&O/$objlib/g" | sed "s/&N/$objname/g") "$SCRIPT_DIR"/launch "$joblog_json" "$cmd" </dev/null # echo "Running $cmd" cmd="" fi done < <(grep "" $pseudoSrcFile)
as you can see the return value of the
launch
script is not being returned
follow question on the "recipes" , here another request, if one is able to run the recipes on their own perhaps?
I am sorry, the recipes are invoked from the generated makefile and have variables that need to be resolved by make, so they cannot be run outside of make. Running makei compile -f
on a touched file of the specific type does isolate running that recipe. So in the scenario above if you touch foo.ilesrvpgm
and the run makei compile -f foo.ilesrvpgm
you will be running that recipe
the following code might be helpful
result=$("$SCRIPT_DIR"/launch "$joblog_json" "$cmd" </dev/null) echo "Result: $result" if [ "$result" -ne 0 ]; then exit 1 fi
ok, seems AI did a win for me on understanding Bash
you were on the right track with the return code , though because of the exit operation in bash, one cant "view" the return code
so the correct patch code is then as follows will then evaluate the correct if conditional:
cmd+=$line
if [ -n "$cmd" ]; then
cmd=$(echo "$cmd" | sed "s/&O/$objlib/g" | sed "s/&N/$objname/g")
#echo "Running Command: $cmd"
"$SCRIPT_DIR"/launch "$joblog_json" "$cmd" </dev/null
#cmd=""
### Patch Code Start Here ###
#result=$("$SCRIPT_DIR"/launch "$joblog_json" "$cmd" </dev/null)
if [ $? -ne 0 ]; then
echo "Result: NOT OK!!!"
exit 1
fi
### Patch Code End Here ###
fi
done < <(grep "" $pseudoSrcFile)
this then works beautifully.
though I feel that it will make it clearer if one can "return" the integers accordingly.
what will the impact be if we change this part : https://github.com/IBM/ibmi-bob/blob/109affd27b8364e25d96ae257b2014aff9c3dca0/src/scripts/launch#L56 exit $exitCode to echo $exitCode ?
one perhaps have more "structure and standard" vs the other "free form"
(excuse the jump around on the discussion, still finding my feet wet on Git)
for reference on Bash return code
@ITMentalist Marius would you be able to create a pulll request?
@ITMentalist Marius would you be able to create a pulll request?
Hi @edmundreinhardt , sure, if you dont mind me being the complete beginner,
Can you perhaps walk me through some pointers? (do I just submit the changed code as a pull request?) , what about testing confirmation? and build confirmation.
Will you have time later today? Say 1pm EST
Can we perhaps try on Monday? , I see my free night didnt turn out the way I planned. (1pm EST on Monday will work for me), would you like to connect over email or zoom perhaps?
OK,I am booking a meeting on Monday at 1pm EST. What is your email address?
1pm EST at Meeting link: https://ibm.webex.com/meet/edmund.reinhardt
Meeting number: 927 985 491
Join from a video conferencing system or application Dial: edmund.reinhardt@ibm.webex.com
Access Code: 927 985 491
It looks like based on output that returncode still evaluates to true/success when custom commands in ILEPGM / ILESRVPGM commands
Screenshots :
Is there a way to determine with a debug flag in the build engine to see which commands run in sequence and their output ? or any point into direction where one can evaluate the part where the spool in *.output gets evaluated for completion on success/failure.
Much appreciated.