forked from WEC-Sim/WEC-Sim_Applications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getTestTargets.m
126 lines (94 loc) · 3.03 KB
/
getTestTargets.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
function getTestTargets(diffFile)
arguments
diffFile (1,1) string = ""
end
% getTestTargets Return modified test directories
%
% Returns a list of target directories in JSON formatted file
% 'folder.json' and a list of required MATLAB products in JSON formatted
% file 'include.json'. A JSON formatted diff file can be passed as an
% argument, otherwise all valid test directories are returned.
if (diffFile ~= "")
targets = getDiffTargets(diffFile);
else
targets = getAllTargets();
end
filename = 'folder.json';
fid = fopen(filename, 'w');
fprintf(fid, '%s', jsonencode(targets));
fclose(fid);
products = getProducts(targets);
include_struct = struct('folder', targets, 'products', products);
include = num2cell(include_struct);
filename = 'include.json';
fid = fopen(filename, 'w');
fprintf(fid, '%s', jsonencode(include));
fclose(fid);
end
function products = getProducts(targets)
arguments
targets (1,:) cell
end
arguments (Output)
products (1, :) cell
end
function products = loadProductFiles(product_file, file_exists)
if ~file_exists
products = "";
return
end
fileID = fopen(product_file);
C = textscan(fileID,'%s');
fclose(fileID);
products = strjoin(C{:, 1});
end
product_files = fullfile(targets, "products.txt");
products = arrayfun(@loadProductFiles, ...
product_files, ...
isfile(product_files), ...
'UniformOutput', 0);
end
function targets = getDiffTargets(diffFile)
arguments
diffFile (1,1) string
end
arguments (Output)
targets (1, :) cell
end
diff = readstruct(diffFile);
max_filtered = strings(1, length(diff.files));
i_filtered = 1;
for path = string({diff.files.path})
bits = split(path, "/");
% Ignore top level files
if isscalar(bits)
continue
end
% Ignore directories that start with . or _
if sum(strncmp(path, [".", "_"], 1))
continue
end
max_filtered(i_filtered) = bits(1);
i_filtered = i_filtered + 1;
end
targets = cellstr(unique(max_filtered(1:i_filtered - 1)));
end
function targets = getAllTargets
arguments (Output)
targets (1, :) cell
end
d = dir();
isub = [d(:).isdir];
all_folders = {d(isub).name};
max_filtered = strings(1, length(all_folders));
i_filtered = 1;
for folder = all_folders
% Ignore directories that start with . or _
if sum(strncmp(folder, [".", "_"], 1))
continue
end
max_filtered(i_filtered) = folder;
i_filtered = i_filtered + 1;
end
targets = cellstr(unique(max_filtered(1:i_filtered - 1)));
end