~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to build_files/cmake/project_source_info.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ***** BEGIN GPL LICENSE BLOCK *****
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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.
 
16
#
 
17
# Contributor(s): Campbell Barton
 
18
#
 
19
# ***** END GPL LICENSE BLOCK *****
 
20
 
 
21
# <pep8 compliant>
 
22
 
 
23
__all__ = (
 
24
    "build_info",
 
25
    "SOURCE_DIR",
 
26
    )
 
27
 
 
28
 
 
29
import sys
 
30
if not sys.version.startswith("3"):
 
31
    print("\nPython3.x needed, found %s.\nAborting!\n" %
 
32
          sys.version.partition(" ")[0])
 
33
    sys.exit(1)
 
34
 
 
35
 
 
36
import os
 
37
from os.path import join, dirname, normpath, abspath
 
38
 
 
39
SOURCE_DIR = join(dirname(__file__), "..", "..")
 
40
SOURCE_DIR = normpath(SOURCE_DIR)
 
41
SOURCE_DIR = abspath(SOURCE_DIR)
 
42
 
 
43
 
 
44
def is_c_header(filename):
 
45
    ext = os.path.splitext(filename)[1]
 
46
    return (ext in (".h", ".hpp", ".hxx"))
 
47
 
 
48
 
 
49
def is_c(filename):
 
50
    ext = os.path.splitext(filename)[1]
 
51
    return (ext in (".c", ".cpp", ".cxx", ".m", ".mm", ".rc", ".cc", ".inl"))
 
52
 
 
53
 
 
54
def is_c_any(filename):
 
55
    return os.path.s_c(filename) or is_c_header(filename)
 
56
 
 
57
 
 
58
# copied from project_info.py
 
59
CMAKE_DIR = "."
 
60
 
 
61
 
 
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("#")]
 
65
    cache_file.close()
 
66
 
 
67
    for l in lines:
 
68
        if l.split(":")[0] == var:
 
69
            return l.split("=", 1)[-1]
 
70
    return None
 
71
 
 
72
 
 
73
def do_ignore(filepath, ignore_prefix_list):
 
74
    if ignore_prefix_list is None:
 
75
        return False
 
76
 
 
77
    relpath = os.path.relpath(filepath, SOURCE_DIR)
 
78
    return any([relpath.startswith(prefix) for prefix in ignore_prefix_list])
 
79
 
 
80
 
 
81
def makefile_log():
 
82
    import subprocess
 
83
    import time
 
84
 
 
85
    print("running make with --dry-run ...")
 
86
    process = subprocess.Popen(["make", "--always-make", "--dry-run", "--keep-going", "VERBOSE=1"],
 
87
                                stdout=subprocess.PIPE,
 
88
                                )
 
89
 
 
90
    while process.poll():
 
91
        time.sleep(1)
 
92
 
 
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")
 
97
 
 
98
 
 
99
def build_info(use_c=True, use_cxx=True, ignore_prefix_list=None):
 
100
 
 
101
    makelog = makefile_log()
 
102
 
 
103
    source = []
 
104
 
 
105
    compilers = []
 
106
    if use_c:
 
107
        compilers.append(cmake_cache_var("CMAKE_C_COMPILER"))
 
108
    if use_cxx:
 
109
        compilers.append(cmake_cache_var("CMAKE_CXX_COMPILER"))
 
110
 
 
111
    print("compilers:", " ".join(compilers))
 
112
 
 
113
    fake_compiler = "%COMPILER%"
 
114
 
 
115
    print("parsing make log ...")
 
116
 
 
117
    for line in makelog:
 
118
 
 
119
        args = line.split()
 
120
 
 
121
        if not any([(c in args) for c in compilers]):
 
122
            continue
 
123
 
 
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")
 
129
 
 
130
        for c in compilers:
 
131
            args = args.replace(c, fake_compiler)
 
132
        args = args.split()
 
133
        # end
 
134
 
 
135
        # remove compiler
 
136
        args[:args.index(fake_compiler) + 1] = []
 
137
 
 
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):
 
142
 
 
143
            if do_ignore(c, ignore_prefix_list):
 
144
                continue
 
145
 
 
146
            source.append((c, inc_dirs, defs))
 
147
 
 
148
        # safety check that our includes are ok
 
149
        for f in inc_dirs:
 
150
            if not os.path.exists(f):
 
151
                raise Exception("%s missing" % f)
 
152
 
 
153
    print("done!")
 
154
 
 
155
    return source
 
156
 
 
157
 
 
158
# could be moved elsewhere!, this just happens to be used by scripts that also
 
159
# use this module.
 
160
def queue_processes(process_funcs, job_total=-1):
 
161
    """ Takes a list of function arg pairs, each function must return a process
 
162
    """
 
163
 
 
164
    if job_total == -1:
 
165
        import multiprocessing
 
166
        job_total = multiprocessing.cpu_count()
 
167
        del multiprocessing
 
168
 
 
169
    if job_total == 1:
 
170
        for func, args in process_funcs:
 
171
            sys.stdout.flush()
 
172
            sys.stderr.flush()
 
173
 
 
174
            process = func(*args)
 
175
            process.wait()
 
176
    else:
 
177
        import time
 
178
 
 
179
        processes = []
 
180
        for func, args in process_funcs:
 
181
            # wait until a thread is free
 
182
            while 1:
 
183
                processes[:] = [p for p in processes if p.poll() is None]
 
184
 
 
185
                if len(processes) <= job_total:
 
186
                    break
 
187
                else:
 
188
                    time.sleep(0.1)
 
189
 
 
190
            sys.stdout.flush()
 
191
            sys.stderr.flush()
 
192
 
 
193
            processes.append(func(*args))
 
194
 
 
195
 
 
196
def main():
 
197
    if not os.path.exists(join(CMAKE_DIR, "CMakeCache.txt")):
 
198
        print("This script must run from the cmake build dir")
 
199
        return
 
200
 
 
201
    for s in build_info():
 
202
        print(s)
 
203
 
 
204
if __name__ == "__main__":
 
205
    main()