-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Release Action
committed
May 17, 2021
1 parent
f32a05c
commit f0c693e
Showing
13 changed files
with
440 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2020, The MathWorks, Inc. | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. In all cases, the software is, and all modifications and derivatives of the | ||
software shall be, licensed to you solely for use in conjunction with | ||
MathWorks products and service offerings. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
@echo off | ||
rem Executes a specified MATLAB command in batch mode. With MATLAB R2018b+, | ||
rem running this script is equivalent to executing "matlab -batch command" from | ||
rem the system prompt. | ||
rem | ||
rem Copyright 2020 The MathWorks, Inc. | ||
|
||
setlocal enableextensions enabledelayedexpansion | ||
|
||
set command=%~1 | ||
if "%command%" == "" ( | ||
call :usage | ||
exit /b 1 | ||
) | ||
|
||
for %%a in (matlab.exe) do set matlab_path=%%~$PATH:a | ||
|
||
if "%matlab_path%" == "" ( | ||
echo 'matlab.exe' command not found. Please make sure MATLAB_ROOT\bin is on | ||
echo the system path, where MATLAB_ROOT is the full path to your MATLAB | ||
echo installation directory. | ||
exit /b 1 | ||
) | ||
|
||
for %%a in ("%matlab_path%\..\..") do set matlab_root=%%~fa | ||
|
||
rem try to discover the MATLAB version | ||
if exist "%matlab_root%\VersionInfo.xml" ( | ||
rem get version tag contents | ||
for /f %%a in ('findstr "<version>.*</version>" "%matlab_root%\VersionInfo.xml"') do ( | ||
set ver_line=%%a | ||
set ver_line=!ver_line:*^<version^>=! | ||
for /f "tokens=1 delims=<" %%b in ("!ver_line!") do set matlab_ver=%%b | ||
) | ||
) else if exist "%matlab_root%\toolbox\matlab\general\Contents.m" ( | ||
rem get version printed after "MATLAB Version" | ||
for /f "delims=" %%a in ('findstr /r /c:"MATLAB Version .*" "%matlab_root%\toolbox\matlab\general\Contents.m"') do ( | ||
set ver_line=%%a | ||
set ver_line=!ver_line:*MATLAB Version =! | ||
for /f "tokens=1" %%b in ("!ver_line!") do set matlab_ver=%%b | ||
) | ||
) | ||
|
||
rem if version not discovered, assume worst-case version of 0 | ||
if not defined matlab_ver set matlab_ver=0 | ||
|
||
rem use -r to launch MATLAB versions below R2018b (i.e. 9.5), otherwise use -batch | ||
call :ver_less_than %matlab_ver% 9.5 | ||
if %errorlevel% == 0 ( | ||
rem define start-up options | ||
set opts=-nosplash -nodesktop -wait -log | ||
call :ver_less_than %matlab_ver% 8.5 | ||
if not !errorlevel! == 0 set opts=!opts! -noDisplayDesktop | ||
|
||
rem escape single quotes in command | ||
set exp=!command:'=''! | ||
|
||
matlab.exe !opts! -r "try,eval('!exp!'),catch e,disp(getReport(e,'extended')),exit(1),end,exit" > NUL | ||
) else ( | ||
matlab.exe -batch "%command%" | ||
) | ||
exit /b %errorlevel% | ||
|
||
:usage | ||
echo Usage: run_matlab_command.sh command | ||
echo. | ||
echo command - MATLAB script, statement, or function to execute. | ||
echo. | ||
goto :eof | ||
|
||
:ver_less_than | ||
setlocal | ||
call :ver_str %~1 v1 | ||
call :ver_str %~2 v2 | ||
if "%v1%" lss "%v2%" ( exit /b 0 ) else ( exit /b 1 ) | ||
|
||
:ver_str | ||
setlocal | ||
set ver=%~1 | ||
for /f "tokens=1-4 delims=." %%a in ("%ver%") do ( | ||
set major=%%a | ||
set minor=000%%b | ||
set minor=!minor:~-3! | ||
set patch=000%%c | ||
set patch=!patch:~-3! | ||
set build=000000000%%d | ||
set build=!build:~-9! | ||
) | ||
( endlocal & rem return values | ||
set %~2=%major%%minor%%patch%%build% | ||
) | ||
goto :eof |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/bin/sh | ||
# Executes a specified MATLAB command in batch mode. With MATLAB R2018b+, | ||
# running this script is equivalent to executing "matlab -batch command" from | ||
# the system prompt. | ||
# | ||
# Copyright 2020 The MathWorks, Inc. | ||
|
||
usage() { | ||
echo '' | ||
echo ' Usage: run_matlab_command.sh command' | ||
echo '' | ||
echo ' command - MATLAB script, statement, or function to execute.' | ||
echo '' | ||
} | ||
|
||
ver_less_than() { | ||
[ "$(ver_str "$1")" -lt "$(ver_str "$2")" ] | ||
} | ||
|
||
ver_str() { | ||
echo "$@" | awk -F. '{ printf("%d%03d%03d%09d\n", $1,$2,$3,$4); }'; | ||
} | ||
|
||
command=$1 | ||
if [ -z "$command" ]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
if ! matlab_path="$(command -v matlab)" || [ -z "$matlab_path" ]; then | ||
echo "'matlab'"' command not found. Please make sure MATLAB_ROOT/bin is on' | ||
echo 'the system path, where MATLAB_ROOT is the full path to your MATLAB' | ||
echo 'installation directory.' | ||
exit 1 | ||
fi | ||
|
||
# resolve symlink to target | ||
while [ -h "$matlab_path" ]; do | ||
dir=$(dirname -- "$matlab_path") | ||
target=$(readlink "$matlab_path") | ||
matlab_path=$(cd "$dir" && cd "$(dirname -- "$target")" && pwd)/$(basename -- "$target") | ||
done | ||
|
||
matlab_root=$(dirname -- "$(dirname -- "$matlab_path")") | ||
|
||
# try to discover the MATLAB version | ||
if [ -f "$matlab_root"/VersionInfo.xml ]; then | ||
# get version tag contents | ||
matlab_ver=$(sed -n 's:.*<version>\(.*\)</version>.*:\1:p' < "$matlab_root"/VersionInfo.xml) | ||
elif [ -f "$matlab_root"/toolbox/matlab/general/Contents.m ]; then | ||
# get version printed after "MATLAB Version" | ||
matlab_ver=$(grep -o 'MATLAB Version .*' < "$matlab_root"/toolbox/matlab/general/Contents.m | awk -v N=3 '{print $N}') | ||
fi | ||
|
||
# if version not discovered, assume worst-case version of 0 | ||
matlab_ver=${matlab_ver:-0} | ||
|
||
# use -r to launch MATLAB versions below R2018b (i.e. 9.5), otherwise use -batch | ||
if ver_less_than "$matlab_ver" '9.5'; then | ||
# define start-up options | ||
opts='-nosplash -nodesktop' | ||
if ! ver_less_than "$matlab_ver" '8.6'; then | ||
opts="$opts -noAppIcon" | ||
fi | ||
|
||
# escape single quotes in command | ||
exp=$(echo "$command" | sed "s/'/''/g") | ||
|
||
matlab "$opts" -r "try,eval('$exp'),catch e,disp(getReport(e,'extended')),exit(1),end,exit" | ||
else | ||
matlab -batch "$command" | ||
fi |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import * as matlab from "./matlab"; | ||
export { matlab }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Helper interface to represent a MATLAB script. | ||
*/ | ||
export interface HelperScript { | ||
dir: string; | ||
command: string; | ||
} | ||
/** | ||
* Type of a function that executes a command on a runner and returns the error | ||
* code. | ||
*/ | ||
export declare type ExecFn = (command: string, args?: string[]) => Promise<number>; | ||
/** | ||
* Generate a MATLAB script in the temporary directory that runs a command in | ||
* the workspace. | ||
* | ||
* @param workspaceDir CI job workspace directory | ||
* @param command MATLAB command to run | ||
*/ | ||
export declare function generateScript(workspaceDir: string, command: string): Promise<HelperScript>; | ||
/** | ||
* Run a HelperScript in MATLAB. | ||
* | ||
* Create the HelperScript using `generateScript`. | ||
* | ||
* @param hs HelperScript pointing to the script containing the command | ||
* @param platform Operating system of the runner (e.g., "win32" or "linux") | ||
* @param fn ExecFn that will execute a command on the runner | ||
*/ | ||
export declare function runCommand(hs: HelperScript, platform: string, fn: ExecFn): Promise<void>; | ||
/** | ||
* Get the path of the script containing RunMATLABCommand for the host OS. | ||
* | ||
* @param platform Operating system of the runner (e.g., "win32" or "linux") | ||
*/ | ||
export declare function getRunMATLABCommandScriptPath(platform: string): string; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.