[M120 Migration] Optimize chromium rebuilds 28/311328/2
authorMichal Jurkiewicz <m.jurkiewicz@samsung.com>
Wed, 15 May 2024 12:02:01 +0000 (14:02 +0200)
committerBot Blink <blinkbot@samsung.com>
Fri, 17 May 2024 21:49:33 +0000 (21:49 +0000)
Port the following patch from tizen 7.5:

  * [M108 Migration] Optimize chromium rebuilds
    https://review.tizen.org/gerrit/c/platform/framework/web/chromium-efl/+/290585

Bug: https://cam.sprc.samsung.pl/browse/VDWASM-1212
Signed-off-by: Michal Jurkiewicz <m.jurkiewicz@samsung.com>
Change-Id: I50fef0b948d3f265d36e41b7019ae81687f689fc

build/linux/unbundle/replace_gn_files.py
tizen_src/downloadable/ewk_api_wrapper_generator.py

index c1b1094b7e08a8ec1557d68db1da67d9b8d8b626..c5b247fbce61f17e500c808c2dd1f95c0c3f29a4 100755 (executable)
@@ -103,8 +103,11 @@ def DoMain(argv):
       try:
         # Restore original file, and also remove the backup.
         # This is meant to restore the source tree to its original state.
-        os.rename(os.path.join(source_tree_root, path + '.orig'),
-                  os.path.join(source_tree_root, path))
+        orig_file = os.path.join(source_tree_root, path + '.orig')
+        dest_file = os.path.join(source_tree_root, path)
+        stat = os.stat(orig_file)
+        os.rename(orig_file, dest_file)
+        os.utime(dest_file, (stat.st_atime, stat.st_mtime))
       except OSError:
         # .orig file may be not created (when we skip fetching the target
         # library due to unexpected termination), so just ignore the error.
@@ -112,8 +115,11 @@ def DoMain(argv):
     else:
       try:
         # Create a backup copy for --undo.
-        shutil.copyfile(os.path.join(source_tree_root, path),
-                        os.path.join(source_tree_root, path + '.orig'))
+        base_file = os.path.join(source_tree_root, path)
+        orig_file = os.path.join(source_tree_root, path + '.orig')
+        stat = os.stat(base_file)
+        shutil.copy2(base_file, orig_file)
+        os.utime(orig_file, (stat.st_atime, stat.st_mtime))
       except IOError:
         # This exception may happen when the target directory does not exist,
         # which is the case when we skip fetching the third_party library due to unexpected
@@ -132,12 +138,14 @@ def DoMain(argv):
       dst = os.path.join(source_tree_root, path)
       print('** use system %s library **' % lib)
       print('  From %s\n  To %s' % (src, dst))
-      shutil.copyfile(src, dst)
+      stat = os.stat(src)
+      shutil.copy2(src, dst)
+      os.utime(dst, (stat.st_atime, stat.st_mtime))
       src = os.path.join(my_dirname, '%s' % lib)
       # Copy the additional configuration files from directory of this script to target path.
       if os.path.isdir(src):
         dst = os.path.join(source_tree_root, 'third_party')
-        os.system("cp -rf " + src + " " + dst)
+        os.system("cp -rpf " + src + " " + dst)
         print('  From %s\n  To %s' % (src, dst))
 
   unhandled_libraries = set(args.system_libraries) - handled_libraries
index 35bac1dda6a3aa1f2a160c3fa5ca01c5333fe56f..25f4cc5c3d2ccc94fd0c1862ff25f2dc30dd2f1f 100644 (file)
@@ -1,7 +1,11 @@
+import filecmp
 import glob
 import sys
 import os
+import shutil
+import tempfile
 from optparse import OptionParser
+from pathlib import Path
 
 # Text file containing list of EWK APIs
 filepath = 'API_LIST.txt'
@@ -23,15 +27,26 @@ headers_list_inc = ["EWebKit.h", "EWebKit_internal.h", "EWebKit_product.h", "dlf
 basepath = os.path.dirname(os.path.realpath(__file__))
 path = basepath + "/../ewk/efl_integration/public/ewk*.h"
 
-files = glob.glob(path)
-with open(filepath, 'w') as outfile:
-  for file in files:
-    if (file.find("ewk_export.h") != -1):
-      continue;
-    f = open(file, 'r')
-    for line in f:
-      outfile.write(line)
-    f.close()
+with tempfile.TemporaryDirectory() as tmp_dir:
+  backup_filepath = os.path.join(Path(tmp_dir), filepath)
+  api_list_exists = os.path.isfile(filepath)
+  if api_list_exists:
+    shutil.move(filepath, backup_filepath)
+
+  files = glob.glob(path)
+  with open(filepath, 'w') as outfile:
+    for file in files:
+      if (file.find("ewk_export.h") != -1):
+        continue;
+      f = open(file, 'r')
+      for line in f:
+        outfile.write(line)
+      f.close()
+
+  api_list_is_the_same = api_list_exists and filecmp.cmp(filepath, backup_filepath)
+  if api_list_is_the_same:
+    # No action will be performed, API_LIST.txt file has not been changed.
+    sys.exit(0)
 
 # Extract lines containing EXPORT_API
 api_line = ""