diff --git a/zUtil_OAR/gtCompileFunctions.m b/zUtil_OAR/gtCompileFunctions.m index fb775bffbd57331319c77f7cdf95ccd3853d11f9..5f260195a873d40b7966356ac142dc76060f7be2 100644 --- a/zUtil_OAR/gtCompileFunctions.m +++ b/zUtil_OAR/gtCompileFunctions.m @@ -1,50 +1,52 @@ function gtCompileFunctions( force, mfiles, funcs_to_compile ) - error_log = {}; - wrong_names = {}; force = strcmp(force, 'force'); - tot_keys = fieldnames(mfiles); - if (isempty(funcs_to_compile) ... - || (numel(funcs_to_compile) == 1 && strcmp(funcs_to_compile{1}, 'all')) ) - funcs_to_compile = tot_keys; - else - valid = true(numel(funcs_to_compile), 1); - - for ii = 1:numel(funcs_to_compile) - if (~ismember(funcs_to_compile{ii}, tot_keys)) - valid(ii) = false; - wrong_names(1, end+1) = funcs_to_compile(ii); - end - end + should_compile_all = isempty(funcs_to_compile) ... + || (numel(funcs_to_compile) == 1 && strcmp(funcs_to_compile{1}, 'all')); + all_keys = fieldnames(mfiles); + if (should_compile_all) + wrong_names = {}; + funcs_to_compile = all_keys; + else + valid = ismember(funcs_to_compile, all_keys); + wrong_names = funcs_to_compile(~valid); funcs_to_compile = funcs_to_compile(valid); end funcs_to_compile = reshape(funcs_to_compile, [1 numel(funcs_to_compile)]); + num_funcs = numel(funcs_to_compile); - for funcName = funcs_to_compile - disp(['Checking function: "' funcName{1} '":']) - func = mfiles.(funcName{1}); + error_log = cell(num_funcs, 2); + for ii_f = 1:numel(funcs_to_compile) + func_name = funcs_to_compile{ii_f}; + disp(['Checking function: "' func_name '":']) + func = mfiles.(func_name); mat_file_path = func.('in_mfile'); comp_file_path = func.('out_file'); - [upToDate, msg] = gtCheckFunctionUpToDate(mat_file_path, comp_file_path); + [up_to_date, msg] = gtCheckFunctionUpToDate(mat_file_path, comp_file_path); fprintf(msg); - if (force || ~upToDate) - disp(['Compiling function: ' funcName{1}]); + if (force || ~up_to_date) + disp(['Compiling function: ' func_name]); comp_file_dir = fileparts(comp_file_path); try - gt_mcc(funcName{1}, 'out_path', comp_file_dir) + gtMcc(func_name, 'bin_path', comp_file_dir) catch mexc - error_log(1, end+1) = funcName; + error_log(ii_f, :) = {func_name, mexc}; end end end - for err_msg = error_log - disp(['Error while compiling: ' err_msg{1}]); + errors = find(~isempty(error_log(:, 1))); + for ii_e = 1:numel(errors) + func_name = error_log{errors(ii_e), 1}; + mexc = error_log{errors(ii_e), 2}; + gtPrintException(mexc, ... + sprintf('Could not compile function: %s', func_name)) end + for wr_name = wrong_names disp(['Wrong m-file name: ' wr_name{1}]); end diff --git a/zUtil_OAR/gt_mcc.m b/zUtil_OAR/gtMcc.m similarity index 68% rename from zUtil_OAR/gt_mcc.m rename to zUtil_OAR/gtMcc.m index 33de6f29e564e634ece49eb0a106ade74c59d9a4..15a71a75a6a453ab4e7de3c1195e9296caf64c58 100644 --- a/zUtil_OAR/gt_mcc.m +++ b/zUtil_OAR/gtMcc.m @@ -1,7 +1,7 @@ -function gt_mcc(myfunctionname, varargin) +function gtMcc(myfunctionname, varargin) % gt_mcc.m Compiles an executable and puts it in the right place if (isempty(whos('global', 'GT_MATLAB_HOME'))) - gtError('COMPILE:no_such_variable', ... + error('COMPILE:no_such_variable', ... ['GT_MATLAB_HOME variable doesn''t exist in global workspace, '... 'your environment is not sane, and you need to either ' ... 're-initialise or re-run matlab.']) @@ -23,30 +23,24 @@ function gt_mcc(myfunctionname, varargin) end % Parsing arguments - conf = []; - conf.not_really = false; - conf.out_path = ''; - conf.licence_warning = false; - + conf = struct( ... + 'dry_run', false, ... + 'bin_path', fullfile(GT_MATLAB_HOME, 'bin', 'compiled'), ... + 'licence_warning', false, ... + 'remove_old', false ); conf = parse_pv_pairs(conf, varargin); - if (isempty(conf.out_path)) - path_for_binaries = fullfile(GT_MATLAB_HOME, 'bin', 'compiled'); - else - path_for_binaries = conf.out_path; - end - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Modify the M name if necessary [~, ~, ext] = fileparts(myfunctionname); - if ~strcmp(ext, '.m') + if (~strcmp(ext, '.m')) myfunctionname = [myfunctionname '.m']; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % check the code is visible at the moment - if ~exist(myfunctionname, 'file') - gtError('gt_mcc:wrong_file_name', ... + if (~exist(myfunctionname, 'file')) + error('gtMcc:wrong_file_name', ... 'Cannot find your function - is it in the path?') end @@ -55,7 +49,7 @@ function gt_mcc(myfunctionname, varargin) globalVars = whos('global'); eval(['global' sprintf(' %s', globalVars.('name'))]); if (isempty(whos('global', 'GT_DB'))) - gtError('COMPILE:no_such_variable', ... + error('gtMcc:no_such_variable', ... ['GT_DB variable doesn''t exist in global workspace, '... 'your environment is not sane, and you need to either ' ... 're-initialise or re-run matlab.']) @@ -65,27 +59,30 @@ function gt_mcc(myfunctionname, varargin) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % startup the compiler disp('Starting to compile - this may take a few minutes...'); - disp('- Removing previously compiled code'); - compFile = fullfile(path_for_binaries, [myfunctionname(1:end-2)]); - runFile = fullfile(path_for_binaries, ['run_' myfunctionname(1:end-1) 'sh']); - filesToDelele = {compFile, runFile}; - for fileToDelele = filesToDelele - if (conf.not_really) - disp(['I should now be deleting: ' fileToDelele{1}]); - elseif exist(fileToDelele{1}, 'file') - delete(fileToDelele{1}); + if (conf.remove_old) + fprintf('- Removing previously compiled code..'); + compFile = fullfile(conf.bin_path, myfunctionname(1:end-2)); + runFile = fullfile(conf.bin_path, ['run_' myfunctionname(1:end-1) 'sh']); + filesToDelele = {compFile, runFile}; + for fileToDelele = filesToDelele + if (conf.dry_run) + disp(['I should now be deleting: ' fileToDelele{1}]); + elseif exist(fileToDelele{1}, 'file') + delete(fileToDelele{1}); + end end + fprintf('\b\b: Done.\n') end - disp(['- Placing result in ' path_for_binaries]); - if (conf.not_really) - cmd = sprintf('mcc -m "%s" -d "%s" -a workspaceGlobal.mat', myfunctionname, path_for_binaries); + disp(['- Placing binary in: ' conf.bin_path]); + if (conf.dry_run) + cmd = sprintf('mcc -m "%s" -d "%s" -a workspaceGlobal.mat', myfunctionname, conf.bin_path); disp(['I should now be executing: ''' cmd '''']); else try - mcc('-m', myfunctionname, '-d', path_for_binaries, '-a', 'workspaceGlobal.mat'); + mcc('-m', myfunctionname, '-d', conf.bin_path, '-a', 'workspaceGlobal.mat'); catch mexc - if gtCheckExceptionType(mexc, 'mcc_err_checkout_failed') + if (gtCheckExceptionType(mexc, 'mcc_err_checkout_failed')) disp('Could not get a compiler license.'); disp('Surf to http://compweb/public/nice/matlab_licence.php'); disp('and call the person with the compiler license to see if you could use it!');