Skip to content

Commit bb9154d

Browse files
author
Build Action
committed
Build for bc14c58
1 parent bc14c58 commit bb9154d

13 files changed

+440
-0
lines changed

dist/bin/license.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) 2020, The MathWorks, Inc.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
3. In all cases, the software is, and all modifications and derivatives of the
15+
software shall be, licensed to you solely for use in conjunction with
16+
MathWorks products and service offerings.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

dist/bin/run_matlab_command.bat

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
@echo off
2+
rem Executes a specified MATLAB command in batch mode. With MATLAB R2018b+,
3+
rem running this script is equivalent to executing "matlab -batch command" from
4+
rem the system prompt.
5+
rem
6+
rem Copyright 2020 The MathWorks, Inc.
7+
8+
setlocal enableextensions enabledelayedexpansion
9+
10+
set command=%~1
11+
if "%command%" == "" (
12+
call :usage
13+
exit /b 1
14+
)
15+
16+
for %%a in (matlab.exe) do set matlab_path=%%~$PATH:a
17+
18+
if "%matlab_path%" == "" (
19+
echo 'matlab.exe' command not found. Please make sure MATLAB_ROOT\bin is on
20+
echo the system path, where MATLAB_ROOT is the full path to your MATLAB
21+
echo installation directory.
22+
exit /b 1
23+
)
24+
25+
for %%a in ("%matlab_path%\..\..") do set matlab_root=%%~fa
26+
27+
rem try to discover the MATLAB version
28+
if exist "%matlab_root%\VersionInfo.xml" (
29+
rem get version tag contents
30+
for /f %%a in ('findstr "<version>.*</version>" "%matlab_root%\VersionInfo.xml"') do (
31+
set ver_line=%%a
32+
set ver_line=!ver_line:*^<version^>=!
33+
for /f "tokens=1 delims=<" %%b in ("!ver_line!") do set matlab_ver=%%b
34+
)
35+
) else if exist "%matlab_root%\toolbox\matlab\general\Contents.m" (
36+
rem get version printed after "MATLAB Version"
37+
for /f "delims=" %%a in ('findstr /r /c:"MATLAB Version .*" "%matlab_root%\toolbox\matlab\general\Contents.m"') do (
38+
set ver_line=%%a
39+
set ver_line=!ver_line:*MATLAB Version =!
40+
for /f "tokens=1" %%b in ("!ver_line!") do set matlab_ver=%%b
41+
)
42+
)
43+
44+
rem if version not discovered, assume worst-case version of 0
45+
if not defined matlab_ver set matlab_ver=0
46+
47+
rem use -r to launch MATLAB versions below R2018b (i.e. 9.5), otherwise use -batch
48+
call :ver_less_than %matlab_ver% 9.5
49+
if %errorlevel% == 0 (
50+
rem define start-up options
51+
set opts=-nosplash -nodesktop -wait -log
52+
call :ver_less_than %matlab_ver% 8.5
53+
if not !errorlevel! == 0 set opts=!opts! -noDisplayDesktop
54+
55+
rem escape single quotes in command
56+
set exp=!command:'=''!
57+
58+
matlab.exe !opts! -r "try,eval('!exp!'),catch e,disp(getReport(e,'extended')),exit(1),end,exit" > NUL
59+
) else (
60+
matlab.exe -batch "%command%"
61+
)
62+
exit /b %errorlevel%
63+
64+
:usage
65+
echo Usage: run_matlab_command.sh command
66+
echo.
67+
echo command - MATLAB script, statement, or function to execute.
68+
echo.
69+
goto :eof
70+
71+
:ver_less_than
72+
setlocal
73+
call :ver_str %~1 v1
74+
call :ver_str %~2 v2
75+
if "%v1%" lss "%v2%" ( exit /b 0 ) else ( exit /b 1 )
76+
77+
:ver_str
78+
setlocal
79+
set ver=%~1
80+
for /f "tokens=1-4 delims=." %%a in ("%ver%") do (
81+
set major=%%a
82+
set minor=000%%b
83+
set minor=!minor:~-3!
84+
set patch=000%%c
85+
set patch=!patch:~-3!
86+
set build=000000000%%d
87+
set build=!build:~-9!
88+
)
89+
( endlocal & rem return values
90+
set %~2=%major%%minor%%patch%%build%
91+
)
92+
goto :eof

dist/bin/run_matlab_command.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/sh
2+
# Executes a specified MATLAB command in batch mode. With MATLAB R2018b+,
3+
# running this script is equivalent to executing "matlab -batch command" from
4+
# the system prompt.
5+
#
6+
# Copyright 2020 The MathWorks, Inc.
7+
8+
usage() {
9+
echo ''
10+
echo ' Usage: run_matlab_command.sh command'
11+
echo ''
12+
echo ' command - MATLAB script, statement, or function to execute.'
13+
echo ''
14+
}
15+
16+
ver_less_than() {
17+
[ "$(ver_str "$1")" -lt "$(ver_str "$2")" ]
18+
}
19+
20+
ver_str() {
21+
echo "$@" | awk -F. '{ printf("%d%03d%03d%09d\n", $1,$2,$3,$4); }';
22+
}
23+
24+
command=$1
25+
if [ -z "$command" ]; then
26+
usage
27+
exit 1
28+
fi
29+
30+
if ! matlab_path="$(command -v matlab)" || [ -z "$matlab_path" ]; then
31+
echo "'matlab'"' command not found. Please make sure MATLAB_ROOT/bin is on'
32+
echo 'the system path, where MATLAB_ROOT is the full path to your MATLAB'
33+
echo 'installation directory.'
34+
exit 1
35+
fi
36+
37+
# resolve symlink to target
38+
while [ -h "$matlab_path" ]; do
39+
dir=$(dirname -- "$matlab_path")
40+
target=$(readlink "$matlab_path")
41+
matlab_path=$(cd "$dir" && cd "$(dirname -- "$target")" && pwd)/$(basename -- "$target")
42+
done
43+
44+
matlab_root=$(dirname -- "$(dirname -- "$matlab_path")")
45+
46+
# try to discover the MATLAB version
47+
if [ -f "$matlab_root"/VersionInfo.xml ]; then
48+
# get version tag contents
49+
matlab_ver=$(sed -n 's:.*<version>\(.*\)</version>.*:\1:p' < "$matlab_root"/VersionInfo.xml)
50+
elif [ -f "$matlab_root"/toolbox/matlab/general/Contents.m ]; then
51+
# get version printed after "MATLAB Version"
52+
matlab_ver=$(grep -o 'MATLAB Version .*' < "$matlab_root"/toolbox/matlab/general/Contents.m | awk -v N=3 '{print $N}')
53+
fi
54+
55+
# if version not discovered, assume worst-case version of 0
56+
matlab_ver=${matlab_ver:-0}
57+
58+
# use -r to launch MATLAB versions below R2018b (i.e. 9.5), otherwise use -batch
59+
if ver_less_than "$matlab_ver" '9.5'; then
60+
# define start-up options
61+
opts='-nosplash -nodesktop'
62+
if ! ver_less_than "$matlab_ver" '8.6'; then
63+
opts="$opts -noAppIcon"
64+
fi
65+
66+
# escape single quotes in command
67+
exp=$(echo "$command" | sed "s/'/''/g")
68+
69+
matlab "$opts" -r "try,eval('$exp'),catch e,disp(getReport(e,'extended')),exit(1),end,exit"
70+
else
71+
matlab -batch "$command"
72+
fi

dist/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import * as matlab from "./matlab";
2+
export { matlab };

lib/index.js

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/matlab.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Helper interface to represent a MATLAB script.
3+
*/
4+
export interface HelperScript {
5+
dir: string;
6+
command: string;
7+
}
8+
/**
9+
* Type of a function that executes a command on a runner and returns the error
10+
* code.
11+
*/
12+
export declare type ExecFn = (command: string, args?: string[]) => Promise<number>;
13+
/**
14+
* Generate a MATLAB script in the temporary directory that runs a command in
15+
* the workspace.
16+
*
17+
* @param workspaceDir CI job workspace directory
18+
* @param command MATLAB command to run
19+
*/
20+
export declare function generateScript(workspaceDir: string, command: string): Promise<HelperScript>;
21+
/**
22+
* Run a HelperScript in MATLAB.
23+
*
24+
* Create the HelperScript using `generateScript`.
25+
*
26+
* @param hs HelperScript pointing to the script containing the command
27+
* @param platform Operating system of the runner (e.g., "win32" or "linux")
28+
* @param fn ExecFn that will execute a command on the runner
29+
*/
30+
export declare function runCommand(hs: HelperScript, platform: string, fn: ExecFn): Promise<void>;
31+
/**
32+
* Get the path of the script containing RunMATLABCommand for the host OS.
33+
*
34+
* @param platform Operating system of the runner (e.g., "win32" or "linux")
35+
*/
36+
export declare function getRunMATLABCommandScriptPath(platform: string): string;

lib/matlab.js

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/matlab.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)