Skip to content

Commit 06d3b8c

Browse files
committed
Fix build_distrib.py script for Python 2.7 and Python 3.4 (latest pip
versions are broken with these old Pythons). Fix screenshot.py example sometimes failing. When compiling for Python 3.4 you can encounter the the missing "ammintrin.h" header file error. Just copy it from the VS 2019 include/ directory. For Pythons 3.5 / 3.6 / 3.7 / 3.8 / 3.9 you can use the same VC++ 14.2 (VS 2019) compiler which is binary compatible with VC++ 14.1 (VS 2017) and VC++ 14.0 (VS 2015). Currently the subprocess.exe executable built by Python 3.4 (VC++ 10.0 compiler) gives the least amount of false-positives by AVs on virustotal.com . For comparison: Py34 (1/69), Py27 (2/69), Py39 (5/69). Results differ for 32bit and 64bit binaries.
1 parent 3beaaf5 commit 06d3b8c

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

examples/screenshot.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def save_screenshot(browser):
158158
"raw", "RGBA", 0, 1)
159159
image.save(SCREENSHOT_PATH, "PNG")
160160
print("[screenshot.py] Saved image: {path}".format(path=SCREENSHOT_PATH))
161+
# See comments in exit_app() why PostTask must be used
162+
cef.PostTask(cef.TID_UI, exit_app, browser)
161163

162164

163165
def open_with_default_application(path):
@@ -188,9 +190,10 @@ def OnLoadingStateChange(self, browser, is_loading, **_):
188190
# Loading is complete
189191
sys.stdout.write(os.linesep)
190192
print("[screenshot.py] Web page loading is complete")
191-
save_screenshot(browser)
192-
# See comments in exit_app() why PostTask must be used
193-
cef.PostTask(cef.TID_UI, exit_app, browser)
193+
print("[screenshot.py] Will save screenshot in 2 seconds")
194+
# Give up to 2 seconds for the OnPaint call. Most of the time
195+
# it is already called, but sometimes it may be called later.
196+
cef.PostDelayedTask(cef.TID_UI, 2000, save_screenshot, browser)
194197

195198
def OnLoadError(self, browser, frame, error_code, failed_url, **_):
196199
"""Called when the resource load for a navigation fails

tools/build_distrib.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,14 @@ def install_upgrade_requirements(pythons):
353353
" for: {name}".format(name=python["name"]))
354354

355355
# Upgrade pip
356-
command = ("\"{python}\" -m pip install --upgrade pip"
357-
.format(python=python["executable"]))
356+
pip_version = "pip"
357+
# Old Python versions require specific versions of pip, latest versions are broken with these.
358+
if python["version2"] == (2, 7):
359+
pip_version = "pip==20.3.4"
360+
elif python["version2"] == (3, 4):
361+
pip_version = "pip==19.1.1"
362+
command = ("\"{python}\" -m pip install --upgrade {pip_version}"
363+
.format(python=python["executable"], pip_version=pip_version))
358364
command = sudo_command(command, python=python["executable"])
359365
pcode = subprocess.call(command, shell=True)
360366
if pcode != 0:
@@ -522,39 +528,37 @@ def build_cefpython_modules(pythons, arch):
522528

523529

524530
def backup_subprocess_executable_issue342(python):
525-
"""Use subprocess executable build by Python 2.7 to avoid
526-
false-positives by AVs when building subprocess with Python 3.
527-
Windows-only issue."""
531+
"""Use subprocess executable built by Python 3.4 to have the least amount of
532+
false-positives by AVs. Windows-only issue."""
528533
if not WINDOWS:
529534
return
530535
if python["version2"] == (2, 7):
531536
print("[build_distrib.py] Backup subprocess executable built"
532-
" with Python 2.7 (Issue #342)")
537+
" with Python 3.4 (Issue #342)")
533538
cefpython_binary_basename = get_cefpython_binary_basename(
534539
get_os_postfix2_for_arch(python["arch"]))
535540
cefpython_binary = os.path.join(BUILD_DIR, cefpython_binary_basename)
536541
assert os.path.isdir(cefpython_binary)
537542
src = os.path.join(cefpython_binary, "subprocess.exe")
538543
dst = os.path.join(BUILD_CEFPYTHON,
539-
"subprocess_py27_{arch}_issue342.exe"
544+
"subprocess_py34_{arch}_issue342.exe"
540545
.format(arch=python["arch"]))
541546
shutil.copy(src, dst)
542547

543548

544549
def restore_subprocess_executable_issue342(arch):
545-
"""Use subprocess executable build by Python 2.7 to avoid
546-
false-positives by AVs when building subprocess with Python 3.
547-
Windows-only issue."""
550+
"""Use subprocess executable built by Python 3.4 to have the least amount of
551+
false-positives by AVs. Windows-only issue."""
548552
if not WINDOWS:
549553
return
550554
print("[build_distrib.py] Restore subprocess executable built"
551-
" with Python 2.7 (Issue #342)")
555+
" with Python 3.4 (Issue #342)")
552556
cefpython_binary_basename = get_cefpython_binary_basename(
553557
get_os_postfix2_for_arch(arch))
554558
cefpython_binary = os.path.join(BUILD_DIR, cefpython_binary_basename)
555559
assert os.path.isdir(cefpython_binary)
556560
src = os.path.join(BUILD_CEFPYTHON,
557-
"subprocess_py27_{arch}_issue342.exe"
561+
"subprocess_py34_{arch}_issue342.exe"
558562
.format(arch=arch))
559563
assert os.path.isfile(src)
560564
dst = os.path.join(cefpython_binary, "subprocess.exe")

0 commit comments

Comments
 (0)