0

I dont have much experience with IDL but i need to fix a bug where in the compilation failure status needs to be returned to the calling script.

    cat << ENDCAT > something.pro

    PRINT, "Start"

    PRINT, "Compiling functions needing early compile"
    @do_early_func

    PRINT, "Compiling remaining functions"
    @do_other_func

    PRINT, "Running: resolve_all"
    resolve_all

    EXIT

    ENDCAT

    setenv IDL_STARTUP something.pro

    $IDL_DIR/bin/idl

The above content exists in a script called make_program which is called by another script called the build_script

The problem i am facing is that even if 'resolve_all' results in a compilation failure, the make_program always returns a true to the build_script making it think the compilation succeeded when it actually didnt. How can i return the failure status back to the calling script?

Onkar
  • 25
  • 6

2 Answers2

0

The EXIT routine has a STATUS keyword that can return the exit status of the script. So something like:

exit, status=status_code

To determine if RESOLVE_ALL completed correctly, you may need to do a CATCH block. The easiest way is probably to wrap RESOLVE_ALL in your own routine that has an ERROR keyword that returns whether the RESOLVE_ALL succeeded.

mgalloy
  • 2,356
  • 1
  • 12
  • 10
0

I'm not sure where I picked this up but you'll need two routines:

function validate_syntax_helper, routineName

  compile_opt strictarr, hidden

  catch, error
  if (error ne 0) then return, 0

  resolve_routine, routineName, /either, /compile_full_file
  return, 1

end

and

function validate_syntax, routineName

  compile_opt strictarr, hidden

  oldquiet = !quiet
  !quiet = 1

  catch, error
  if (error ne 0) then return, 0

  ; Get current directory
  cd, current=pwd

  o = obj_new('IDL_IDLBridge')
  o->execute, '@' + pref_get('IDL_STARTUP')
  ; Change to current directory
  o->execute, 'cd, ''' + pwd + ''''
  ; Validate syntax
  cmd = 'result = validate_syntax_helper(''' + routineName + ''')'
  o->execute, cmd
  result = o->getVar('result')
  obj_destroy, o

  !quiet = oldquiet

  return, result

end

You then call validate_syntax, which returns 1 when it can compile and 0 when it can't. I don't think this can be used from the IDL virtual machine since it uses execute, but maybe that doesn't matter to you. You'll have to manually run this on all your routines to be compiled instead of running resolve_all.

sappjw
  • 373
  • 1
  • 14