2 # ***** BEGIN GPL LICENSE BLOCK *****
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # Contributor(s): Campbell Barton
20 # ***** END GPL LICENSE BLOCK *****
24 "/decimate_glut_test/",\
28 "/decimation/intern/future/",\
29 "/TerraplayNetwork/",\
33 from os.path import join, dirname, normpath, abspath
35 base = join(os.path.dirname(__file__), "..", "..")
39 print("Scanning:", base)
45 from os.path import splitext
46 def source_list(path, filename_check=None):
47 for dirpath, dirnames, filenames in os.walk(path):
50 if dirpath.startswith("."):
53 for filename in filenames:
54 if filename_check is None or filename_check(filename):
55 yield os.path.join(dirpath, filename)
58 def is_c_header(filename):
59 ext = splitext(filename)[1]
60 return (ext in (".h", ".hpp", ".hxx"))
62 def is_cmake(filename):
63 ext = splitext(filename)[1]
64 return (ext == ".cmake") or (filename == "CMakeLists.txt")
66 def is_c_header(filename):
67 ext = splitext(filename)[1]
68 return (ext in (".h", ".hpp", ".hxx"))
71 ext = splitext(filename)[1]
72 return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc"))
74 def is_c_any(filename):
75 return is_c(filename) or is_c_header(filename)
82 filen = open(f, "r", encoding="utf8")
96 if not l.startswith("#"):
97 if 'set(SRC' in l or ('set(' in l and l.endswith("SRC")):
98 if len(l.split()) > 1:
99 raise Exception("strict formatting not kept 'set(SRC*' %s:%d" % (f, i))
103 if "list(APPEND SRC" in l:
105 raise Exception("strict formatting not kept 'list(APPEND SRC...)' on 1 line %s:%d" % (f, i))
110 cmake_base = dirname(f)
112 while it is not None:
116 except StopIteration:
122 if not l.startswith("#"):
126 raise Exception("strict formatting not kept '*)' %s:%d" % (f, i))
131 elif l.startswith("$"):
132 print("Cant use var '%s' %s:%d" % (l, f, i))
133 elif len(l.split()) > 1:
134 raise Exception("Multi-line define '%s' %s:%d" % (l, f, i))
136 new_file = normpath(join(cmake_base, l))
138 if is_c_header(new_file):
139 sources_h.append(new_file)
141 sources_c.append(new_file)
143 raise Exception("unknown file type - not c or h %s -> %s" % (f, new_file))
147 global_h.update(set(sources_h))
148 global_c.update(set(sources_c))
150 if not sources_h and not sources_c:
151 raise Exception("No sources %s" % f)
153 sources_h_fs = list(source_list(cmake_base, is_c_header))
154 sources_c_fs = list(source_list(cmake_base, is_c))
156 # find missing C files:
158 for ff in sources_c_fs:
159 if ff not in sources_c:
160 print(" missing: " + ff)
166 for cmake in source_list(base, is_cmake):
175 # First do stupid check, do these files exist?
176 for f in (global_h | global_c):
177 if f.endswith("dna.c"):
180 if not os.path.exists(f):
181 raise Exception("CMake referenced file missing: " + f)
184 # now check on files not accounted for.
185 print("\nC/C++ Files CMake doesnt know about...")
186 for cf in sorted(source_list(base, is_c)):
187 if not is_ignore(cf):
188 if cf not in global_c:
189 print("missing_c: ", cf)
190 print("\nC/C++ Headers CMake doesnt know about...")
191 for hf in sorted(source_list(base, is_c_header)):
192 if not is_ignore(hf):
193 if hf not in global_h:
194 print("missing_h: ", hf)
198 for files in (global_c, global_h):
199 for f in sorted(files):
202 for l in open(f, "r", encoding="utf8"):
205 print("Non utf8: %s:%d" % (f, i))
207 traceback.print_exc()