Skip to content
Snippets Groups Projects
Commit 5ff3060a authored by Yoann Guilhem's avatar Yoann Guilhem Committed by Nicola Vigano
Browse files

Add a check for compiled functions at DCT matlab startup

parent 920219e7
No related branches found
No related tags found
No related merge requests found
...@@ -59,6 +59,7 @@ class DCTLauncher(object): ...@@ -59,6 +59,7 @@ class DCTLauncher(object):
raise ValueError("Not recognized command: %s" % self.command) raise ValueError("Not recognized command: %s" % self.command)
def _launchMatlab(self): def _launchMatlab(self):
from zUtil_Python.dct_compile_matlab_functions import FunctionsBuilder
if os.path.exists(self.confPath) is False: if os.path.exists(self.confPath) is False:
raise SystemError("File conf.xml not found in DCT directory") raise SystemError("File conf.xml not found in DCT directory")
...@@ -69,6 +70,10 @@ class DCTLauncher(object): ...@@ -69,6 +70,10 @@ class DCTLauncher(object):
else: else:
invoker = dct.dct_matlab_invocation.DCTMatlabInvocation(dct_dir = self.dct_dir, \ invoker = dct.dct_matlab_invocation.DCTMatlabInvocation(dct_dir = self.dct_dir, \
extra_args = self.args) extra_args = self.args)
func_builder = FunctionsBuilder.getInstanceFromArgs([], dct_dir = self.dct_dir)
func_builder.generateMfile()
invoker.invoke() invoker.invoke()
def _launchUpdate(self): def _launchUpdate(self):
......
...@@ -214,6 +214,30 @@ function initialise_gt(ignore_id19) ...@@ -214,6 +214,30 @@ function initialise_gt(ignore_id19)
'Couldn''t find matlab version in conf.xml'); 'Couldn''t find matlab version in conf.xml');
end 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 end
function isUpToDate = gtCheckFunctionUpToDate(funcName, outputBinary, verbose) function [isUpToDate, msg] = gtCheckFunctionUpToDate(funcName, outputBinary)
% GTCHECKFUNCTIONUPTODATE Checks if a compiled function is up to date. % GTCHECKFUNCTIONUPTODATE Checks if a compiled function is up to date.
if (~exist('verbose', 'var'))
verbose = true;
end
srcFileInfo = dir(funcName); srcFileInfo = dir(funcName);
if (isempty(srcFileInfo)) if (isempty(srcFileInfo))
error('CHECK:wrong_function_path', ... error('CHECK:wrong_function_path', ...
...@@ -14,19 +10,23 @@ function isUpToDate = gtCheckFunctionUpToDate(funcName, outputBinary, verbose) ...@@ -14,19 +10,23 @@ function isUpToDate = gtCheckFunctionUpToDate(funcName, outputBinary, verbose)
binFileInfo = dir(outputBinary); binFileInfo = dir(outputBinary);
if (~isempty(binFileInfo)) if (~isempty(binFileInfo))
if (srcFileInfo(1).datenum > binFileInfo(1).datenum) if (srcFileInfo(1).datenum > binFileInfo(1).datenum)
if (verbose), fprintf(' + Binary is outdated.\n'); end msg = sprintf(' + Binary is outdated.\n');
isUpToDate = false; isUpToDate = false;
else else
deps = gtGetFunctionDeps({funcName}, {}, 'matlab_(\d*)(.?)/toolbox'); deps = gtGetFunctionDeps({funcName}, {}, 'matlab_(\d*)(.?)/toolbox');
depsToRebuild = gtCheckFunctionsTimestamp(deps, binFileInfo(1).datenum); depsToRebuild = gtCheckFunctionsTimestamp(deps, binFileInfo(1).datenum);
isUpToDate = isempty(depsToRebuild); 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); depsToRebuild);
msg = [msg{:}];
else
msg = sprintf('* Is up to date.\n');
end end
end end
else else
if (verbose), fprintf(' + Binary doesn''t exist.\n'); end msg = sprintf(' + Binary doesn''t exist.\n');
isUpToDate = false; isUpToDate = false;
end end
end end
...@@ -28,22 +28,22 @@ function gtCompileFunctions( force, mfiles, funcs_to_compile ) ...@@ -28,22 +28,22 @@ function gtCompileFunctions( force, mfiles, funcs_to_compile )
mat_file_path = func.('in_mfile'); mat_file_path = func.('in_mfile');
comp_file_path = func.('out_file'); comp_file_path = func.('out_file');
if (force || ~gtCheckFunctionUpToDate(mat_file_path, comp_file_path)) [upToDate, msg] = gtCheckFunctionUpToDate(mat_file_path, comp_file_path);
disp('Compiling..') disp(msg);
if (force || ~upToDate)
disp('Compiling...');
comp_file_dir = fileparts(comp_file_path); comp_file_dir = fileparts(comp_file_path);
if (~gt_mcc(funcName{1}, 'out_path', comp_file_dir)) if (~gt_mcc(funcName{1}, 'out_path', comp_file_dir))
error_log(1, end+1) = funcName; error_log(1, end+1) = funcName;
end end
else
disp('* Is up to date.')
end end
end end
for err_msg = error_log for err_msg = error_log
disp(['Error while compiling: ' err_msg{1}]) disp(['Error while compiling: ' err_msg{1}]);
end end
for wr_name = wrong_names for wr_name = wrong_names
disp(['Wrong m-file name: ' wr_name{1}]) disp(['Wrong m-file name: ' wr_name{1}]);
end end
end end
...@@ -109,7 +109,7 @@ class FunctionsBuilder(object): ...@@ -109,7 +109,7 @@ class FunctionsBuilder(object):
searchPatterns = [ ] searchPatterns = [ ]
for method in FunctionsBuilder.submitMethods: for method in FunctionsBuilder.submitMethods:
regexpString = '[^%]*\s*' + method + "\s*\(\s*'.*'" regexpString = '[^%]*\s*' + method + "\s*\(\s*'.*'"
print('Regular expression: "' + regexpString + '"') #print('Regular expression: "' + regexpString + '"')
regexp = re.compile(regexpString) regexp = re.compile(regexpString)
searchPatterns.append(regexp) searchPatterns.append(regexp)
...@@ -175,7 +175,7 @@ class FunctionsBuilder(object): ...@@ -175,7 +175,7 @@ class FunctionsBuilder(object):
os.makedirs(self.script_dir) os.makedirs(self.script_dir)
DCTOutput.printSubJob("Generating m-file that will compile those Functions..") 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" ] "mfiles = [];\n" ]
for func in self.compile_records: for func in self.compile_records:
out_file = self.compile_records[func][0] out_file = self.compile_records[func][0]
...@@ -183,7 +183,8 @@ class FunctionsBuilder(object): ...@@ -183,7 +183,8 @@ class FunctionsBuilder(object):
script_content.append("mfiles.('%s') = struct( ...\n" % func) script_content.append("mfiles.('%s') = struct( ...\n" % func)
script_content.append(" 'out_file', '%s', ...\n" % out_file) script_content.append(" 'out_file', '%s', ...\n" % out_file)
script_content.append(" 'in_mfile', '%s' );\n" % in_mfile) 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') script_loc = os.path.join(self.script_dir, 'compile.m')
DCTOutput.printSubJob("Writing '%s' script to disk.." % script_loc) DCTOutput.printSubJob("Writing '%s' script to disk.." % script_loc)
...@@ -205,7 +206,7 @@ class FunctionsBuilder(object): ...@@ -205,7 +206,7 @@ class FunctionsBuilder(object):
compile_args = "'no-force" compile_args = "'no-force"
compile_args = "','".join([compile_args] + self.mfiles_to_consider) + "'" 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, \ invoker = dct_matlab_invocation.DCTMatlabInvocation(dct_dir = self.dct_dir, \
work_dir = self.script_dir, \ work_dir = self.script_dir, \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment