matlab-actions / setup-matlab

Set up your GitHub Actions workflow with a specific version of MATLAB.
BSD 3-Clause "New" or "Revised" License
76 stars 11 forks source link

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

Open traversaro opened 6 months ago

traversaro commented 6 months ago

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!

mcafaro commented 6 months ago

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.

traversaro commented 6 months ago

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!

mcafaro commented 6 months ago

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