cmake_consistency_check.py revision cdc60c622d70859a52693bd71ab473c5dad37eef
# $Id: cmake_consistency_check.py 38869 2011-07-31 03:15:37Z campbellbarton $
# ***** BEGIN GPL LICENSE BLOCK *****
#
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Contributor(s): Campbell Barton
#
# ***** END GPL LICENSE BLOCK *****
# <pep8 compliant>
import os
print("Scanning:", SOURCE_DIR)
global_refs = {}
l = data[i]
# skip '.svn'
continue
# extension checking
def is_c_header(filename):
def cmake_get_src(f):
sources_h = []
sources_c = []
i = 0
# print(f)
def is_definition(l, f, i, name):
return True
if l.endswith(")"):
return True
while it is not None:
context_name = ""
while it is not None:
i += 1
try:
except StopIteration:
it = None
break
l = l.strip()
if not l.startswith("#"):
if found:
context_name = "SRC"
break
if found:
context_name = "INC"
break
if found:
cmake_base = dirname(f)
while it is not None:
i += 1
try:
except StopIteration:
it = None
break
l = l.strip()
if not l.startswith("#"):
if ")" in l:
if l.strip() != ")":
raise Exception("strict formatting not kept '*)' %s:%d" % (f, i))
break
# replace dirs
if not l:
pass
elif l.startswith("$"):
if context_name == "SRC":
# assume if it ends with context_name we know about it
print("Can't use var '%s' %s:%d" % (l, f, i))
raise Exception("Multi-line define '%s' %s:%d" % (l, f, i))
else:
if context_name == "SRC":
if is_c_header(new_file):
elif l in ("PARENT_SCOPE", ):
# cmake var, ignore
pass
pass
pass
else:
elif context_name == "INC":
if new_path_rel != l:
print("overly relative path:\n %s:%d\n %s\n %s" % (f, i, l, new_path_rel))
## Save time. just replace the line
# replace_line(f, i - 1, new_path_rel)
else:
# print(new_file)
'''
if not sources_h and not sources_c:
raise Exception("No sources %s" % f)
sources_h_fs = list(source_list(cmake_base, is_c_header))
sources_c_fs = list(source_list(cmake_base, is_c))
'''
# find missing C files:
'''
for ff in sources_c_fs:
if ff not in sources_c:
print(" missing: " + ff)
'''
# reset
sources_h[:] = []
sources_c[:] = []
def is_ignore(f):
if ig in f:
return True
return False
# First do stupid check, do these files exist?
print("\nChecking for missing references:")
errs = []
if f.endswith("dna.c"):
continue
refs = global_refs[f]
if refs:
else:
raise Exception("CMake referenecs missing, internal error, aborting!")
print("%s:%d" % (cf, i))
# Write a 'sed' script, useful if we get a lot of these
# print("sed '%dd' '%s' > '%s.tmp' ; mv '%s.tmp' '%s'" % (i, cf, cf, cf, cf))
if is_err:
raise Exception("CMake referenecs missing files, aborting!")
del is_err
del errs
# now check on files not accounted for.
print("\nC/C++ Files CMake doesnt know about...")
print("missing_c: ", cf)
# check if automake builds a corrasponding .o file.
'''
if cf in global_c:
out1 = os.path.splitext(cf)[0] + ".o"
out2 = os.path.splitext(cf)[0] + ".Po"
out2_dir, out2_file = out2 = os.path.split(out2)
out2 = os.path.join(out2_dir, ".deps", out2_file)
if not os.path.exists(out1) and not os.path.exists(out2):
print("bad_c: ", cf)
'''
print("\nC/C++ Headers CMake doesnt know about...")
print("missing_h: ", hf)
if UTF8_CHECK:
# test encoding
import traceback
# ignore outside of our source tree
if "extern" not in f:
i = 1
try:
i += 1
except:
print("Non utf8: %s:%d" % (f, i))
if i > 1: