|
1 | 1 | %% TOOLBOX_USED list all Matlab toolboxes used by all functions in pkgPath |
2 | 2 | % |
3 | 3 | %%% inputs |
4 | | -% * pkgPath: path to user namespace or file. Example: '+stdlib' or 'stdlib.cpu_arch' |
| 4 | +% * pkgPath: path to user namespace or file. Example: 'stdlib' or 'stdlib.cpu_arch' |
5 | 5 | %%% Outputs |
6 | 6 | % * tbxMathworks: Mathworks toolbox names used |
7 | 7 | % * funUser: all user function files under pkgPath |
8 | 8 |
|
9 | | -function [tbxMathworks, funUser] = toolbox_used(pkgPath) |
| 9 | +function [tbxMathworks, funUser] = toolbox_used(name) |
10 | 10 |
|
11 | | -[user, mathworks] = matlab.codetools.requiredFilesAndProducts(pkgPath); |
| 11 | +n = name; |
| 12 | + |
| 13 | +try |
| 14 | + |
| 15 | + f = namespaceFunctions(name); |
| 16 | + if ~isempty(f) |
| 17 | + n = f(1).NamespaceName + "." + string({f.Name}); |
| 18 | + end |
| 19 | + |
| 20 | +catch e |
| 21 | + |
| 22 | + if ~strcmp(e.identifier, 'MATLAB:UndefinedFunction') |
| 23 | + rethrow(e) |
| 24 | + end |
| 25 | + |
| 26 | +end |
| 27 | + |
| 28 | +if ispc() |
| 29 | + old = getenv('KMP_DUPLICATE_LIB_OK'); |
| 30 | + setenv('KMP_DUPLICATE_LIB_OK', 'TRUE'); |
| 31 | + |
| 32 | + % otherwise, |
| 33 | + % matlab -batch "buildtool test" |
| 34 | + % or |
| 35 | + % matlab -batch "stdlib.toolbox_used('stdlib')" |
| 36 | + % crash Matlab with: |
| 37 | + % OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized. |
| 38 | + % |
| 39 | + % calling toolbox_used on any one function doesn't fail. |
| 40 | +end |
| 41 | + |
| 42 | +try |
| 43 | + [user, mathworks] = matlab.codetools.requiredFilesAndProducts(n); |
| 44 | +catch e |
| 45 | + if ispc() |
| 46 | + setenv('KMP_DUPLICATE_LIB_OK', old) |
| 47 | + end |
| 48 | + rethrow(e) |
| 49 | +end |
| 50 | + |
| 51 | +if ispc() |
| 52 | + setenv('KMP_DUPLICATE_LIB_OK', old) |
| 53 | +end |
12 | 54 |
|
13 | 55 | tbxMathworks = string({mathworks.Name}).'; |
14 | 56 |
|
|
0 commit comments