9393ENABLE_PROFILING = False
9494ENABLE_LINE_TRACING = False
9595
96- # First run
97- FIRST_RUN = False
98-
99-
10096def main ():
10197 command_line_args ()
10298 print ("[build.py] Python version: {ver} {arch}"
@@ -107,21 +103,15 @@ def main():
107103 check_cython_version ()
108104 check_directories ()
109105 setup_environ ()
110- if os .path .exists (CEFPYTHON_API_HFILE ):
111- fix_cefpython_api_header_file ()
112- if WINDOWS :
113- compile_cpp_projects_with_setuptools ()
114- elif MAC or LINUX :
115- compile_cpp_projects_unix ()
116- else :
117- print ("[build.py] INFO: Looks like first run, as"
118- " cefpython_py{pyver}.h is missing. Skip building"
119- " C++ projects."
120- .format (pyver = PYVERSION ))
121- global FIRST_RUN
122- FIRST_RUN = True
123106 clear_cache ()
124107 copy_and_fix_pyx_files ()
108+ if not os .path .exists (CEFPYTHON_API_HFILE ):
109+ cythonize_pyx_to_generate_header ()
110+ fix_cefpython_api_header_file ()
111+ if WINDOWS :
112+ compile_cpp_projects_with_setuptools ()
113+ elif MAC or LINUX :
114+ compile_cpp_projects_unix ()
125115 build_cefpython_module ()
126116 fix_cefpython_api_header_file ()
127117 install_and_run ()
@@ -443,13 +433,6 @@ def compile_cpp_projects_unix():
443433 print ("[build.py] Clean C++ projects (--clean flag passed)" )
444434 clean_cpp_projects_unix ()
445435
446- # Need to allow continuing even when make fails, as it may
447- # fail because the "public" function declaration is not yet
448- # in cefpython API header file, but for it to be generated we need
449- # to run cython compiling, so in this case you continue even when
450- # make fails and then run the compile.py script again and this time
451- # make should succeed.
452-
453436 # -- CLIENT_HANDLER
454437 print ("[build.py] ~~ Build CLIENT_HANDLER project" )
455438
@@ -672,6 +655,19 @@ def except_all_missing(content):
672655 return lineNumber
673656
674657
658+ def cythonize_pyx_to_generate_header ():
659+ """On first run, transpile the pyx file via cython_setup.py --cython-only
660+ to generate the Cython public API header before C++ compilation."""
661+ print ("[build.py] First run: generating Cython API header via transpilation" )
662+ os .chdir (BUILD_CEFPYTHON )
663+ command = ("\" {python}\" {tools_dir}/cython_setup.py --cython-only"
664+ .format (python = sys .executable , tools_dir = TOOLS_DIR ))
665+ ret = subprocess .call (command , shell = True )
666+ if ret != 0 :
667+ print ("[build.py] ERROR: Failed to generate Cython API header" )
668+ sys .exit (1 )
669+
670+
675671def build_cefpython_module ():
676672 # if DEBUG_FLAG:
677673 # ret = subprocess.call("python-dbg setup.py build_ext --inplace"
@@ -719,26 +715,7 @@ def build_cefpython_module():
719715
720716 # Check if built succeeded after pyx files were removed
721717 if ret != 0 :
722- if FIRST_RUN and os .path .exists (CEFPYTHON_API_HFILE ):
723- print ("[build.py] INFO: looks like this was first run and"
724- " building the cefpython module is expected to fail"
725- " in such case due to cefpython API header file not"
726- " being generated yet. Will re-run the build.py script"
727- " programmatically now." )
728- args = list ()
729- args .append ("\" {python}\" " .format (python = sys .executable ))
730- args .append (os .path .join (TOOLS_DIR , os .path .basename (__file__ )))
731- assert os .path .basename (__file__ ) in sys .argv [0 ]
732- args .extend (SYS_ARGV_ORIGINAL [1 :])
733- command = " " .join (args )
734- print ("[build.py] Running command: %s" % command )
735- ret = subprocess .call (command , shell = True )
736- # Always pass fixed value to sys.exit, read note at
737- # the top of the script about os.system and sys.exit
738- # issue.
739- sys .exit (0 if ret == 0 else 1 )
740- else :
741- print ("[build.py] ERROR: failed to build the cefpython module" )
718+ print ("[build.py] ERROR: failed to build the cefpython module" )
742719 sys .exit (1 )
743720
744721 # Move the cefpython module
0 commit comments