ENH: Update FreeFOAM contributions to GPL v3
[freefoam.git] / data / utilities / compareDeps.py.in
blob58603c16e711e54110109a5c006e25c16afa00d4
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2012 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software: you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation, either version 3 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM. If not, see <http://www.gnu.org/licenses/>.
31 # Script
32 # compareDeps
34 # Description
35 # Compares the dependency files generated by generateOpenFOAMDeps.py and
36 # compiling with -MD.
38 #------------------------------------------------------------------------------
40 """Usage: generateOpenFOAMDeps <WM_PROJECT_DIR>
42 Compares the dependency files generated by generateOpenFOAMDeps.py and
43 compiling with -MD.
45 Options
46 -------
47 <WM_PROJECT_DIR> Top-level OpenFOAM source directory
49 """
51 import sys
52 sys.path.insert(0, '@FOAM_PYTHON_DIR@')
53 from FreeFOAM.compat import *
54 import re
55 import os
56 import os.path as op
58 # argument parsing
59 args = sys.argv[1:]
60 if len(args) != 1:
61 echo('Error: the path to the OpenFOAM installation is required',
62 file=sys.stderr)
63 sys.exit(1)
65 WM_PROJECT_DIR=op.abspath(args[0])
67 blacklistPatterns = (
68 re.compile(r'ImplI?\.C\.ffd$'),
69 re.compile(r'[pP]rintStack\.C\.ffd$'),
70 re.compile(r'PDRFoamAutoRefine\.C\.ffd$'),
71 re.compile(r'src/OpenFOAM/db/dlLibraryTable/dlLibraryTable'),
74 def checkBlacklistPatterns(f):
75 for p in blacklistPatterns:
76 if p.search(f) is not None:
77 return True
78 return False
80 blacklistDepsPatterns = (
81 re.compile(r'src/OpenFOAM/db/dlLibraryTable'),
82 re.compile(r'src/OpenFOAM/primitives/Lists/fileNameList.H'),
83 re.compile(r'src/OpenFOAM/primitives/ints/long/long.H'),
84 re.compile(r'src/OpenFOAM/include/OSspecific.H'),
87 def removeBlacklistDeps(l):
88 result = list(l)
89 for p in blacklistDepsPatterns:
90 result = list(filter(lambda f: p.search(f) is None, result))
91 return result
93 substPatterns = (
94 (re.compile(r'_(\.C\.ffd)$'), r'\1'),
95 (re.compile(r'_subst(\.C\.ffd)$'), r'\1'),
96 (re.compile(r'mpi(PstreamGlobals\.C\.ffd)$'), r'\1'),
97 (re.compile(r'\.C.ffd$'), r'.ofd'),
100 def applySubstPatterns(f):
101 result = f
102 for p, r in substPatterns:
103 result = p.sub(r, result)
104 return result
106 mpiPatterns = (
107 re.compile(r'parMetisDecomp\.C\.ffd$'),
108 re.compile(r'decompositionMethod\.C\.ffd$'),
109 re.compile(r'hierarchGeomDecomp\.C\.ffd$'),
110 re.compile(r'geomDecomp\.C\.ffd$'),
111 re.compile(r'manualDecomp\.C\.ffd$'),
112 re.compile(r'simpleGeomDecomp\.C\.ffd$'),
113 re.compile(r'mpiPstreamGlobals\.C\.ffd$'),
116 def checkMpiPatterns(f):
117 for p in mpiPatterns:
118 if p.search(f) is not None:
119 return True
120 return False
122 SOURCE_DIR = "@PROJECT_SOURCE_DIR@"
123 BINARY_DIR = "@PROJECT_BINARY_DIR@"
125 for parent, dirs, files in os.walk(BINARY_DIR):
126 for f in filter(lambda f: op.splitext(f)[1]=='.ffd', files):
127 f = op.join(parent, f)
128 # skip blacklisted items
129 if checkBlacklistPatterns(f):
130 continue
131 # construct name in OpenFOAM
132 i = f.rfind('/', 0, f.find('@CMAKE_FILES_DIRECTORY@')+1)
133 d = op.join(WM_PROJECT_DIR, op.relpath(f[:i], BINARY_DIR), 'Make',
134 'linux64FreeFOAMDPDep')
135 if checkMpiPatterns(f):
136 d += 'SYSTEMOPENMPI'
137 of = op.basename(f)
138 of = applySubstPatterns(of)
139 of = op.join(d, of)
140 if not op.isfile(of):
141 echo('ERROR: failed to find', of, file=sys.stderr)
142 sys.exit(1)
143 # read files
144 ffdeps = removeBlacklistDeps(map(str.strip, open(f, 'rt').readlines()))
145 src = ffdeps[0]
146 ffdeps = set(ffdeps)
147 ofdeps = set(removeBlacklistDeps(map(
148 str.strip, open(of, 'rt').readlines())))
149 ffadd = ffdeps - ofdeps
150 ffrem = ofdeps - ffdeps
151 if len(ffadd) or len(ffrem):
152 echo(src+':')
153 if len(ffadd):
154 echo(' +', '\n + '.join(ffadd))
155 if len(ffrem):
156 echo(' -', '\n - '.join(ffrem))
158 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file