# HG changeset patch # User Eugenio Gianniti # Date 1402752463 -7200 # Node ID e3f57f92fa667feb7321a038ee61caf9a052b6de # Parent 1a3674836579f4ac8cd7d265bc8b8254042ef359 Avoid just-in-time compilation when not needed * inst/private/check_hash.m: check whether the previous compilation used the same ufl file * inst/private/save_hash.m: save to disk ufl file's md5sum for future comparison * inst/private/check_oct_files.m: ensure the expected oct files are present * inst/import_ufl_*.m: add checks using the logic above diff -r 1a3674836579 -r e3f57f92fa66 inst/import_ufl_BilinearForm.m --- a/inst/import_ufl_BilinearForm.m Fri Jun 13 18:45:40 2014 +0200 +++ b/inst/import_ufl_BilinearForm.m Sat Jun 14 15:27:43 2014 +0200 @@ -35,24 +35,27 @@ error ("import_ufl_BilinearForm: first argument is not a valid string"); endif - n = length (mfilename ("fullpath")) - length (mfilename()); - path = strtrunc(mfilename ("fullpath"), n); + if (check_hash (var_prob) || ! check_oct_files (var_prob, "BilinearForm")) + n = length (mfilename ("fullpath")) - length (mfilename()); + path = strtrunc(mfilename ("fullpath"), n); - private = fullfile (path, "include/"); - output = generate_rhs (var_prob); - output += generate_makefile (var_prob, private); - if output != 0 - error ("Compilation failed"); - else - [output, textfile] = system (sprintf ("make -f Makefile_%s rhs", var_prob)); + private = fullfile (path, "include/"); + output = generate_rhs (var_prob); + output += generate_makefile (var_prob, private); if output != 0 - display (text); error ("Compilation failed"); - endif - [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); - if output != 0 - display (text); - error ("Compilation failed"); + else + [output, textfile] = system (sprintf ("make -f Makefile_%s rhs", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + save_hash (var_prob); endif endif endfunction diff -r 1a3674836579 -r e3f57f92fa66 inst/import_ufl_FunctionSpace.m --- a/inst/import_ufl_FunctionSpace.m Fri Jun 13 18:45:40 2014 +0200 +++ b/inst/import_ufl_FunctionSpace.m Sat Jun 14 15:27:43 2014 +0200 @@ -33,24 +33,27 @@ error ("import_ufl_FunctionSpace: first argument is not a valid string"); endif - n = length (mfilename ("fullpath")) - length (mfilename()); - path = strtrunc(mfilename ("fullpath"), n); + if (check_hash (var_prob) || ! check_oct_files (var_prob, "FunctionSpace")) + n = length (mfilename ("fullpath")) - length (mfilename()); + path = strtrunc(mfilename ("fullpath"), n); - private = fullfile (path, "include/"); - output = generate_fs (var_prob); - output += generate_makefile (var_prob, private); - if output != 0 - error ("Compilation failed"); - else - [output, textfile] = system (sprintf ("make -f Makefile_%s fs", var_prob)); + private = fullfile (path, "include/"); + output = generate_fs (var_prob); + output += generate_makefile (var_prob, private); if output != 0 - display (text); error ("Compilation failed"); - endif - [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); - if output != 0 - display (text); - error ("Compilation failed"); + else + [output, textfile] = system (sprintf ("make -f Makefile_%s fs", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + save_hash (var_prob); endif endif diff -r 1a3674836579 -r e3f57f92fa66 inst/import_ufl_Functional.m --- a/inst/import_ufl_Functional.m Fri Jun 13 18:45:40 2014 +0200 +++ b/inst/import_ufl_Functional.m Sat Jun 14 15:27:43 2014 +0200 @@ -32,24 +32,27 @@ error ("import_ufl_Functional: first argument is not a valid string"); endif - n = length (mfilename ("fullpath")) - length (mfilename()); - path = strtrunc(mfilename ("fullpath"), n); + if (check_hash (var_prob) || ! check_oct_files (var_prob, "Functional")) + n = length (mfilename ("fullpath")) - length (mfilename()); + path = strtrunc(mfilename ("fullpath"), n); - private = fullfile (path, "include/"); - output = generate_fun (var_prob); - output += generate_makefile (var_prob, private); - if output != 0 - error ("Compilation failed"); - else - [output, textfile] = system (sprintf ("make -f Makefile_%s fun", var_prob)); + private = fullfile (path, "include/"); + output = generate_fun (var_prob); + output += generate_makefile (var_prob, private); if output != 0 - display (text); error ("Compilation failed"); - endif - [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); - if output != 0 - display (text); - error ("Compilation failed"); + else + [output, textfile] = system (sprintf ("make -f Makefile_%s fun", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + save_hash (var_prob); endif endif endfunction diff -r 1a3674836579 -r e3f57f92fa66 inst/import_ufl_LinearForm.m --- a/inst/import_ufl_LinearForm.m Fri Jun 13 18:45:40 2014 +0200 +++ b/inst/import_ufl_LinearForm.m Sat Jun 14 15:27:43 2014 +0200 @@ -33,26 +33,28 @@ error ("import_ufl_LinearForm: first argument is not a valid string"); endif - n = length (mfilename ("fullpath")) - length (mfilename()); - path = strtrunc(mfilename ("fullpath"), n); + if (check_hash (var_prob) || ! check_oct_files (var_prob, "LinearForm")) + n = length (mfilename ("fullpath")) - length (mfilename()); + path = strtrunc(mfilename ("fullpath"), n); - private = fullfile (path, "include/"); + private = fullfile (path, "include/"); - output = generate_lhs (var_prob); - output += generate_makefile (var_prob, private); - if output != 0 - error ("Compilation failed"); - else - [output, textfile] = system (sprintf ("make -f Makefile_%s lhs", var_prob)); + output = generate_lhs (var_prob); + output += generate_makefile (var_prob, private); if output != 0 - display (text); error ("Compilation failed"); - endif - [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); - if output != 0 - display (text); - error ("Compilation failed"); + else + [output, textfile] = system (sprintf ("make -f Makefile_%s lhs", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + save_hash (var_prob); endif endif - endfunction diff -r 1a3674836579 -r e3f57f92fa66 inst/import_ufl_Problem.m --- a/inst/import_ufl_Problem.m Fri Jun 13 18:45:40 2014 +0200 +++ b/inst/import_ufl_Problem.m Sat Jun 14 15:27:43 2014 +0200 @@ -32,26 +32,29 @@ error ("import_ufl_Problem: first argument is not a valid string"); endif - n = length (mfilename ("fullpath")) - length (mfilename()); - path = strtrunc(mfilename ("fullpath"), n); + if (check_hash (var_prob) || ! check_oct_files (var_prob, "Problem")) + n = length (mfilename ("fullpath")) - length (mfilename()); + path = strtrunc(mfilename ("fullpath"), n); - private = fullfile (path, "include/"); - output = generate_fs (var_prob); - output += generate_rhs (var_prob); - output += generate_lhs (var_prob); - output += generate_makefile (var_prob, private); - if output != 0 - error ("Compilation failed"); - else - [output, textfile] = system (sprintf ("make -f Makefile_%s all", var_prob)); + private = fullfile (path, "include/"); + output = generate_fs (var_prob); + output += generate_rhs (var_prob); + output += generate_lhs (var_prob); + output += generate_makefile (var_prob, private); if output != 0 - display (text); error ("Compilation failed"); - endif - [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); - if output != 0 - display (text); - error ("Compilation failed"); + else + [output, textfile] = system (sprintf ("make -f Makefile_%s all", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + [output, textfile] = system (sprintf ("make -f Makefile_%s clean", var_prob)); + if output != 0 + display (text); + error ("Compilation failed"); + endif + save_hash (var_prob); endif endif diff -r 1a3674836579 -r e3f57f92fa66 inst/private/check_hash.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inst/private/check_hash.m Sat Jun 14 15:27:43 2014 +0200 @@ -0,0 +1,36 @@ +## Copyright (C) 2014 Eugenio Gianniti +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . + + +## -*- texinfo -*- +## function for internal usage only +## @end deftypefn + +function differs = check_hash (ufl_name) + if (! ischar (ufl_name)) + error ("check_hash: wrong input argument"); + else + filename = [ufl_name, ".ufl"]; + hashfile = [filename, ".md5sum"]; + [~, err, ~] = stat (hashfile); + if (err == -1) + differs = true; + else + oldhash = fileread (hashfile); + newhash = md5sum (filename); + differs = ! strcmp (oldhash, newhash); + endif + endif +endfunction \ No newline at end of file diff -r 1a3674836579 -r e3f57f92fa66 inst/private/check_oct_files.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inst/private/check_oct_files.m Sat Jun 14 15:27:43 2014 +0200 @@ -0,0 +1,56 @@ +## Copyright (C) 2014 Eugenio Gianniti +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . + + +## -*- texinfo -*- +## function for internal usage only +## @end deftypefn + +function found = check_oct_files (ufl_name, type) + persistent opts = {"BilinearForm", + "Functional", + "FunctionSpace", + "LinearForm", + "Problem"}; + + if (! ischar (ufl_name)) + error ("check_oct_files: invalid argument"); + endif + type = validatestring (type, opts, "check_oct_files", "type"); + + [~, err, ~] = stat ([ufl_name, "_BilinearForm.oct"]); + bilinearform = (err == 0); + [~, err, ~] = stat ([ufl_name, "_FunctionSpace.oct"]); + functionspace = (err == 0); + [~, err, ~] = stat ([ufl_name, "_LinearForm.oct"]); + linearform = (err == 0); + [~, err, ~] = stat ([ufl_name, "_Functional.oct"]); + functional = (err == 0); + + switch (type) + case "BilinearForm" + found = bilinearform; + case "Functional" + found = functional; + case "FunctionSpace" + found = functionspace; + case "LinearForm" + found = linearform; + case "Problem" + found = bilinearform && linearform && functionspace; + otherwise + error ("check_oct_files: unrecognized option"); + endswitch +endfunction \ No newline at end of file diff -r 1a3674836579 -r e3f57f92fa66 inst/private/save_hash.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inst/private/save_hash.m Sat Jun 14 15:27:43 2014 +0200 @@ -0,0 +1,33 @@ +## Copyright (C) 2014 Eugenio Gianniti +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . + + +## -*- texinfo -*- +## function for internal usage only +## @end deftypefn + +function save_hash (ufl_name) + if (! ischar (ufl_name)) + error ("save_hash: wrong input argument"); + else + filename = [ufl_name, ".ufl"]; + hash = md5sum (filename); + fid = fopen ([filename, ".md5sum"], "w"); + if (is_valid_file_id (fid)) + fputs (fid, hash); + fclose (fid); + endif + endif +endfunction \ No newline at end of file