setup-matlab icon indicating copy to clipboard operation
setup-matlab copied to clipboard

Support for launching matlab via CMake in setup-matlab@v2

Open traversaro opened this issue 1 year ago • 3 comments

Hello everyone, thanks a lot for work on MATLAB-related GitHub Actions.

I looked in updating the CI of my projects to setup-matlab@v2 (see https://github.com/robotology/idyntree/pull/1181). As my project is a C++ library that also provides MATLAB bindings, all the tests are handled via CMake test infrastructure (see for example CMake's FindMatlab matlab_add_unit_test command). On setup-matlab@v1 everything worked fine, while on setup-matlab@v2 the test fail as matlab is not able to find the license.

The problem is similar to https://github.com/matlab-actions/setup-matlab/issues/89, but in my case I do not directly set the command used to launch the tests, as that is handled by CMake. I wonder if there is any workaround for launching matlab command using setup-matlab@v2 ? Thanks a lot in advance!

traversaro avatar May 06 '24 08:05 traversaro

Hi @traversaro, like #89, we do not have an official solution for supporting this type of workflow yet.

In the meantime, you may be able to create an adapter script that translates the matlab command CMake is attempting to call into a run-matlab-command call.

For example, in your job log, I see CMake is attempting to call matlab -nodisplay -nodesktop -nojvm -batch SOME_COMMAND_HERE. You could potentially write a bash script named matlab that does something like this:

# Example: 
# matlab -nodisplay -nojvm -batch "disp hello"

# Treat the last arg as the command
# In the example: "disp hello"
cmd=${@: -1}

# Treat everything else but the last two args as args for run-matlab-command 
# In the example: -nodisplay -nojvm
args=${@:1:$#-2}

# Call run-matlab-command with the cmd and args
# In the example: ./run-matlab-command "disp hello" -nodisplay -nojvm 
run-matlab-command "$cmd" "$args"

Then you have to get CMake to call your version of matlab instead of the matlab in the MATLAB bin folder. I am not familiar enough with the FindMatlab module to know if it supports doing that.

Like I mentioned in #89 though: please note the "run-matlab-command" binary is undocumented and subject to change in the future.

mcafaro avatar May 06 '24 14:05 mcafaro

Good idea, thanks! I was thinking on modifying the CMake build system to use run-matlab-command, but avoiding to modify the CMake script would be welcome.

Like I mentioned in https://github.com/matlab-actions/setup-matlab/issues/89 though: please note the "run-matlab-command" binary is undocumented and subject to change in the future.

Sure, thanks!

traversaro avatar May 06 '24 14:05 traversaro

Interested to hear if you end up getting things working with v2.

mcafaro avatar May 06 '24 15:05 mcafaro