|
4 | 4 |
|
5 | 5 | # Common stuff for tools such as automate.py, build.py, etc. |
6 | 6 |
|
| 7 | +import atexit |
7 | 8 | import glob |
8 | 9 | import os |
9 | 10 | import platform |
10 | 11 | import re |
11 | 12 | import shutil |
12 | 13 | import struct |
13 | 14 | import sys |
| 15 | +import tempfile |
14 | 16 |
|
15 | 17 | # These sample apps will be deleted when creating setup/wheel packages |
16 | 18 | CEF_SAMPLE_APPS = ["cefclient", "cefsimple", "ceftests", "chrome-sandbox"] |
@@ -268,26 +270,47 @@ def get_python_include_path(): |
268 | 270 | return results[0] |
269 | 271 | return ".\\" if WINDOWS else "./" |
270 | 272 |
|
| 273 | +g_deleted_sample_apps = [] |
| 274 | + |
271 | 275 |
|
272 | 276 | def delete_cef_sample_apps(caller_script, bin_dir): |
273 | 277 | """Delete CEF sample apps to reduce package size.""" |
| 278 | + atexit.register(restore_cef_sample_apps, caller_script) |
274 | 279 | for sample_app_name in CEF_SAMPLE_APPS: |
275 | 280 | sample_app = os.path.join(bin_dir, sample_app_name + APP_EXT) |
276 | 281 | # Not on all platforms sample apps may be available |
277 | 282 | if os.path.exists(sample_app): |
278 | 283 | print("[{script}] Delete {sample_app}" |
279 | 284 | .format(script=os.path.basename(caller_script), |
280 | 285 | 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) |
285 | 291 | # Also delete subdirs eg. cefclient_files/, ceftests_files/ |
286 | 292 | files_subdir = os.path.join(bin_dir, sample_app_name + "_files") |
287 | 293 | 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)] |
291 | 314 |
|
292 | 315 |
|
293 | 316 | def _detect_cef_binaries_libraries_dir(): |
|
0 commit comments