@@ -82,21 +82,23 @@ def main():
8282 check_cython_version ()
8383 check_directories ()
8484 setup_environ ()
85- if os .path .exists (CEFPYTHON_H ):
86- fix_cefpython_h ()
85+ if os .path .exists (CEFPYTHON_API_HFILE ):
86+ fix_cefpython_api_header_file ()
8787 if WINDOWS :
8888 compile_cpp_projects_with_setuptools ()
8989 elif MAC or LINUX :
9090 compile_cpp_projects_unix ()
9191 else :
92- print ("[build.py] INFO: Looks like first run, as cefpython.h"
93- " is missing. Skip building C++ projects." )
92+ print ("[build.py] INFO: Looks like first run, as"
93+ " cefpython_py{pyver}.h is missing. Skip building"
94+ " C++ projects."
95+ .format (pyver = PYVERSION ))
9496 global FIRST_RUN
9597 FIRST_RUN = True
9698 clear_cache ()
9799 copy_and_fix_pyx_files ()
98100 build_cefpython_module ()
99- fix_cefpython_h ()
101+ fix_cefpython_api_header_file ()
100102 install_and_run ()
101103
102104
@@ -282,49 +284,52 @@ def check_directories():
282284 assert os .path .exists (CEFPYTHON_BINARY )
283285
284286
285- def fix_cefpython_h ():
286- """This function does two things: 1) Disable warnings in cefpython.h
287- and 2) Make a copy named cefpython_fixed.h - this copy will be used
288- by C++ projects and its modification time won't change every time
289- you run build.py script, thus C++ won't rebuild each time."""
287+ def fix_cefpython_api_header_file ():
288+ """This function does two things: 1) Disable warnings in cefpython
289+ API header file and 2) Make a copy named cefpython_pyXX_fixed.h,
290+ this copy will be used by C++ projects and its modification time
291+ won't change every time you run build.py script, thus C++ won't
292+ rebuild each time."""
290293
291- # Fix cefpython .h to disable this warning:
294+ # Fix cefpython_pyXX .h to disable this warning:
292295 # > warning: 'somefunc' has C-linkage specified, but returns
293296 # > user-defined type 'sometype' which is incompatible with C
294297 # On Mac this warning must be disabled using -Wno-return-type-c-linkage
295298 # flag in makefiles.
296299
297- print ("[build.py] Fix cefpython.h in the build_cefpython/ directory" )
298- if not os .path .exists (CEFPYTHON_H ):
299- assert not os .path .exists (CEFPYTHON_H_FIXED )
300- print ("[build.py] cefpython.h was not yet generated" )
300+ print ("[build.py] Fix cefpython API header file in the build_cefpython/"
301+ " directory" )
302+ if not os .path .exists (CEFPYTHON_API_HFILE ):
303+ assert not os .path .exists (CEFPYTHON_API_HFILE_FIXED )
304+ print ("[build.py] cefpython API header file was not yet generated" )
301305 return
302306
303- with open (CEFPYTHON_H , "rb" ) as fo :
307+ with open (CEFPYTHON_API_HFILE , "rb" ) as fo :
304308 contents = fo .read ().decode ("utf-8" )
305309
306310 already_fixed = False
307311 pragma = "#pragma warning(disable:4190)"
308312 if pragma in contents :
309313 already_fixed = True
310- print ("[build.py] cefpython.h is already fixed" )
314+ print ("[build.py] cefpython API header file is already fixed" )
311315 else :
312316 if not MAC :
313317 contents = ("%s\n \n " % pragma ) + contents
314318
315319 if not already_fixed :
316- with open (CEFPYTHON_H , "wb" ) as fo :
320+ with open (CEFPYTHON_API_HFILE , "wb" ) as fo :
317321 fo .write (contents .encode ("utf-8" ))
318- print ("[build.py] Save cefpython.h" )
322+ print ("[build.py] Save {filename}"
323+ .format (filename = CEFPYTHON_API_HFILE ))
319324
320- if os .path .exists (CEFPYTHON_H_FIXED ):
321- with open (CEFPYTHON_H_FIXED , "rb" ) as fo :
325+ if os .path .exists (CEFPYTHON_API_HFILE_FIXED ):
326+ with open (CEFPYTHON_API_HFILE_FIXED , "rb" ) as fo :
322327 contents_fixed = fo .read ().decode ("utf-8" )
323328 else :
324329 contents_fixed = ""
325330 if contents != contents_fixed :
326331 print ("[build.py] Save cefpython_fixed.h" )
327- with open (CEFPYTHON_H_FIXED , "wb" ) as fo :
332+ with open (CEFPYTHON_API_HFILE_FIXED , "wb" ) as fo :
328333 fo .write (contents .encode ("utf-8" ))
329334
330335
@@ -437,9 +442,9 @@ def compile_cpp_projects_unix():
437442
438443 # Need to allow continuing even when make fails, as it may
439444 # fail because the "public" function declaration is not yet
440- # in " cefpython.h" , but for it to be generated we need to run
441- # cython compiling, so in this case you continue even when make
442- # fails and then run the compile.py script again and this time
445+ # in cefpython API header file , but for it to be generated we need
446+ # to run cython compiling, so in this case you continue even when
447+ # make fails and then run the compile.py script again and this time
443448 # make should succeed.
444449
445450 # -- CLIENT_HANDLER
@@ -533,15 +538,16 @@ def copy_and_fix_pyx_files():
533538
534539 os .chdir (BUILD_CEFPYTHON )
535540 print ("\n " )
536- mainfile = "cefpython.pyx"
541+ mainfile_original = "cefpython.pyx"
542+ mainfile_newname = "cefpython_py{pyver}.pyx" .format (pyver = PYVERSION )
537543
538544 pyxfiles = glob .glob ("../../src/*.pyx" )
539545 if not len (pyxfiles ):
540546 print ("[build.py] ERROR: no .pyx files found in root" )
541547 sys .exit (1 )
542- pyxfiles = [f for f in pyxfiles if f .find (mainfile ) == - 1 ]
543- # Now, pyxfiles contains all pyx files except the mainfile (cefpython.pyx),
544- # we do not fix includes in mainfile.
548+ pyxfiles = [f for f in pyxfiles if f .find (mainfile_original ) == - 1 ]
549+ # Now, pyxfiles contains all pyx files except mainfile_original
550+ # (cefpython.pyx), we do not fix includes in mainfile.
545551
546552 pyxfiles2 = glob .glob ("../../src/handlers/*.pyx" )
547553 if not len (pyxfiles2 ):
@@ -562,19 +568,19 @@ def copy_and_fix_pyx_files():
562568
563569 # Copy cefpython.pyx and fix includes in cefpython.pyx, eg.:
564570 # include "handlers/focus_handler.pyx" becomes include "focus_handler.pyx"
565- shutil .copy ("../../src/%s" % mainfile , "./%s" % mainfile )
566- with open ("./%s" % mainfile , "rb" ) as fo :
571+ shutil .copy ("../../src/%s" % mainfile_original , "./%s" % mainfile_newname )
572+ with open ("./%s" % mainfile_newname , "rb" ) as fo :
567573 content = fo .read ().decode ("utf-8" )
568574 (content , subs ) = re .subn (r"^include \"handlers/" ,
569575 "include \" " ,
570576 content ,
571577 flags = re .MULTILINE )
572578 # Add __version__ variable in cefpython.pyx
573- print ("[build.py] Add __version__ variable to %s" % mainfile )
579+ print ("[build.py] Add __version__ variable to %s" % mainfile_newname )
574580 content = ('__version__ = "{}"\n ' .format (VERSION )) + content
575- with open ("./%s" % mainfile , "wb" ) as fo :
581+ with open ("./%s" % mainfile_newname , "wb" ) as fo :
576582 fo .write (content .encode ("utf-8" ))
577- print ("[build.py] Fix %s includes in %s" % (subs , mainfile ))
583+ print ("[build.py] Fix %s includes in %s" % (subs , mainfile_newname ))
578584
579585 # Copy the rest of the files
580586 print ("[build.py] Fix includes in other .pyx files" )
@@ -682,10 +688,12 @@ def build_cefpython_module():
682688
683689 # Check if built succeeded after pyx files were removed
684690 if ret != 0 :
685- if FIRST_RUN and os .path .exists (CEFPYTHON_H ):
691+ if FIRST_RUN and os .path .exists (CEFPYTHON_API_HFILE ):
686692 print ("[build.py] INFO: looks like this was first run and"
687- " linking is expected to fail in such case. Will re-run"
688- " the build.py script programmatically now." )
693+ " building the cefpython module is expected to fail"
694+ " in such case due to cefpython API header file not"
695+ " being generated yet. Will re-run the build.py script"
696+ " programmatically now." )
689697 args = list ()
690698 args .append (sys .executable )
691699 args .append (os .path .join (TOOLS_DIR , os .path .basename (__file__ )))
0 commit comments