1
# ***** BEGIN GPL LICENSE BLOCK *****
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
# Contributor(s): Campbell Barton
19
# ***** END GPL LICENSE BLOCK *****
30
if not sys.version.startswith("3"):
31
print("\nPython3.x needed, found %s.\nAborting!\n" %
32
sys.version.partition(" ")[0])
37
from os.path import join, dirname, normpath, abspath
39
SOURCE_DIR = join(dirname(__file__), "..", "..")
40
SOURCE_DIR = normpath(SOURCE_DIR)
41
SOURCE_DIR = abspath(SOURCE_DIR)
44
def is_c_header(filename):
45
ext = os.path.splitext(filename)[1]
46
return (ext in (".h", ".hpp", ".hxx"))
50
ext = os.path.splitext(filename)[1]
51
return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"))
54
def is_c_any(filename):
55
return os.path.s_c(filename) or is_c_header(filename)
58
# copied from project_info.py
62
def cmake_cache_var(var):
63
cache_file = open(join(CMAKE_DIR, "CMakeCache.txt"))
64
lines = [l_strip for l in cache_file for l_strip in (l.strip(),) if l_strip if not l_strip.startswith("//") if not l_strip.startswith("#")]
68
if l.split(":")[0] == var:
69
return l.split("=", 1)[-1]
73
def do_ignore(filepath, ignore_prefix_list):
74
if ignore_prefix_list is None:
77
relpath = os.path.relpath(filepath, SOURCE_DIR)
78
return any([relpath.startswith(prefix) for prefix in ignore_prefix_list])
85
print("running make with --dry-run ...")
86
process = subprocess.Popen(["make", "--always-make", "--dry-run", "--keep-going", "VERBOSE=1"],
87
stdout=subprocess.PIPE,
93
out = process.stdout.read()
94
process.stdout.close()
95
print("done!", len(out), "bytes")
96
return out.decode("utf-8", errors="ignore").split("\n")
99
def build_info(use_c=True, use_cxx=True, ignore_prefix_list=None):
101
makelog = makefile_log()
107
compilers.append(cmake_cache_var("CMAKE_C_COMPILER"))
109
compilers.append(cmake_cache_var("CMAKE_CXX_COMPILER"))
111
print("compilers:", " ".join(compilers))
113
fake_compiler = "%COMPILER%"
115
print("parsing make log ...")
121
if not any([(c in args) for c in compilers]):
124
# join args incase they are not.
125
args = ' '.join(args)
126
args = args.replace(" -isystem", " -I")
127
args = args.replace(" -D ", " -D")
128
args = args.replace(" -I ", " -I")
131
args = args.replace(c, fake_compiler)
136
args[:args.index(fake_compiler) + 1] = []
138
c_files = [f for f in args if is_c(f)]
139
inc_dirs = [f[2:].strip() for f in args if f.startswith('-I')]
140
defs = [f[2:].strip() for f in args if f.startswith('-D')]
141
for c in sorted(c_files):
143
if do_ignore(c, ignore_prefix_list):
146
source.append((c, inc_dirs, defs))
148
# safety check that our includes are ok
150
if not os.path.exists(f):
151
raise Exception("%s missing" % f)
158
# could be moved elsewhere!, this just happens to be used by scripts that also
160
def queue_processes(process_funcs, job_total=-1):
161
""" Takes a list of function arg pairs, each function must return a process
165
import multiprocessing
166
job_total = multiprocessing.cpu_count()
170
for func, args in process_funcs:
174
process = func(*args)
180
for func, args in process_funcs:
181
# wait until a thread is free
183
processes[:] = [p for p in processes if p.poll() is None]
185
if len(processes) <= job_total:
193
processes.append(func(*args))
197
if not os.path.exists(join(CMAKE_DIR, "CMakeCache.txt")):
198
print("This script must run from the cmake build dir")
201
for s in build_info():
204
if __name__ == "__main__":