From 5ff3060a735ae547afa0bb60582376c7645a3b9b Mon Sep 17 00:00:00 2001 From: Yoann Guilhem <yoann.guilhem@esrf.fr> Date: Wed, 10 Apr 2013 15:07:50 +0200 Subject: [PATCH] Add a check for compiled functions at DCT matlab startup Signed-off-by: Yoann Guilhem <yoann.guilhem@esrf.fr> --- dct_launch.py | 5 ++++ initialise_gt.m | 26 +++++++++++++++++++- zUtil_OAR/gtCheckFunctionUpToDate.m | 18 +++++++------- zUtil_OAR/gtCompileFunctions.m | 12 ++++----- zUtil_Python/dct_compile_matlab_functions.py | 9 ++++--- 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/dct_launch.py b/dct_launch.py index df3c4200..d169b560 100755 --- a/dct_launch.py +++ b/dct_launch.py @@ -59,6 +59,7 @@ class DCTLauncher(object): raise ValueError("Not recognized command: %s" % self.command) def _launchMatlab(self): + from zUtil_Python.dct_compile_matlab_functions import FunctionsBuilder if os.path.exists(self.confPath) is False: raise SystemError("File conf.xml not found in DCT directory") @@ -69,6 +70,10 @@ class DCTLauncher(object): else: invoker = dct.dct_matlab_invocation.DCTMatlabInvocation(dct_dir = self.dct_dir, \ extra_args = self.args) + + func_builder = FunctionsBuilder.getInstanceFromArgs([], dct_dir = self.dct_dir) + func_builder.generateMfile() + invoker.invoke() def _launchUpdate(self): diff --git a/initialise_gt.m b/initialise_gt.m index 4f7188dd..48c9ee36 100644 --- a/initialise_gt.m +++ b/initialise_gt.m @@ -214,6 +214,30 @@ function initialise_gt(ignore_id19) 'Couldn''t find matlab version in conf.xml'); end - disp('Finished adding.') + disp('Finished adding.'); + + disp('Checking compiled functions...'); + currentDir = pwd; + cd(fullfile(GT_MATLAB_HOME, 'bin', 'scripts')); + mFiles = compile(false, false); + funcNames = fieldnames(mFiles); + + defaultColor = sprintf(gtGetANSIColour()); + yellowColor = sprintf(gtGetANSIColour('yellow')); + for funcName = reshape(funcNames, [1 numel(funcNames)]) + func = mFiles.(funcName{1}); + + mat_file_path = func.('in_mfile'); + comp_file_path = func.('out_file'); + [upToDate, msg] = gtCheckFunctionUpToDate(mat_file_path, comp_file_path); + if (~upToDate) + out = [yellowColor 'Function should be recompiled: ' ... + defaultColor funcName{1}]; + disp(out); + fprintf(msg); + end + end + cd(currentDir); + disp('Finished checking.'); end diff --git a/zUtil_OAR/gtCheckFunctionUpToDate.m b/zUtil_OAR/gtCheckFunctionUpToDate.m index 846350e9..73d37cc6 100644 --- a/zUtil_OAR/gtCheckFunctionUpToDate.m +++ b/zUtil_OAR/gtCheckFunctionUpToDate.m @@ -1,10 +1,6 @@ -function isUpToDate = gtCheckFunctionUpToDate(funcName, outputBinary, verbose) +function [isUpToDate, msg] = gtCheckFunctionUpToDate(funcName, outputBinary) % GTCHECKFUNCTIONUPTODATE Checks if a compiled function is up to date. - if (~exist('verbose', 'var')) - verbose = true; - end - srcFileInfo = dir(funcName); if (isempty(srcFileInfo)) error('CHECK:wrong_function_path', ... @@ -14,19 +10,23 @@ function isUpToDate = gtCheckFunctionUpToDate(funcName, outputBinary, verbose) binFileInfo = dir(outputBinary); if (~isempty(binFileInfo)) if (srcFileInfo(1).datenum > binFileInfo(1).datenum) - if (verbose), fprintf(' + Binary is outdated.\n'); end + msg = sprintf(' + Binary is outdated.\n'); isUpToDate = false; else deps = gtGetFunctionDeps({funcName}, {}, 'matlab_(\d*)(.?)/toolbox'); depsToRebuild = gtCheckFunctionsTimestamp(deps, binFileInfo(1).datenum); isUpToDate = isempty(depsToRebuild); - if (~isUpToDate && verbose) - cellfun(@(x)fprintf(' + "%s" was modified after it.\n', x), ... + + if (~isUpToDate) + msg = cellfun(@(x){sprintf(' + "%s" was modified after it.\n', x)}, ... depsToRebuild); + msg = [msg{:}]; + else + msg = sprintf('* Is up to date.\n'); end end else - if (verbose), fprintf(' + Binary doesn''t exist.\n'); end + msg = sprintf(' + Binary doesn''t exist.\n'); isUpToDate = false; end end diff --git a/zUtil_OAR/gtCompileFunctions.m b/zUtil_OAR/gtCompileFunctions.m index 3cbb2b37..c147a8aa 100644 --- a/zUtil_OAR/gtCompileFunctions.m +++ b/zUtil_OAR/gtCompileFunctions.m @@ -28,22 +28,22 @@ function gtCompileFunctions( force, mfiles, funcs_to_compile ) mat_file_path = func.('in_mfile'); comp_file_path = func.('out_file'); - if (force || ~gtCheckFunctionUpToDate(mat_file_path, comp_file_path)) - disp('Compiling..') + [upToDate, msg] = gtCheckFunctionUpToDate(mat_file_path, comp_file_path); + disp(msg); + if (force || ~upToDate) + disp('Compiling...'); comp_file_dir = fileparts(comp_file_path); if (~gt_mcc(funcName{1}, 'out_path', comp_file_dir)) error_log(1, end+1) = funcName; end - else - disp('* Is up to date.') end end for err_msg = error_log - disp(['Error while compiling: ' err_msg{1}]) + disp(['Error while compiling: ' err_msg{1}]); end for wr_name = wrong_names - disp(['Wrong m-file name: ' wr_name{1}]) + disp(['Wrong m-file name: ' wr_name{1}]); end end diff --git a/zUtil_Python/dct_compile_matlab_functions.py b/zUtil_Python/dct_compile_matlab_functions.py index 965a36ae..1f1e226d 100755 --- a/zUtil_Python/dct_compile_matlab_functions.py +++ b/zUtil_Python/dct_compile_matlab_functions.py @@ -109,7 +109,7 @@ class FunctionsBuilder(object): searchPatterns = [ ] for method in FunctionsBuilder.submitMethods: regexpString = '[^%]*\s*' + method + "\s*\(\s*'.*'" - print('Regular expression: "' + regexpString + '"') + #print('Regular expression: "' + regexpString + '"') regexp = re.compile(regexpString) searchPatterns.append(regexp) @@ -175,7 +175,7 @@ class FunctionsBuilder(object): os.makedirs(self.script_dir) DCTOutput.printSubJob("Generating m-file that will compile those Functions..") - script_content = [ "function compile(force, varargin)\n\n", + script_content = [ "function varargout = compile(force, doCompile, varargin)\n\n", "mfiles = [];\n" ] for func in self.compile_records: out_file = self.compile_records[func][0] @@ -183,7 +183,8 @@ class FunctionsBuilder(object): script_content.append("mfiles.('%s') = struct( ...\n" % func) script_content.append(" 'out_file', '%s', ...\n" % out_file) script_content.append(" 'in_mfile', '%s' );\n" % in_mfile) - script_content.append("\ngtCompileFunctions(force, mfiles, varargin)\nend\n") + script_content.append("\nif (nargout > 0)\n varargout{1} = mfiles;\nend\n") + script_content.append("\nif (doCompile)\n gtCompileFunctions(force, mfiles, varargin)\nend\n\nend % end of function\n") script_loc = os.path.join(self.script_dir, 'compile.m') DCTOutput.printSubJob("Writing '%s' script to disk.." % script_loc) @@ -205,7 +206,7 @@ class FunctionsBuilder(object): compile_args = "'no-force" compile_args = "','".join([compile_args] + self.mfiles_to_consider) + "'" - cmd = "compile(%s);quit;" % compile_args + cmd = "compile(%s,true);quit;" % compile_args invoker = dct_matlab_invocation.DCTMatlabInvocation(dct_dir = self.dct_dir, \ work_dir = self.script_dir, \ -- GitLab