forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
769 lines (643 loc) · 26.1 KB
/
build.py
File metadata and controls
769 lines (643 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
# Copyright (c) 2017 The CEF Python authors. All rights reserved.
# Licensed under the BSD 3-clause license.
"""
Build the cefpython module, install package and run example.
Before running you must first put cefpython ready CEF binaries and
libraries in the cefpython/build/ directory (create if doesn't exist).
You have two options for obtaining these binaries and libraries.
Option 1: Download upstream CEF binaries and libraries from cefpython
GitHub Releases page. These binaries are tagged eg. "v55-upstream".
Extract the archive so that for example you have such a directory:
cefpython/build/cef55_3.2883.1553.g80bd606_win32/ .
Option 2: Use the automate.py tool. With this tool you can build CEF
from sources or use ready binaries from Spotify Automated Builds.
Usage:
build.py VERSION [--rebuild-cpp] [--fast] [--kivy]
Options:
VERSION Version in format xx.xx
--rebuild-cpp Force rebuild of C++ projects
--fast Fast mode
--kivy Run only Kivy example
"""
# How to debug on Linux:
# 1. Install "python-dbg" package
# 2. Install "python-wxgtk2.8-dbg" package
# 3. Run "python compile.py debug"
# 4. In cygdb type "cy run"
# 5. To display debug backtrace type "cy bt"
# 6. More commands: http://docs.cython.org/src/userguide/debugging.html
# This will not show "Segmentation fault" error message:
# > subprocess.call(["python", "./wxpython.py"])
# You need to call it with command as string and shell=True
# for this kind of error message to be shown:
# > subprocess.call("python wxpython.py", shell=True)
from common import *
import sys
import os
import glob
import shutil
import subprocess
import re
# raw_input() was renamed to input() in Python 3
try:
# noinspection PyUnresolvedReferences
# noinspection PyShadowingBuiltins
input = raw_input
except NameError:
pass
# Command line args variables
DEBUG_FLAG = False
FAST_FLAG = False
KIVY_FLAG = False
REBUILD_CPP = False
VERSION = ""
# First run
FIRST_RUN = False
CEFPYTHON_H = os.path.join(BUILD_CEFPYTHON, "cefpython.h")
def main():
if len(sys.argv) <= 1:
print(__doc__)
sys.exit(1)
print("[build.py] PYVERSION = %s" % PYVERSION)
print("[build.py] OS_POSTFIX2 = %s" % OS_POSTFIX2)
setup_environ()
check_cython_version()
command_line_args()
check_directories()
if os.path.exists(CEFPYTHON_H):
fix_cefpython_h()
if WINDOWS:
compile_cpp_projects_windows()
elif MAC or LINUX:
compile_cpp_projects_unix()
else:
print("[build.py] INFO: Looks like first run, as cefpython.h"
" is missing. Skip building C++ projects.")
global FIRST_RUN
FIRST_RUN = True
clear_cache()
copy_and_fix_pyx_files()
build_cefpython_module()
fix_cefpython_h()
install_and_run()
def setup_environ():
"""Set environment variables. Set PATH so that it contains only
minimum set of directories,to avoid any possible issues. Set Python
include path. Set Mac compiler options. Etc."""
print("[build.py] Setup environment variables")
# PATH
if WINDOWS:
path = [
"C:\\Windows\\system32",
"C:\\Windows",
"C:\\Windows\\System32\\Wbem",
get_python_path(),
]
os.environ["PATH"] = os.pathsep.join(path)
print("[build.py] environ PATH: {path}"
.format(path=os.environ["PATH"]))
# INCLUDE env for vcproj build
if WINDOWS:
if "INCLUDE" not in os.environ:
os.environ["INCLUDE"] = ""
os.environ["INCLUDE"] += os.pathsep + os.path.join(get_python_path(),
"include")
print("[build.py] environ INCLUDE: {include}"
.format(include=os.environ["INCLUDE"]))
# LIB env for vcproj build
if WINDOWS:
os.environ["AdditionalLibraryDirectories"] = os.path.join(
CEF_BINARIES_LIBRARIES, "lib")
print("[build.py] environ AdditionalLibraryDirectories: {lib}"
.format(lib=os.environ["AdditionalLibraryDirectories"]))
if LINUX or MAC:
# Used in makefiles
os.environ["CEF_CCFLAGS"] = "-std=gnu++11 -DNDEBUG -Wall -Werror"
if FAST_FLAG:
os.environ["CEF_CCFLAGS"] += " -O0"
else:
os.environ["CEF_CCFLAGS"] += " -O3"
os.environ["CEF_LINK_FLAGS"] = ""
if LINUX:
# TODO: Set CEF_CCFLAGS and CEF_LINK_FLAGS according to what is
# in upstream cefclient, see cef/cmake/cef_variables.cmake.
pass
# Mac env variables for makefiles
if MAC:
os.environ["CEF_BIN"] = os.path.join(CEF_BINARIES_LIBRARIES, "bin")
os.environ["CEF_LIB"] = os.path.join(CEF_BINARIES_LIBRARIES, "lib")
# Mac compiler options
if MAC:
os.environ["PATH"] = "/usr/local/bin:"+os.environ["PATH"]
os.environ["CC"] = "c++"
os.environ["CXX"] = "c++"
if ARCH32:
raise Exception("Python 32-bit is not supported on Mac")
os.environ["ARCHFLAGS"] = "-arch x86_64"
os.environ["CEF_CCFLAGS"] += " -arch x86_64"
os.environ["CEF_LINK_FLAGS"] += " -mmacosx-version-min=10.7"
# -Wno-return-type-c-linkage to ignore:
# > warning: 'somefunc' has C-linkage specified, but returns
# > user-defined type 'sometype' which is incompatible with C
os.environ["CEF_CCFLAGS"] += " -Wno-return-type-c-linkage"
# Compile against libc++ otherwise error "symbol not found"
# with cef::logging::LogMessage symbol. Also include -lc++
# and -lc++abi libraries.
os.environ["CEF_CCFLAGS"] += " -stdlib=libc++"
# See compile/link flags in upstream cefclient
os.environ["CEF_CCFLAGS"] += (
" -fno-strict-aliasing"
" -fno-rtti"
" -fno-threadsafe-statics"
" -fobjc-call-cxx-cdtors"
" -fvisibility=hidden"
" -fvisibility-inlines-hidden"
)
os.environ["CEF_LINK_FLAGS"] += (
" -lc++"
" -lc++abi"
" -Wl,-search_paths_first"
" -Wl,-ObjC"
" -Wl,-pie"
" -Wl,-dead_strip"
)
def get_python_path():
"""Get Python path."""
return os.path.dirname(sys.executable)
def check_cython_version():
print("[build.py] Check Cython version")
with open(os.path.join(TOOLS_DIR, "requirements.txt"), "r") as fileobj:
contents = fileobj.read()
match = re.search(r"cython\s*==\s*([\d.]+)", contents,
flags=re.IGNORECASE)
assert match, "cython package not found in requirements.txt"
require_version = match.group(1)
try:
import Cython
version = Cython.__version__
except ImportError:
# noinspection PyUnusedLocal
Cython = None
print("[build.py] ERROR: Cython is not installed ({0} required)"
.format(require_version))
sys.exit(1)
if version != require_version:
print("[build.py] ERROR: Wrong Cython version: {0}. Required: {1}"
.format(version, require_version))
sys.exit(1)
print("[build.py] Cython version: {0}".format(version))
def command_line_args():
global DEBUG_FLAG, FAST_FLAG, KIVY_FLAG, REBUILD_CPP, VERSION
print("[build.py] Parse command line arguments")
# -- debug flag
if len(sys.argv) > 1 and "--debug" in sys.argv:
DEBUG_FLAG = True
print("[build.py] DEBUG mode On")
# --fast flag
if len(sys.argv) > 1 and "--fast" in sys.argv:
# Fast mode doesn't delete C++ .o .a files.
# Fast mode also disables optimization flags in setup/setup.py .
FAST_FLAG = True
print("[build.py] FAST mode On")
# --kivy flag
if len(sys.argv) > 1 and "--kivy" in sys.argv:
KIVY_FLAG = True
print("[build.py] KIVY mode enabled")
# --rebuild-cpp flag
# Rebuild c++ projects
if len(sys.argv) > 1 and "--rebuild-cpp" in sys.argv:
REBUILD_CPP = True
print("[build.py] REBUILD_CPP mode enabled")
# version arg
if len(sys.argv) > 1 and re.search(r"^\d+\.\d+$", sys.argv[1]):
VERSION = sys.argv[1]
else:
print("[build.py] ERROR: expected first arg to be a version number")
print(" Allowed version format: \\d+\.\\d+")
sys.exit(1)
print("[build.py] VERSION=%s" % VERSION)
def check_directories():
print("[build.py] Check directories")
# Create directories if necessary
if not os.path.exists(CEFPYTHON_BINARY):
os.makedirs(CEFPYTHON_BINARY)
if not os.path.exists(BUILD_CEFPYTHON):
os.makedirs(BUILD_CEFPYTHON)
# Check directories exist
assert os.path.exists(BUILD_DIR)
assert os.path.exists(BUILD_CEFPYTHON)
assert os.path.exists(CEF_BINARIES_LIBRARIES)
assert os.path.exists(CEFPYTHON_BINARY)
def fix_cefpython_h():
# Fix cefpython.h to disable this warning:
# > warning: 'somefunc' has C-linkage specified, but returns
# > user-defined type 'sometype' which is incompatible with C
# On Mac this warning must be disabled using -Wno-return-type-c-linkage
# flag in makefiles.
if MAC:
return
os.chdir(BUILD_CEFPYTHON)
print("[build.py] Fix cefpython.h to disable warnings")
if not os.path.exists("cefpython.h"):
print("[build.py] cefpython.h was not yet generated")
return
with open("cefpython.h", "r") as fo:
contents = fo.read()
pragma = "#pragma warning(disable:4190)"
if pragma in contents:
print("[build.py] cefpython.h is already fixed")
return
contents = ("%s\n\n" % pragma) + contents
with open("cefpython.h", "w") as fo:
fo.write(contents)
print("[build.py] Save build_cefpython/cefpython.h")
def compile_cpp_projects_windows():
print("[build.py] Compile C++ projects")
print("[build.py] ~~ Build CLIENT_HANDLER vcproj")
vcproj = ("client_handler_py{pyver}_{os}.vcproj"
.format(pyver=PYVERSION, os=OS_POSTFIX2))
vcproj = os.path.join(SRC_DIR, "client_handler", vcproj)
build_vcproj(vcproj)
print("[build.py] ~~ Build LIBCEFPYTHONAPP vcproj")
vcproj = ("libcefpythonapp_py{pyver}_{os}.vcproj"
.format(pyver=PYVERSION, os=OS_POSTFIX2))
vcproj = os.path.join(SRC_DIR, "subprocess", vcproj)
build_vcproj(vcproj)
print("[build.py] ~~ Build SUBPROCESS vcproj")
vcproj = ("subprocess_{os}.vcproj"
.format(os=OS_POSTFIX2))
vcproj = os.path.join(SRC_DIR, "subprocess", vcproj)
ret = build_vcproj(vcproj)
# Copy subprocess executable
subprocess_from = os.path.join(
SUBPROCESS_DIR,
"Release_{os}".format(os=OS_POSTFIX2),
"subprocess_{os}.exe".format(os=OS_POSTFIX2))
subprocess_to = os.path.join(CEFPYTHON_BINARY, "subprocess.exe")
if os.path.exists(subprocess_to):
os.remove(subprocess_to)
if ret == 0:
print("[build.py] Copy subprocess executable")
# shutil.copy() will also copy Permission bits
shutil.copy(subprocess_from, subprocess_to)
print("[build.py] ~~ Build CPP_UTILS vcproj")
vcproj = ("cpp_utils_{os}.vcproj"
.format(os=OS_POSTFIX2))
vcproj = os.path.join(SRC_DIR, "cpp_utils", vcproj)
build_vcproj(vcproj)
def build_vcproj(vcproj):
if PYVERSION == "27":
args = list()
args.append(VS2008_VCVARS)
args.append(VS_PLATFORM_ARG)
args.append("&&")
args.append(VS2008_BUILD)
args.append("/nocolor")
args.append("/nologo")
args.append("/nohtmllog")
if REBUILD_CPP:
args.append("/rebuild")
args.append(vcproj)
ret = subprocess.call(args, shell=True)
if ret != 0:
compile_ask_to_continue()
return ret
else:
raise Exception("Only Python 2.7 32-bit is currently supported")
# In VS2010 vcbuild was replaced by msbuild.exe.
# /clp:disableconsolecolor
# msbuild /p:BuildProjectReferences=false project.proj
# MSBuild.exe MyProject.proj /t:build
def compile_ask_to_continue():
# noinspection PyUnboundLocalVariable
what = input("[build.py] make failed, 'y' to continue, Enter to stop: ")
if what != "y":
sys.exit(1)
def compile_cpp_projects_unix():
print("[build.py] Compile C++ projects")
# Need to allow continuing even when make fails, as it may
# fail because the "public" function declaration is not yet
# in "cefpython.h", but for it to be generated we need to run
# cython compiling, so in this case you continue even when make
# fails and then run the compile.py script again and this time
# make should succeed.
# -- CLIENT_HANDLER
print("[build.py] ~~ Build CLIENT_HANDLER project")
os.chdir(CLIENT_HANDLER_DIR)
if not FAST_FLAG:
subprocess.call("rm -f *.o *.a", shell=True)
ret = subprocess.call("make -f Makefile", shell=True)
if ret != 0:
compile_ask_to_continue()
# -- LIBCEFPYTHONAPP
print("[build.py] ~~ Build LIBCEFPYTHONAPP project")
os.chdir(SUBPROCESS_DIR)
if not FAST_FLAG:
subprocess.call("rm -f *.o *.a", shell=True)
subprocess.call("rm -f subprocess", shell=True)
ret = subprocess.call("make -f Makefile-libcefpythonapp", shell=True)
if ret != 0:
compile_ask_to_continue()
# -- SUBPROCESS
print("[build.py] ~~ Build SUBPROCESS project")
ret = subprocess.call("make -f Makefile", shell=True)
if ret != 0:
compile_ask_to_continue()
# Copy subprocess executable
subprocess_from = os.path.join(SUBPROCESS_DIR, "subprocess")
subprocess_to = os.path.join(CEFPYTHON_BINARY, "subprocess")
if os.path.exists(subprocess_from):
# shutil.copy() will also copy Permission bits
shutil.copy(subprocess_from, subprocess_to)
# -- CPP_UTILS
print("[build.py] ~~ Build CPP_UTILS project")
os.chdir(CPP_UTILS_DIR)
if not FAST_FLAG:
subprocess.call("rm -f *.o *.a", shell=True)
ret = subprocess.call("make -f Makefile", shell=True)
if ret != 0:
compile_ask_to_continue()
def clear_cache():
print("[build.py] Clean build cache")
# Cache in CEFPYTHON_BINARY directory (eg. cefpython_linux64/)
os.chdir(CEFPYTHON_BINARY)
delete_files_by_pattern("./"+MODULE_NAME_TEMPLATE
.format(pyversion="*", ext=MODULE_EXT))
# Cache in build_cefpython/ directory
os.chdir(BUILD_CEFPYTHON)
delete_files_by_pattern("./"+MODULE_NAME_TEMPLATE
.format(pyversion="*", ext=MODULE_EXT))
delete_files_by_pattern("./*.pyx")
try:
if not FAST_FLAG:
# Cython's internal build/ directory
shutil.rmtree(os.path.join(BUILD_CEFPYTHON, "build"))
except OSError:
pass
def copy_and_fix_pyx_files():
print("[build.py] Copy and fix pyx files")
# First, it copies all .pyx files from upper directory to setup/.
# Then, fixes repeating of "include" statements in pyx files.
# Only the mainfile needs to have "include" statements,
# but we're using PyCharm and to get rid of "unresolved references"
# and other errors displayed in pycharm we are adding "include"
# statements in all of the pyx files.
# I'm not 100% sure how includes work in Cython, but I suspect that
# a few includes of the same file will include the same content more
# than once, it should work, but function and variable definitions are
# duplicated, it is some kind of overhead and it could lead to some
# problems in the future, better to fix it now.
# It also checks cdef & cpdef functions whether they are not missing
# "except *", it is required to add it when returning non-python type.
os.chdir(BUILD_CEFPYTHON)
print("\n")
mainfile = "cefpython.pyx"
pyxfiles = glob.glob("../../src/*.pyx")
if not len(pyxfiles):
print("[build.py] ERROR: no .pyx files found in root")
sys.exit(1)
pyxfiles = [f for f in pyxfiles if f.find(mainfile) == -1]
# Now, pyxfiles contains all pyx files except the mainfile (cefpython.pyx),
# we do not fix includes in mainfile.
pyxfiles2 = glob.glob("../../src/handlers/*.pyx")
if not len(pyxfiles2):
print("[build.py] ERROR: no .pyx files found in handlers/")
sys.exit(1)
pyxfiles = pyxfiles + pyxfiles2
# Remove old pyx files
oldpyxfiles = glob.glob("./*.pyx")
print("[build.py] Clean pyx files in build_cefpython/")
for pyxfile in oldpyxfiles:
if os.path.exists(pyxfile):
os.remove(pyxfile)
# Copying pyxfiles and reading its contents.
print("[build.py] Copy pyx files to build_cefpython/")
# Copy cefpython.pyx and fix includes in cefpython.pyx, eg.:
# include "handlers/focus_handler.pyx" becomes include "focus_handler.pyx"
shutil.copy("../../src/%s" % mainfile, "./%s" % mainfile)
with open("./%s" % mainfile, "r") as fo:
content = fo.read()
(content, subs) = re.subn(r"^include \"handlers/",
"include \"",
content,
flags=re.MULTILINE)
# Add __version__ variable in cefpython.pyx
print("[build.py] Add __version__ variable to %s" % mainfile)
content = ('__version__ = "{}"\n'.format(VERSION)) + content
with open("./%s" % mainfile, "w") as fo:
fo.write(content)
print("[build.py] Fix %s includes in %s" % (subs, mainfile))
# Copy the rest of the files
print("[build.py] Fix includes in other .pyx files")
for pyxfile in pyxfiles:
newfile = "./%s" % os.path.basename(pyxfile)
shutil.copy(pyxfile, newfile)
pyxfile = newfile
with open(pyxfile, "r") as pyxfileopened:
content = pyxfileopened.read()
lineNumber = except_all_missing(content)
if lineNumber:
print("[build.py] WARNING: 'except *' missing"
" in a cdef/cpdef function,"
" in file %s on line %d"
% (os.path.basename(pyxfile), lineNumber))
sys.exit(1)
# Do not remove the newline - so that line numbers
# are exact with originals.
(content, subs) = re.subn(
r"^include[\t ]+[\"'][^\"'\n\r]+[\"'][\t ]*",
"",
content,
flags=re.MULTILINE)
if subs:
# print("[build.py] %s includes removed in: %s"
# % (subs, os.path.basename(pyxfile)))
pass
with open(pyxfile, "w") as pyxfileopened:
pyxfileopened.write(content)
print("\n")
def except_all_missing(content):
# This is not perfect, won't detect C++ custom types, but will find
# the built-in types, templates and pointers.
patterns = list()
patterns.append(
r"\bcp?def\s+"
"((int|short|long|double|char|unsigned|float|double|cpp_bool"
"|cpp_string|cpp_wstring|uintptr_t|void"
"|int32|uint32|int64|uint64"
"|int32_t|uint32_t|int64_t|uint64_t"
"|CefString)\s+)+"
"\w+\([^)]*\)\s*(with\s+(gil|nogil))?\s*:")
patterns.append(
r"\bcp?def\s+"
# A template ends with bracket: CefRefPtr[CefBrowser]
# or a pointer ends with asterisk: CefBrowser*
"[^\s]+[\]*]\s+"
"\w+\([^)]*\)\s*(with\s+(gil|nogil))?\s*:")
patterns.append(
r"\bcp?def\s+"
# A reference, eg. CefString&
"[^\s]+&\s+"
"\w+\([^)]*\)\s*(with\s+(gil|nogil))?\s*:")
match = None
for pattern in patterns:
match = re.search(pattern, content)
if match:
break
if match:
lineNumber = (content.count("\n", 0, match.start()) + 1)
return lineNumber
def build_cefpython_module():
# if DEBUG_FLAG:
# ret = subprocess.call("python-dbg setup.py build_ext --inplace"
# " --cython-gdb", shell=True)
print("[build.py] Execute build_module.py script")
print("")
os.chdir(BUILD_CEFPYTHON)
if FAST_FLAG:
ret = subprocess.call("{python} {tools_dir}/build_module.py"
" build_ext --fast"
.format(python=sys.executable,
tools_dir=TOOLS_DIR),
shell=True)
else:
ret = subprocess.call("{python} {tools_dir}/build_module.py"
" build_ext"
.format(python=sys.executable,
tools_dir=TOOLS_DIR),
shell=True)
# if DEBUG_FLAG:
# shutil.rmtree("./../binaries_%s/cython_debug/" % BITS,
# ignore_errors=True)
# shutil.copytree("./cython_debug/",
# "./../binaries_%s/cython_debug/" % BITS)
# Remove .pyx files
oldpyxfiles = glob.glob("./*.pyx")
print("")
print("[build.py] Cleanup: remove pyx files in build_cefpython/")
for pyxfile in oldpyxfiles:
if os.path.exists(pyxfile):
os.remove(pyxfile)
# Check if built succeeded after pyx files were removed
if ret != 0:
if FIRST_RUN and os.path.exists(CEFPYTHON_H):
print("[build.py] INFO: looks like this was first run and"
" linking is expected to fail in such case. Will re-run"
" the build.py script programmatically now.")
args = list()
args.append(sys.executable)
args.append(os.path.join(TOOLS_DIR, os.path.basename(__file__)))
assert __file__ in sys.argv[0]
args.extend(sys.argv[1:])
ret = subprocess.call(" ".join(args), shell=True)
sys.exit(ret)
else:
print("[build.py] ERROR: failed to build the cefpython module")
sys.exit(1)
# Move the cefpython module
module_pattern = MODULE_NAME_TEMPLATE.format(pyversion=PYVERSION+"*",
ext=MODULE_EXT)
if MAC:
module_pattern = "./build/lib*/"+module_pattern
else:
module_pattern = "./"+module_pattern
move_file_by_pattern(module_pattern, os.path.join(CEFPYTHON_BINARY,
MODULE_NAME))
print("[build.py] DONE building the cefpython module")
def move_file_by_pattern(pattern, move_to):
assert len(pattern) > 2
print("[build.py] Move file: {pattern} to {move_to}"
.format(pattern=pattern, move_to=move_to))
files = glob.glob(pattern)
assert(len(files) == 1)
os.rename(files[0], move_to)
def delete_files_by_pattern(pattern):
assert len(pattern) > 2
print("[build.py] Delete files by pattern: {pattern}"
.format(pattern=pattern))
files = glob.glob(pattern)
for f in files:
os.remove(f)
def delete_directories_by_pattern(pattern):
assert len(pattern) > 2
print("[build.py] Delete directories by pattern: {pattern}"
.format(pattern=pattern))
paths = glob.glob(pattern)
for path in paths:
if os.path.isdir(path):
shutil.rmtree(path)
def install_and_run():
# if DEBUG_FLAG:
# os.chdir("./binaries_%s" % BITS)
# subprocess.call("cygdb . --args python-dbg wxpython.py", shell=True)
print("[build.py] Install and run...")
os.chdir(BUILD_DIR)
# Setup installer directory
setup_installer_dir = ("./cefpython3-{version}-{os}-setup/"
.format(version=VERSION, os=OS_POSTFIX2))
setup_installer_dir = os.path.join(BUILD_DIR, setup_installer_dir)
# Delete setup installer directory if exists
if os.path.exists(setup_installer_dir):
delete_directory_reliably(setup_installer_dir)
# Make setup installer
print("[build.py] Make setup installer")
make_tool = os.path.join(TOOLS_DIR, "make_installer.py")
ret = os.system("{python} {make_tool} --version {version}"
.format(python=sys.executable,
make_tool=make_tool,
version=VERSION))
if ret != 0:
print("[build.py] ERROR while making installer package")
sys.exit(ret)
# Install
print("[build.py] Install the cefpython package")
os.chdir(setup_installer_dir)
ret = os.system("{sudo} {python} setup.py install"
.format(sudo=get_sudo(), python=sys.executable))
if ret != 0:
print("[build.py] ERROR while installing package")
sys.exit(ret)
os.chdir(BUILD_DIR)
# Run unittests
print("[build.py] Run unittests")
test_runner = os.path.join(UNITTESTS_DIR, "_test_runner.py")
ret = os.system("{python} {test_runner}"
.format(python=sys.executable, test_runner=test_runner))
if ret != 0:
print("[build.py] ERROR while running unit tests")
sys.exit(ret)
# Run examples
print("[build.py] Run examples")
os.chdir(EXAMPLES_DIR)
kivy_flag = "--kivy" if KIVY_FLAG else ""
run_examples = os.path.join(TOOLS_DIR, "run_examples.py")
ret = os.system("{python} {run_examples} {kivy_flag}"
.format(python=sys.executable,
run_examples=run_examples,
kivy_flag=kivy_flag))
if ret != 0:
print("[build.py] ERROR while running examples")
sys.exit(1)
print("[build.py] Everything OK")
def get_sudo():
# System Python requires sudo when installing package
if sys.executable in ["/usr/bin/python", "/usr/bin/python3"]:
sudo = "sudo"
else:
sudo = ""
return sudo
def delete_directory_reliably(adir):
assert len(adir) > 2
assert os.path.isdir(adir)
print("[build.py] Delete directory: {dir}"
.format(dir=adir.replace(ROOT_DIR, "")))
if WINDOWS:
shutil.rmtree(adir)
else:
# On Linux sudo might be required to delete directory, as this
# might be a setup installer directory with package installed
# using sudo and in such case files were created with sudo.
os.system("{sudo} rm -rf {dir}"
.format(sudo=get_sudo(), dir=adir))
if __name__ == "__main__":
main()