Skip to content

Commit fabe4fa

Browse files
authored
Add runtime directory to system PATH for windows (#140)
1 parent 20b7fe4 commit fabe4fa

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

tasks/install-matlab/v1/src/install.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import {AgentHostedMode, getAgentMode} from "azure-pipelines-task-lib/task";
44
import * as toolLib from "azure-pipelines-tool-lib/tool";
5+
import * as fs from "fs";
56
import * as path from "path";
67
import * as matlab from "./matlab";
78
import * as mpm from "./mpm";
@@ -41,4 +42,16 @@ export async function install(platform: string, architecture: string, release: s
4142

4243
// install matlab-batch
4344
await matlab.setupBatch(platform, matlabArch);
45+
46+
// add MATLAB Runtime to system path on Windows
47+
if (platform === "win32") {
48+
try {
49+
const runtimePath = path.join(toolpath, "runtime", matlabArch === "x86" ? "win32" : "win64");
50+
if (fs.existsSync(runtimePath)) {
51+
toolLib.prependPath(runtimePath);
52+
}
53+
} catch (err: any) {
54+
throw new Error("Failed to add MATLAB Runtime to system path on windows.");
55+
}
56+
}
4457
}

tasks/install-matlab/v1/test/install.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as assert from "assert";
44
import * as taskLib from "azure-pipelines-task-lib/task";
55
import * as toolLib from "azure-pipelines-tool-lib/tool";
6+
import * as fs from "fs";
67
import * as sinon from "sinon";
78
import * as install from "../src/install";
89
import * as matlab from "../src/matlab";
@@ -19,6 +20,7 @@ export default function suite() {
1920
let stubMpmSetup: sinon.SinonStub;
2021
let stubMpmInstall: sinon.SinonStub;
2122
let stubPrependPath: sinon.SinonStub;
23+
let stubExistsSync: sinon.SinonStub;
2224

2325
const platform = "linux";
2426
const architecture = "x64";
@@ -44,6 +46,7 @@ export default function suite() {
4446
stubMpmSetup = sinon.stub(mpm, "setup");
4547
stubMpmInstall = sinon.stub(mpm, "install");
4648
stubPrependPath = sinon.stub(toolLib, "prependPath");
49+
stubExistsSync = sinon.stub(fs, "existsSync");
4750
});
4851

4952
afterEach(() => {
@@ -55,6 +58,7 @@ export default function suite() {
5558
stubMpmSetup.restore();
5659
stubMpmInstall.restore();
5760
stubPrependPath.restore();
61+
stubExistsSync.restore();
5862
});
5963

6064
it("ideally works", async () => {
@@ -102,5 +106,13 @@ export default function suite() {
102106
assert(stubSetupBatch.calledWith("darwin", "x64"));
103107
assert(stubMpmSetup.calledWith("darwin", "x64"));
104108
});
109+
110+
// Update the test cases
111+
it("adds MATLAB Runtime to system path on Windows if directory exists", async () => {
112+
stubExistsSync.returns(true);
113+
await install.install("win32", "x64", release, products);
114+
assert(stubPrependPath.calledWith(`${toolcacheDir}/runtime/win64`));
115+
});
116+
105117
});
106118
}

0 commit comments

Comments
 (0)