IBM / ibmi-bob

A build system for creating IBM i-native objects using GNU Make.
https://ibm.github.io/ibmi-bob
Apache License 2.0
48 stars 21 forks source link

Success when failure still (ILEPGM / ILESRVPGM) #314

Closed ITMentalist closed 4 months ago

ITMentalist commented 6 months ago

It looks like based on output that returncode still evaluates to true/success when custom commands in ILEPGM / ILESRVPGM commands

Screenshots : image

image

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.

edmundreinhardt commented 6 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.

ITMentalist commented 6 months ago

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 ?

edmundreinhardt commented 6 months ago

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

edmundreinhardt commented 6 months ago

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
edmundreinhardt commented 6 months ago

we don't have debug flags, but you can put echo statements temporarily in these bash script

ITMentalist commented 5 months ago

hi @edmundreinhardt

ok if I follow correctly : | image 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

ITMentalist commented 5 months ago

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?

edmundreinhardt commented 5 months ago

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

ITMentalist commented 5 months ago

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)

ITMentalist commented 5 months ago

for reference on Bash return code image

edmundreinhardt commented 5 months ago

@ITMentalist Marius would you be able to create a pulll request?

ITMentalist commented 5 months ago

@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.

edmundreinhardt commented 5 months ago

Will you have time later today? Say 1pm EST

ITMentalist commented 5 months ago

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?

edmundreinhardt commented 5 months ago

OK,I am booking a meeting on Monday at 1pm EST. What is your email address?

edmundreinhardt commented 5 months ago

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

https://ibm.webex.com/meet/edmund.reinhardt

irfanshar commented 4 months ago

@ITMentalist

Here's a list of the suggested extensions available on VSCode aiding in your IBM i development

Code for IBM i Db2 for IBM i IBM i Debug IBM i Project Explorer

edmundreinhardt commented 4 months ago

@ITMentalist can we meet again to learn how to merge PRs and to build and test BOB? Would you be free on Friday any time?

edmundreinhardt commented 4 months ago

@ITMentalist please accept my invitation to collaborate on the project

edmundreinhardt commented 4 months ago

https://github.com/IBM/ibmi-bob/invitations

ITMentalist commented 4 months ago

@ITMentalist can we meet again to learn how to merge PRs and to build and test BOB? Would you be free on Friday any time?

Hey @edmundreinhardt ,

Yes ! Definitely, what time will suit you best though? ( I do sometimes join the Code For i Sessions from Seiden which starts at 9pm SAST my time)

(I sent you an email from my gmail account mariuslr , we can connect there to establish the time)