Skip to content

Commit 07310e1

Browse files
authored
Merge pull request #45 from matlab-actions/sdfix
Sdfix
2 parents 536a275 + 0e4d45e commit 07310e1

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

.github/workflows/bat.yml

+14
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,17 @@ jobs:
7474
uses: ./
7575
with:
7676
command: assert(onetyone==11, 'the variable `onetyone` was not set as expected by startup.m')
77+
78+
- run: |
79+
mkdir subdir
80+
echo 'onetyonetyone = 111' > subdir/startup.m
81+
shell: bash
82+
83+
- name: MATLAB sd startup option is not overwritten
84+
uses: ./
85+
with:
86+
command: >
87+
assert(onetyonetyone==111);
88+
[~, f] = fileparts(pwd);
89+
assert(strcmp(f, 'subdir'));
90+
startup-options: -sd subdir

src/matlab.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ export async function generateScript(workspaceDir: string, command: string): Pro
3333
const temporaryDirectory = await fs.mkdtemp(path.join(os.tmpdir(), "run_matlab_command-"));
3434

3535
const scriptPath = path.join(temporaryDirectory, scriptName + ".m");
36-
await fs.writeFile(scriptPath, script.cdAndCall(workspaceDir, command), {
36+
await fs.writeFile(scriptPath, script.cdAndCall(command), {
3737
encoding: "utf8",
3838
});
3939

40-
return { dir: temporaryDirectory, command: scriptName };
40+
return {
41+
dir: temporaryDirectory,
42+
command: scriptName
43+
};
4144
}
4245

4346
/**
@@ -54,7 +57,7 @@ export async function runCommand(hs: HelperScript, platform: string, architectur
5457
const rmcPath = getRunMATLABCommandScriptPath(platform, architecture);
5558
await fs.chmod(rmcPath, 0o777);
5659

57-
const rmcArg = script.cdAndCall(hs.dir, hs.command);
60+
const rmcArg = `setenv('MW_ORIG_WORKING_FOLDER', cd('${script.pathToCharVec(hs.dir)}'));${hs.command}`;
5861

5962
let execArgs = [rmcArg];
6063

src/script.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 The MathWorks, Inc.
1+
// Copyright 2020-2023 The MathWorks, Inc.
22

33
/**
44
* Generate MATLAB command for changing directories and calling a command in it.
@@ -7,8 +7,8 @@
77
* @param command Command to run in directory.
88
* @returns MATLAB command.
99
*/
10-
export function cdAndCall(dir: string, command: string): string {
11-
return `cd('${pathToCharVec(dir)}');${command}`;
10+
export function cdAndCall(command: string): string {
11+
return `cd(getenv('MW_ORIG_WORKING_FOLDER'));${command}`;
1212
}
1313

1414
/**

src/script.unit.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
// Copyright 2020 The MathWorks, Inc.
1+
// Copyright 2020-2023 The MathWorks, Inc.
22

33
import * as script from "./script";
44

55
describe("call generation", () => {
66
it("ideally works", () => {
77
// I know what your thinking
8-
const testDir = String.raw`C:\Users\you\You're Documents`;
98
const testCommand = "disp('hello world')";
10-
const expectedString = String.raw`cd('C:\Users\you\You''re Documents');${testCommand}`;
9+
const expectedString = `cd(getenv('MW_ORIG_WORKING_FOLDER'));${testCommand}`;
1110

12-
expect(script.cdAndCall(testDir, testCommand)).toMatch(expectedString);
11+
expect(script.cdAndCall(testCommand)).toMatch(expectedString);
1312
});
1413
});
1514

0 commit comments

Comments
 (0)