X Tutup
Skip to content

Commit 92b1895

Browse files
committed
Update build_distrib - restore sample apps in cef prebuilt directories
1 parent 5525fbb commit 92b1895

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

tools/automate.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,9 @@ def create_prebuilt_binaries():
744744
"build_cefclient", "tests", "cefclient",
745745
Options.build_type,
746746
"cefclient" + APP_EXT)
747-
if LINUX and os.path.exists(cefclient):
747+
if not MAC:
748+
assert os.path.exists(cefclient)
749+
if LINUX:
748750
# On Windows resources/*.html files are embedded inside exe
749751
cefclient_files = os.path.join(
750752
src,
@@ -759,14 +761,18 @@ def create_prebuilt_binaries():
759761
"build_cefclient", "tests", "cefsimple",
760762
Options.build_type,
761763
"cefsimple" + APP_EXT)
764+
if not MAC:
765+
assert os.path.exists(cefsimple)
762766

763767
# ceftests
764768
ceftests = os.path.join(
765769
src,
766770
"build_cefclient", "tests", "ceftests",
767771
Options.build_type,
768772
"ceftests" + APP_EXT)
769-
if LINUX and os.path.exists(ceftests):
773+
if not MAC:
774+
assert os.path.exists(ceftests)
775+
if LINUX:
770776
# On Windows resources/*.html files are embedded inside exe
771777
ceftests_files = os.path.join(
772778
src,
@@ -776,8 +782,7 @@ def create_prebuilt_binaries():
776782
cpdir(ceftests_files, os.path.join(bindir, "ceftests_files"))
777783

778784
def copy_app(app):
779-
if os.path.exists(app):
780-
if os.path.isdir(app):
785+
if MAC:
781786
# On Mac app is a directory
782787
shutil.copytree(app,
783788
os.path.join(bindir,

tools/common.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
# Common stuff for tools such as automate.py, build.py, etc.
66

7+
import atexit
78
import glob
89
import os
910
import platform
1011
import re
1112
import shutil
1213
import struct
1314
import sys
15+
import tempfile
1416

1517
# These sample apps will be deleted when creating setup/wheel packages
1618
CEF_SAMPLE_APPS = ["cefclient", "cefsimple", "ceftests", "chrome-sandbox"]
@@ -268,26 +270,47 @@ def get_python_include_path():
268270
return results[0]
269271
return ".\\" if WINDOWS else "./"
270272

273+
g_deleted_sample_apps = []
274+
271275

272276
def delete_cef_sample_apps(caller_script, bin_dir):
273277
"""Delete CEF sample apps to reduce package size."""
278+
atexit.register(restore_cef_sample_apps, caller_script)
274279
for sample_app_name in CEF_SAMPLE_APPS:
275280
sample_app = os.path.join(bin_dir, sample_app_name + APP_EXT)
276281
# Not on all platforms sample apps may be available
277282
if os.path.exists(sample_app):
278283
print("[{script}] Delete {sample_app}"
279284
.format(script=os.path.basename(caller_script),
280285
sample_app=os.path.basename(sample_app)))
281-
if os.path.isdir(sample_app):
282-
shutil.rmtree(sample_app)
283-
else:
284-
os.remove(sample_app)
286+
tmpdir = tempfile.mkdtemp()
287+
g_deleted_sample_apps.append((bin_dir,
288+
os.path.basename(sample_app),
289+
tmpdir))
290+
shutil.move(sample_app, tmpdir)
285291
# Also delete subdirs eg. cefclient_files/, ceftests_files/
286292
files_subdir = os.path.join(bin_dir, sample_app_name + "_files")
287293
if os.path.isdir(files_subdir):
288-
print("[build_distrib.py] Delete directory: {dir}/"
289-
.format(dir=os.path.basename(files_subdir)))
290-
shutil.rmtree(files_subdir)
294+
print("[{script}] Delete directory: {dir}/"
295+
.format(script=os.path.basename(caller_script),
296+
dir=os.path.basename(files_subdir)))
297+
tmpdir = tempfile.mkdtemp()
298+
g_deleted_sample_apps.append((bin_dir,
299+
os.path.basename(files_subdir),
300+
tmpdir))
301+
shutil.move(files_subdir, tmpdir)
302+
303+
304+
def restore_cef_sample_apps(caller_script):
305+
for deleted in g_deleted_sample_apps:
306+
bin_dir = deleted[0]
307+
tmp = os.path.join(deleted[2], deleted[1])
308+
print("[{script}] Restore: {path}"
309+
.format(script=os.path.basename(caller_script),
310+
path=os.path.join(bin_dir, deleted[1])))
311+
shutil.move(tmp, bin_dir)
312+
shutil.rmtree(deleted[2])
313+
del g_deleted_sample_apps[0:len(g_deleted_sample_apps)]
291314

292315

293316
def _detect_cef_binaries_libraries_dir():

0 commit comments

Comments
 (0)
X Tutup