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 *****
30 from os.path import join, dirname, normpath, abspath
32 SOURCE_DIR = join(dirname(__file__), "..", "..")
33 SOURCE_DIR = normpath(SOURCE_DIR)
34 SOURCE_DIR = abspath(SOURCE_DIR)
37 def is_c_header(filename):
38 ext = os.path.splitext(filename)[1]
39 return (ext in (".h", ".hpp", ".hxx"))
43 ext = os.path.splitext(filename)[1]
44 return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc"))
47 def is_c_any(filename):
48 return os.path.s_c(filename) or is_c_header(filename)
51 # copied from project_info.py
55 def cmake_cache_var(var):
56 cache_file = open(join(CMAKE_DIR, "CMakeCache.txt"))
57 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("#")]
61 if l.split(":")[0] == var:
62 return l.split("=", 1)[-1]
66 def do_ignore(filepath, ignore_prefix_list):
67 if ignore_prefix_list is None:
70 relpath = os.path.relpath(filepath, SOURCE_DIR)
71 return any([relpath.startswith(prefix) for prefix in ignore_prefix_list])
77 # Check blender is not 2.5x until it supports playback again
78 print("running make with --dry-run ...")
79 process = subprocess.Popen(["make", "--always-make", "--dry-run", "--keep-going", "VERBOSE=1"],
80 stdout=subprocess.PIPE,
86 out = process.stdout.read()
87 process.stdout.close()
88 print("done!", len(out), "bytes")
89 return out.decode("ascii").split("\n")
92 def build_info(use_c=True, use_cxx=True, ignore_prefix_list=None):
94 makelog = makefile_log()
100 compilers.append(cmake_cache_var("CMAKE_C_COMPILER"))
102 compilers.append(cmake_cache_var("CMAKE_CXX_COMPILER"))
104 print("compilers:", " ".join(compilers))
106 fake_compiler = "%COMPILER%"
108 print("parsing make log ...")
114 if not any([(c in args) for c in compilers]):
117 # join args incase they are not.
118 args = ' '.join(args)
119 args = args.replace(" -isystem", " -I")
120 args = args.replace(" -D ", " -D")
121 args = args.replace(" -I ", " -I")
124 args = args.replace(c, fake_compiler)
129 args[:args.index(fake_compiler) + 1] = []
131 c_files = [f for f in args if is_c(f)]
132 inc_dirs = [f[2:].strip() for f in args if f.startswith('-I')]
133 defs = [f[2:].strip() for f in args if f.startswith('-D')]
134 for c in sorted(c_files):
136 if do_ignore(c, ignore_prefix_list):
139 source.append((c, inc_dirs, defs))
141 # safety check that our includes are ok
143 if not os.path.exists(f):
144 raise Exception("%s missing" % f)
151 # could be moved elsewhere!, this just happens to be used by scripts that also
153 def queue_processes(process_funcs, job_total=-1):
154 """ Takes a list of function arg pairs, each function must return a process
159 import multiprocessing
160 job_total = multiprocessing.cpu_count()
164 for func, args in process_funcs:
168 process = func(*args)
174 for func, args in process_funcs:
175 # wait until a thread is free
177 processes[:] = [p for p in processes if p.poll() is None]
179 if len(processes) <= job_total:
187 processes.append(func(*args))
191 if not os.path.exists(join(CMAKE_DIR, "CMakeCache.txt")):
192 print("This script must run from the cmake build dir")
195 for s in build_info():
198 if __name__ == "__main__":