| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7e4d587 commit ed758d8
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ | |||
| 10 | 10 | #define CEFPYTHON_PUBLIC_API_H | |
| 11 | 11 | ||
| 12 | 12 | #if defined(OS_WIN) | |
| 13 | - #pragma warning(disable:4190) // cefpython_fixed.h extern C-linkage warnings | ||
| 13 | + #pragma warning(disable:4190) // cefpython API extern C-linkage warnings | ||
| 14 | 14 | #endif | |
| 15 | 15 | ||
| 16 | 16 | #include "Python.h" | |
@@ -30,6 +30,18 @@ | |||
| 30 | 30 | #include "include/cef_command_line.h" | |
| 31 | 31 | #include "util.h" | |
| 32 | 32 | ||
| 33 | - #include "../../build/build_cefpython/cefpython_fixed.h" | ||
| 33 | + #if PY_MAJOR_VERSION == 2 | ||
| 34 | + #if PY_MINOR_VERSION == 7 | ||
| 35 | + #include "../../build/build_cefpython/cefpython_py27_fixed.h" | ||
| 36 | + #endif // PY_MINOR_VERSION | ||
| 37 | + #elif PY_MAJOR_VERSION == 3 | ||
| 38 | + #if PY_MINOR_VERSION == 4 | ||
| 39 | + #include "../../build/build_cefpython/cefpython_py34_fixed.h" | ||
| 40 | + #elif PY_MINOR_VERSION == 5 | ||
| 41 | + #include "../../build/build_cefpython/cefpython_py35_fixed.h" | ||
| 42 | + #elif PY_MINOR_VERSION == 6 | ||
| 43 | + #include "../../build/build_cefpython/cefpython_py36_fixed.h" | ||
| 44 | + #endif // PY_MINOR_VERSION | ||
| 45 | + #endif // PY_MAJOR_VERSION | ||
| 34 | 46 | ||
| 35 | 47 | #endif // CEFPYTHON_PUBLIC_API_H | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,21 +82,23 @@ def main(): | |||
| 82 | 82 | check_cython_version() | |
| 83 | 83 | check_directories() | |
| 84 | 84 | 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() | ||
| 87 | 87 | if WINDOWS: | |
| 88 | 88 | compile_cpp_projects_with_setuptools() | |
| 89 | 89 | elif MAC or LINUX: | |
| 90 | 90 | compile_cpp_projects_unix() | |
| 91 | 91 | 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)) | ||
| 94 | 96 | global FIRST_RUN | |
| 95 | 97 | FIRST_RUN = True | |
| 96 | 98 | clear_cache() | |
| 97 | 99 | copy_and_fix_pyx_files() | |
| 98 | 100 | build_cefpython_module() | |
| 99 | - fix_cefpython_h() | ||
| 101 | + fix_cefpython_api_header_file() | ||
| 100 | 102 | install_and_run() | |
| 101 | 103 | ||
| 102 | 104 | ||
@@ -282,49 +284,52 @@ def check_directories(): | |||
| 282 | 284 | assert os.path.exists(CEFPYTHON_BINARY) | |
| 283 | 285 | ||
| 284 | 286 | ||
| 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.""" | ||
| 290 | 293 | ||
| 291 | - # Fix cefpython.h to disable this warning: | ||
| 294 | + # Fix cefpython_pyXX.h to disable this warning: | ||
| 292 | 295 | # > warning: 'somefunc' has C-linkage specified, but returns | |
| 293 | 296 | # > user-defined type 'sometype' which is incompatible with C | |
| 294 | 297 | # On Mac this warning must be disabled using -Wno-return-type-c-linkage | |
| 295 | 298 | # flag in makefiles. | |
| 296 | 299 | ||
| 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") | ||
| 301 | 305 | return | |
| 302 | 306 | ||
| 303 | - with open(CEFPYTHON_H, "rb") as fo: | ||
| 307 | + with open(CEFPYTHON_API_HFILE, "rb") as fo: | ||
| 304 | 308 | contents = fo.read().decode("utf-8") | |
| 305 | 309 | ||
| 306 | 310 | already_fixed = False | |
| 307 | 311 | pragma = "#pragma warning(disable:4190)" | |
| 308 | 312 | if pragma in contents: | |
| 309 | 313 | already_fixed = True | |
| 310 | - print("[build.py] cefpython.h is already fixed") | ||
| 314 | + print("[build.py] cefpython API header file is already fixed") | ||
| 311 | 315 | else: | |
| 312 | 316 | if not MAC: | |
| 313 | 317 | contents = ("%s\n\n" % pragma) + contents | |
| 314 | 318 | ||
| 315 | 319 | if not already_fixed: | |
| 316 | - with open(CEFPYTHON_H, "wb") as fo: | ||
| 320 | + with open(CEFPYTHON_API_HFILE, "wb") as fo: | ||
| 317 | 321 | 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)) | ||
| 319 | 324 | ||
| 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: | ||
| 322 | 327 | contents_fixed = fo.read().decode("utf-8") | |
| 323 | 328 | else: | |
| 324 | 329 | contents_fixed = "" | |
| 325 | 330 | if contents != contents_fixed: | |
| 326 | 331 | 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: | ||
| 328 | 333 | fo.write(contents.encode("utf-8")) | |
| 329 | 334 | ||
| 330 | 335 | ||
@@ -437,9 +442,9 @@ def compile_cpp_projects_unix(): | |||
| 437 | 442 | ||
| 438 | 443 | # Need to allow continuing even when make fails, as it may | |
| 439 | 444 | # 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 | ||
| 443 | 448 | # make should succeed. | |
| 444 | 449 | ||
| 445 | 450 | # -- CLIENT_HANDLER | |
@@ -533,15 +538,16 @@ def copy_and_fix_pyx_files(): | |||
| 533 | 538 | ||
| 534 | 539 | os.chdir(BUILD_CEFPYTHON) | |
| 535 | 540 | print("\n") | |
| 536 | - mainfile = "cefpython.pyx" | ||
| 541 | + mainfile_original = "cefpython.pyx" | ||
| 542 | + mainfile_newname = "cefpython_py{pyver}.pyx".format(pyver=PYVERSION) | ||
| 537 | 543 | ||
| 538 | 544 | pyxfiles = glob.glob("../../src/*.pyx") | |
| 539 | 545 | if not len(pyxfiles): | |
| 540 | 546 | print("[build.py] ERROR: no .pyx files found in root") | |
| 541 | 547 | 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. | ||
| 545 | 551 | ||
| 546 | 552 | pyxfiles2 = glob.glob("../../src/handlers/*.pyx") | |
| 547 | 553 | if not len(pyxfiles2): | |
@@ -562,19 +568,19 @@ def copy_and_fix_pyx_files(): | |||
| 562 | 568 | ||
| 563 | 569 | # Copy cefpython.pyx and fix includes in cefpython.pyx, eg.: | |
| 564 | 570 | # 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: | ||
| 567 | 573 | content = fo.read().decode("utf-8") | |
| 568 | 574 | (content, subs) = re.subn(r"^include \"handlers/", | |
| 569 | 575 | "include \"", | |
| 570 | 576 | content, | |
| 571 | 577 | flags=re.MULTILINE) | |
| 572 | 578 | # 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) | ||
| 574 | 580 | content = ('__version__ = "{}"\n'.format(VERSION)) + content | |
| 575 | - with open("./%s" % mainfile, "wb") as fo: | ||
| 581 | + with open("./%s" % mainfile_newname, "wb") as fo: | ||
| 576 | 582 | 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)) | ||
| 578 | 584 | ||
| 579 | 585 | # Copy the rest of the files | |
| 580 | 586 | print("[build.py] Fix includes in other .pyx files") | |
@@ -682,10 +688,12 @@ def build_cefpython_module(): | |||
| 682 | 688 | ||
| 683 | 689 | # Check if built succeeded after pyx files were removed | |
| 684 | 690 | if ret != 0: | |
| 685 | - if FIRST_RUN and os.path.exists(CEFPYTHON_H): | ||
| 691 | + if FIRST_RUN and os.path.exists(CEFPYTHON_API_HFILE): | ||
| 686 | 692 | 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.") | ||
| 689 | 697 | args = list() | |
| 690 | 698 | args.append(sys.executable) | |
| 691 | 699 | args.append(os.path.join(TOOLS_DIR, os.path.basename(__file__))) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,7 +221,7 @@ def smart_compile(compiler, macros, extra_args, sources, output_dir): | |||
| 221 | 221 | obj_time = os.path.getmtime(obj_file) | |
| 222 | 222 | source_time = os.path.getmtime(source_file) | |
| 223 | 223 | header_time = os.path.getmtime(header_file) if header_file else 0 | |
| 224 | - cefpython_h_fixed_time = os.path.getmtime(CEFPYTHON_H_FIXED) | ||
| 224 | + cefpython_h_fixed_time = os.path.getmtime(CEFPYTHON_API_HFILE_FIXED) | ||
| 225 | 225 | common_files_time = get_directory_mtime(os.path.join(SRC_DIR, | |
| 226 | 226 | "common")) | |
| 227 | 227 | changed = ((source_time > obj_time) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,9 +120,13 @@ | |||
| 120 | 120 | UNITTESTS_DIR = os.path.abspath(os.path.join(ROOT_DIR, "unittests")) | |
| 121 | 121 | # ---------------------------------------------------------------------------- | |
| 122 | 122 | ||
| 123 | - # cefpython.h and fixed version | ||
| 124 | - CEFPYTHON_H = os.path.join(BUILD_CEFPYTHON, "cefpython.h") | ||
| 125 | - CEFPYTHON_H_FIXED = os.path.join(BUILD_CEFPYTHON, "cefpython_fixed.h") | ||
| 123 | + # cefpython API header file and a fixed copy of it | ||
| 124 | + CEFPYTHON_API_HFILE = os.path.join(BUILD_CEFPYTHON, | ||
| 125 | + "cefpython_py{pyver}.h" | ||
| 126 | + .format(pyver=PYVERSION)) | ||
| 127 | + CEFPYTHON_API_HFILE_FIXED = os.path.join(BUILD_CEFPYTHON, | ||
| 128 | + "cefpython_py{pyver}_fixed.h" | ||
| 129 | + .format(pyver=PYVERSION)) | ||
| 126 | 130 | ||
| 127 | 131 | # Result libraries paths | |
| 128 | 132 | CEFPYTHON_APP_LIB = os.path.join(BUILD_CEFPYTHON_APP, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,7 +49,8 @@ | |||
| 49 | 49 | ModuleNode.generate_extern_c_macro_definition) | |
| 50 | 50 | ||
| 51 | 51 | def generate_extern_c_macro_definition(self, code): | |
| 52 | - # This code is written to both cefpython.h and cefpython.cpp | ||
| 52 | + # This code is written by Cython to both cefpython API header file | ||
| 53 | + # and cefpython module cpp file. | ||
| 53 | 54 | g_generate_extern_c_macro_definition_old(self, code) | |
| 54 | 55 | code.putln("// Added by: cefpython/tools/cython_setup.py") | |
| 55 | 56 | code.putln("#undef PyMODINIT_FUNC") | |
@@ -97,8 +98,8 @@ def main(): | |||
| 97 | 98 | ||
| 98 | 99 | print("[cython_setup.py] Execute setup()") | |
| 99 | 100 | setup( | |
| 100 | - name='cefpython_py%s' % PYVERSION, | ||
| 101 | - cmdclass={'build_ext': build_ext}, | ||
| 101 | + name="cefpython_py{pyver}".format(pyver=PYVERSION), | ||
| 102 | + cmdclass={"build_ext": build_ext}, | ||
| 102 | 103 | ext_modules=get_ext_modules(options) | |
| 103 | 104 | ) | |
| 104 | 105 | ||
@@ -370,7 +371,7 @@ def get_libraries(): | |||
| 370 | 371 | def get_ext_modules(options): | |
| 371 | 372 | ext_modules = [Extension( | |
| 372 | 373 | name=MODULE_NAME_NOEXT, | |
| 373 | - sources=["cefpython.pyx"], | ||
| 374 | + sources=["cefpython_py{pyver}.pyx".format(pyver=PYVERSION)], | ||
| 374 | 375 | ||
| 375 | 376 | # Ignore the warning in the console: | |
| 376 | 377 | # > C:\Python27\lib\distutils\extension.py:133: UserWarning: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments