Skip to content

Commit d194d92

Browse files
committed
simplify buildfile
1 parent 60445f2 commit d194d92

File tree

10 files changed

+163
-130
lines changed

10 files changed

+163
-130
lines changed

.github/workflows/composite-nomex/action.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ runs:
2727
uses: matlab-actions/run-build@v2
2828
with:
2929
startup-options: ${{ matrix.startup-options }}
30-
tasks: test:java
30+
tasks: test:java test:java_exe
3131

3232

3333
- name: Java Test (< R2024b)
@@ -44,9 +44,8 @@ runs:
4444
if: ${{ matrix.release < 'R2022b' }}
4545
uses: matlab-actions/run-command@v2
4646
with:
47-
command: run('test/test_main.m')
47+
command: test_main
4848
startup-options: -logfile ${{ matrix.release }}-${{ runner.os }}-test.log
49-
# test/test_main.m adds path internally
5049

5150
- name: upload logfile
5251
if: ${{ hashFiles(matrix.release-runner.os-test.log) != '' }}

Readme.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ Matlab R2022b..R2024a, inclusive:
3131

3232
```matlab
3333
buildtool test_main
34-
buildtool test_java
3534
```
3635

3736
Matlab older than R2022b:
3837

3938
```matlab
40-
run('test/test_main.m')
39+
test_main
4140
```
4241

4342
## Java-based functions

buildfile.m

Lines changed: 45 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -9,128 +9,97 @@
99
plan("clean") = matlab.buildtool.tasks.CleanTask;
1010
end
1111

12-
cnomex = ~HasTag("exe") & ~HasTag("mex") & ~HasTag("java") & ~HasTag("python");
12+
cnomex = ~HasTag("exe") & ~HasTag("mex") & ~HasTag("java") & ~HasTag("java_exe") & ~HasTag("python");
1313
if ispc()
1414
cnomex = cnomex & ~HasTag("unix");
1515
else
1616
cnomex = cnomex & ~HasTag("windows");
1717
end
1818

19-
% cmex = HasTag("mex");
20-
21-
cjava = HasTag("java") & ~HasTag("exe");
22-
2319
pkg_root = fullfile(plan.RootFolder, "+stdlib");
2420
test_root = fullfile(plan.RootFolder, "test");
2521

26-
if isMATLABReleaseOlderThan("R2023b")
27-
plan("test_exe") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, HasTag("exe")), Dependencies="exe");
28-
elseif isMATLABReleaseOlderThan("R2024b")
29-
plan("test_exe") = matlab.buildtool.tasks.TestTask(test_root, Tag="exe", Dependencies="exe");
30-
end
31-
3222
if isMATLABReleaseOlderThan("R2024b")
3323

34-
plan("test_java") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cjava));
35-
plan("test_main") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cnomex));
24+
plan("test_main") = matlab.buildtool.Task(Actions=@(context) test_main(context, cnomex));
25+
26+
if isMATLABReleaseOlderThan('R2023b')
27+
return
28+
end
29+
30+
plan("test_java") = matlab.buildtool.tasks.TestTask(test_root, Tag="java");
31+
plan("test_exe") = matlab.buildtool.tasks.TestTask(test_root, Tag="exe", Dependencies="exe");
3632

3733
elseif isMATLABReleaseOlderThan("R2025a")
3834
% Matlab == R2024b
39-
plan("test:java") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cjava));
4035
plan("test:exe") = matlab.buildtool.tasks.TestTask(test_root, Tag="exe", Dependencies="exe");
41-
plan("test:main") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cnomex));
42-
% plan("test:mex") = matlab.buildtool.Task(Actions=@(context) legacy_test(context, cmex), Dependencies="mex");
36+
plan("test:main") = matlab.buildtool.Task(Actions=@(context) test_main(context, cnomex));
4337

4438
else
4539
% Matlab >= R2025a
46-
plan("test:exe") = matlab.buildtool.tasks.TestTask(test_root, Tag="exe", Description="test subprocess",...
47-
SourceFiles=[pkg_root, test_root + ["/*.cpp", "/*.c", "/*.f90"]], ...
48-
RunOnlyImpactedTests=true,...
49-
Dependencies="exe", TestResults="TestResults_exe.xml", Strict=true);
50-
51-
plan("test:main") = matlab.buildtool.tasks.TestTask(test_root, Description="Test non-MEX targets",...
52-
Selector=cnomex, ...
53-
SourceFiles=pkg_root, RunOnlyImpactedTests=true,...
54-
TestResults="TestResults_nomex.xml", Strict=true);
55-
56-
% plan("test:mex") = matlab.buildtool.tasks.TestTask(test_root, Description="Test mex targts",...
57-
% Selector=cmex, ...
58-
% SourceFiles=[pkg_root, plan.RootFolder + "/src"], RunOnlyImpactedTests=true,...
59-
% Dependencies="mex", TestResults="TestResults_mex.xml", Strict=true);
60-
61-
plan("test:java") = matlab.buildtool.tasks.TestTask(test_root, Description="test Java targets", ...
62-
Selector=cjava, ...
63-
SourceFiles=pkg_root, RunOnlyImpactedTests=true,...
64-
TestResults="TestResults_java.xml", Strict=true);
40+
plan("test:exe") = matlab.buildtool.tasks.TestTask(...
41+
test_root, Description="test subprocess",...
42+
Tag="exe", ...
43+
SourceFiles=[pkg_root, test_root + ["/*.cpp", "/*.c", "/*.f90"]], ...
44+
RunOnlyImpactedTests=true,...
45+
Dependencies="exe", TestResults="TestResults_exe.xml", Strict=true);
46+
47+
plan("test:main") = matlab.buildtool.tasks.TestTask(...
48+
test_root, Description="Test non-MEX targets",...
49+
Selector=cnomex, ...
50+
SourceFiles=pkg_root, RunOnlyImpactedTests=true,...
51+
TestResults="TestResults_nomex.xml", Strict=true);
52+
53+
end
54+
55+
56+
if ~isMATLABReleaseOlderThan('R2024b')
57+
58+
plan("test:python") = matlab.buildtool.tasks.TestTask(...
59+
test_root, Description="test Python targets", ...
60+
Tag = "python", ...
61+
TestResults="TestResults_java.xml", Strict=true);
62+
63+
plan("test:java") = matlab.buildtool.tasks.TestTask(...
64+
test_root, Description="test Java targets", ...
65+
Tag = "java", ...
66+
TestResults="TestResults_java.xml", Strict=true);
67+
68+
plan("test:java_exe") = matlab.buildtool.tasks.TestTask(...
69+
test_root, Description="test Java exe targets", ...
70+
Tag = "java_exe", ...
71+
TestResults="TestResults_java_exe.xml", Strict=true);
6572

6673
addons = matlab.addons.installedAddons;
6774
if contains(addons.Name, "Matlab Test")
6875
plan("coverage") = matlab.buildtool.tasks.TestTask(test_root, ...
6976
Description="code coverage", ...
7077
Dependencies="exe", ...
7178
SourceFiles=pkg_root, ...
72-
Selector=cnomex | HasTag("java") | HasTag("exe") | HasTag("python"), ...
7379
Strict=false).addCodeCoverage(matlabtest.plugins.codecoverage.StandaloneReport("coverage-report.html"));
7480
end
7581

76-
% plan("clean_mex") = matlab.buildtool.Task(Actions=@clean_mex, Description="Clean only MEX files to enable incremental tests");
7782
end
7883

79-
if isMATLABReleaseOlderThan("R2023a"), return, end
80-
8184
srcs = ["stdout_stderr_c.c", "stdin_cpp.cpp", "printenv.cpp", "sleep.cpp"];
82-
exes = ["stdout_stderr_c.exe", "stdin_cpp.exe", "printenv.exe", "sleep.exe"];
8385
if ~isempty(get_compiler("fortran"))
8486
srcs = [srcs, "stdout_stderr_fortran.f90", "stdin_fortran.f90"];
85-
exes = [exes, "stdout_stderr_fortran.exe", "stdin_fortran.exe"];
8687
end
88+
[~, exes] = fileparts(srcs);
89+
exes = exes + ".exe";
8790

8891
srcs = fullfile(test_root, srcs);
8992
exes = fullfile(test_root, exes);
9093

9194
plan("exe") = matlab.buildtool.Task(Inputs=srcs, Outputs=exes, Actions=@build_exe, ...
92-
Description="build test exe's for test subprocess");
95+
Description="build demo executables for testing java_run");
9396

9497
if ~isMATLABReleaseOlderThan("R2024a")
9598
plan("check") = matlab.buildtool.tasks.CodeIssuesTask(plan.RootFolder, ...
9699
IncludeSubfolders=true, ...
97100
WarningThreshold=0, Results="CodeIssues.sarif");
98101
end
99102

100-
101-
%% MexTask
102-
if ~isMATLABReleaseOlderThan("R2024b")
103-
% for s = get_mex_sources()
104-
% src = s{1};
105-
% [~, name] = fileparts(src(1));
106-
%
107-
% % name of MEX target function is name of first source file
108-
% plan("mex:" + name) = matlab.buildtool.tasks.MexTask(src, pkg_root, ...
109-
% Description="Build MEX target " + name, ...
110-
% Options=get_compiler_options());
111-
% end
112-
end
113-
114-
end
115-
116-
117-
% function clean_mex(context)
118-
% run(context.Plan, "clean", {"mex"});
119-
% end
120-
121-
122-
function legacy_test(context, sel)
123-
import matlab.unittest.TestSuite
124-
125-
suite = TestSuite.fromFolder(fullfile(context.Plan.RootFolder, 'test'));
126-
suite = suite.selectIf(sel);
127-
128-
runner = testrunner();
129-
130-
r = run(runner, suite);
131-
132-
assert(~isempty(r), "No tests were run")
133-
assertSuccess(r)
134103
end
135104

136105

@@ -143,27 +112,3 @@ function publishTask(context)
143112
"https://github.com/geospace-code/matlab-stdlib", ...
144113
outdir)
145114
end
146-
147-
148-
function srcs = get_mex_sources(build_all)
149-
arguments (Input)
150-
build_all (1,1) logical = false
151-
end
152-
arguments (Output)
153-
srcs cell
154-
end
155-
156-
srcs = {
157-
% "src/remove.cpp", ...
158-
%["src/normalize.cpp", "src/normalize_fs.cpp", "src/pure.cpp"], ...
159-
% "src/set_permissions.cpp"
160-
};
161-
162-
if ~stdlib.has_python() || build_all
163-
srcs{end+1} = "src/is_char_device.cpp";
164-
srcs{end+1} = ["src/is_admin.cpp", "src/admin_fs.cpp"];
165-
% srcs{end+1} = "src/disk_available.cpp";
166-
% srcs{end+1} = "src/disk_capacity.cpp";
167-
end
168-
169-
end

private/clean_mex.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function clean_mex(context)
2+
run(context.Plan, "clean", {"mex"});
3+
end

private/get_mex_sources.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function srcs = get_mex_sources(build_all)
2+
arguments (Input)
3+
build_all (1,1) logical = false
4+
end
5+
arguments (Output)
6+
srcs cell
7+
end
8+
9+
srcs = {
10+
% "src/remove.cpp", ...
11+
%["src/normalize.cpp", "src/normalize_fs.cpp", "src/pure.cpp"], ...
12+
% "src/set_permissions.cpp"
13+
};
14+
15+
if ~stdlib.has_python() || build_all
16+
srcs{end+1} = "src/is_char_device.cpp";
17+
srcs{end+1} = ["src/is_admin.cpp", "src/admin_fs.cpp"];
18+
% srcs{end+1} = "src/disk_available.cpp";
19+
% srcs{end+1} = "src/disk_capacity.cpp";
20+
end
21+
22+
end

private/mex_tasks.m

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function mex_tasks(context)
2+
3+
pkg_root = fullfile(context.Plan.RootFolder, "+stdlib");
4+
test_root = fullfile(context.Plan.RootFolder, "test");
5+
6+
if ~isMATLABReleaseOlderThan("R2024b")
7+
8+
9+
for s = get_mex_sources()
10+
src = s{1};
11+
[~, name] = fileparts(src(1));
12+
13+
% name of MEX target function is name of first source file
14+
context.Plan("mex:" + name) = matlab.buildtool.tasks.MexTask(src, pkg_root, ...
15+
Description="Build MEX target " + name, ...
16+
Options=get_compiler_options());
17+
end
18+
19+
end
20+
21+
context.Plan("clean_mex") = matlab.buildtool.Task(Actions=@clean_mex, Description="Clean only MEX files to enable incremental tests");
22+
23+
if isMATLABReleaseOlderThan('R2025a')
24+
% plan("test:mex") = matlab.buildtool.Task(Actions=@(context) test_main(context, cmex), Dependencies="mex");
25+
26+
context.Plan("test:mex") = matlab.buildtool.tasks.TestTask(...
27+
test_root, Description="Test mex targts",...
28+
Tag="mex", ...
29+
Dependencies="mex", TestResults="TestResults_mex.xml", Strict=true);
30+
else
31+
context.Plan("test:mex") = matlab.buildtool.tasks.TestTask(...
32+
test_root, Description="Test mex targts",...
33+
Tag="mex", ...
34+
SourceFiles=[pkg_root, context.Plan.RootFolder + "/src"], RunOnlyImpactedTests=true,...
35+
Dependencies="mex", TestResults="TestResults_mex.xml", Strict=true);
36+
end
37+
38+
end

test/TestLang.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
classdef TestLang < matlab.unittest.TestCase
2+
3+
methods (TestClassSetup)
4+
function pkg_path(tc)
5+
p = matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))));
6+
tc.applyFixture(p)
7+
end
8+
end
9+
10+
methods (Test, TestTags = "python")
11+
12+
function test_python_home(tc)
13+
tc.assumeTrue(stdlib.has_python(), "Python not available")
14+
tc.verifyNotEmpty(stdlib.python_home())
15+
end
16+
17+
end
18+
19+
end

test/TestSubprocess.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function pkg_path(tc)
1616
end
1717

1818

19-
methods (Test, TestTags=["exe"])
19+
methods (Test, TestTags="exe")
2020

2121
function test_stdout_stderr(tc, lang_out)
2222
import matlab.unittest.constraints.IsFile
@@ -101,7 +101,7 @@ function test_env_run(tc)
101101
end
102102

103103

104-
methods (Test, TestTags=["exe", "java"])
104+
methods (Test, TestTags="java_exe")
105105

106106
function test_Java_stdout_stderr(tc, lang_out)
107107
import matlab.unittest.constraints.IsFile

test/test_main.m

Lines changed: 0 additions & 23 deletions
This file was deleted.

test_main.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function test_main(context, sel)
2+
arguments
3+
context matlab.buildtool.TaskContext {mustBeScalarOrEmpty} = matlab.buildtool.TaskContext.empty
4+
sel {mustBeScalarOrEmpty} = ~HasTag("exe") & ~HasTag("mex")
5+
end
6+
7+
import matlab.unittest.TestRunner
8+
import matlab.unittest.selectors.HasTag
9+
10+
if isempty(context)
11+
cwd = fileparts(mfilename('fullpath'));
12+
else
13+
cwd = context.Plan.RootFolder;
14+
end
15+
test_root = fullfile(cwd, "test");
16+
17+
if isMATLABReleaseOlderThan('R2022b')
18+
suite = testsuite(test_root);
19+
else
20+
suite = testsuite(test_root, 'InvalidFileFoundAction', "error");
21+
end
22+
23+
suite = suite.selectIf(sel);
24+
25+
runner = TestRunner.withTextOutput;
26+
r = runner.run(suite);
27+
28+
assert(~isempty(r), "No tests were run")
29+
assertSuccess(r)
30+
31+
end

0 commit comments

Comments
 (0)