FIX: Hardcoded paths in data/utilities/compareDeps.py.in
[freefoam.git] / data / utilities / compareDeps.py.in
blob3101376b5a2930f8e231e19eb1478fe4bfee1183
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 2 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, write to the Free Software Foundation,
30 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 # Script
33 # compareDeps
35 # Description
36 # Compares the dependency files generated by generateOpenFOAMDeps.py and
37 # compiling with -MD.
39 #------------------------------------------------------------------------------
41 """Usage: generateOpenFOAMDeps <WM_PROJECT_DIR>
43 Compares the dependency files generated by generateOpenFOAMDeps.py and
44 compiling with -MD.
46 Options
47 -------
48 <WM_PROJECT_DIR> Top-level OpenFOAM source directory
50 """
52 import sys
53 sys.path.insert(0, '@FOAM_PYTHON_DIR@')
54 from FreeFOAM.compat import *
55 import re
56 import os
57 import os.path as op
59 # argument parsing
60 args = sys.argv[1:]
61 if len(args) != 1:
62 echo('Error: the path to the OpenFOAM installation is required',
63 file=sys.stderr)
64 sys.exit(1)
66 WM_PROJECT_DIR=op.abspath(args[0])
68 blacklistPatterns = (
69 re.compile(r'ImplI?\.C\.ffd$'),
70 re.compile(r'[pP]rintStack\.C\.ffd$'),
71 re.compile(r'PDRFoamAutoRefine\.C\.ffd$'),
72 re.compile(r'src/OpenFOAM/db/dlLibraryTable/dlLibraryTable'),
75 def checkBlacklistPatterns(f):
76 for p in blacklistPatterns:
77 if p.search(f) is not None:
78 return True
79 return False
81 blacklistDepsPatterns = (
82 re.compile(r'src/OpenFOAM/db/dlLibraryTable'),
83 re.compile(r'src/OpenFOAM/primitives/Lists/fileNameList.H'),
84 re.compile(r'src/OpenFOAM/primitives/ints/long/long.H'),
85 re.compile(r'src/OpenFOAM/include/OSspecific.H'),
88 def removeBlacklistDeps(l):
89 result = list(l)
90 for p in blacklistDepsPatterns:
91 result = list(filter(lambda f: p.search(f) is None, result))
92 return result
94 substPatterns = (
95 (re.compile(r'_(\.C\.ffd)$'), r'\1'),
96 (re.compile(r'_subst(\.C\.ffd)$'), r'\1'),
97 (re.compile(r'mpi(PstreamGlobals\.C\.ffd)$'), r'\1'),
98 (re.compile(r'\.C.ffd$'), r'.ofd'),
101 def applySubstPatterns(f):
102 result = f
103 for p, r in substPatterns:
104 result = p.sub(r, result)
105 return result
107 mpiPatterns = (
108 re.compile(r'parMetisDecomp\.C\.ffd$'),
109 re.compile(r'decompositionMethod\.C\.ffd$'),
110 re.compile(r'hierarchGeomDecomp\.C\.ffd$'),
111 re.compile(r'geomDecomp\.C\.ffd$'),
112 re.compile(r'manualDecomp\.C\.ffd$'),
113 re.compile(r'simpleGeomDecomp\.C\.ffd$'),
114 re.compile(r'mpiPstreamGlobals\.C\.ffd$'),
117 def checkMpiPatterns(f):
118 for p in mpiPatterns:
119 if p.search(f) is not None:
120 return True
121 return False
123 SOURCE_DIR = "@PROJECT_SOURCE_DIR@"
124 BINARY_DIR = "@PROJECT_BINARY_DIR@"
126 for parent, dirs, files in os.walk(BINARY_DIR):
127 for f in filter(lambda f: op.splitext(f)[1]=='.ffd', files):
128 f = op.join(parent, f)
129 # skip blacklisted items
130 if checkBlacklistPatterns(f):
131 continue
132 # construct name in OpenFOAM
133 i = f.rfind('/', 0, f.find('@CMAKE_FILES_DIRECTORY@')+1)
134 d = op.join(WM_PROJECT_DIR, op.relpath(f[:i], BINARY_DIR), 'Make',
135 'linux64FreeFOAMDPDep')
136 if checkMpiPatterns(f):
137 d += 'SYSTEMOPENMPI'
138 of = op.basename(f)
139 of = applySubstPatterns(of)
140 of = op.join(d, of)
141 if not op.isfile(of):
142 echo('ERROR: failed to find', of, file=sys.stderr)
143 sys.exit(1)
144 # read files
145 ffdeps = removeBlacklistDeps(map(str.strip, open(f, 'rt').readlines()))
146 src = ffdeps[0]
147 ffdeps = set(ffdeps)
148 ofdeps = set(removeBlacklistDeps(map(
149 str.strip, open(of, 'rt').readlines())))
150 ffadd = ffdeps - ofdeps
151 ffrem = ofdeps - ffdeps
152 if len(ffadd) or len(ffrem):
153 echo(src+':')
154 if len(ffadd):
155 echo(' +', '\n + '.join(ffadd))
156 if len(ffrem):
157 echo(' -', '\n - '.join(ffrem))
159 # ------------------------- vim: set sw=3 sts=3 et: --------------- end-of-file