Skip to content

Commit 39b2849

Browse files
Merge branch 'chris.thuyen/chore/make_logs_informative' into 'master'
chore(*): make logs informative See merge request mobile/dax-ios/cocoapods-binary-cache!17
2 parents c84bc31 + c2e3d04 commit 39b2849

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

lib/command/PythonScripts/prebuild_lib.py

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import glob
88
from utils.fileutils import FileUtils
99
from utils.ziputils import ZipUtils
10-
from functools import wraps
1110
from utils.logger import logger
1211
from utils.step import step
1312

@@ -21,14 +20,6 @@
2120
# 3. Update tag in this file. Then submit a new MR.
2221

2322

24-
def print_func_name(func):
25-
@wraps(func)
26-
def echo_func(*func_args, **func_kwargs):
27-
logger.info('🚀 Start func: {}'.format(func.__name__))
28-
return func(*func_args, **func_kwargs)
29-
return echo_func
30-
31-
3223
class PrebuildLib:
3324
def __init__(self, config):
3425
self.cache_repo = config.cache_repo
@@ -45,23 +36,23 @@ def __init__(self, config):
4536
self.cache_libs_path = config.cache_libs_path
4637
self.devpod_cache_libs_path = config.devpod_cache_libs_path
4738

48-
@print_func_name
49-
def zip_to_cache(self, libName):
50-
zip_dest_path = os.path.join(self.cache_libs_path, f'{libName}.zip')
39+
def zip_to_cache(self, lib):
40+
zip_dest_path = os.path.join(self.cache_libs_path, f'{lib}.zip')
41+
logger.info(f'Zip {lib} to {zip_dest_path}')
5142
if os.path.exists(zip_dest_path):
52-
logger.info('Warning: lib {} already exist'.format(libName))
43+
logger.warning(f'Lib {lib} already exists at {zip_dest_path} -> Ignore zipping!')
5344
else:
5445
os.makedirs(os.path.dirname(zip_dest_path), exist_ok=True)
5546
ZipUtils.zip_dir(
56-
os.path.join(self.generated_path, libName),
47+
os.path.join(self.generated_path, lib),
5748
zip_dest_path
5849
)
5950

60-
@print_func_name
61-
def clean_cache(self, libName):
62-
FileUtils.remove_file(self.cache_libs_path + libName + ".zip")
51+
def clean_cache(self, lib):
52+
lib_path = os.path.join(self.cache_libs_path, f'{lib}.zip')
53+
logger.info(f'Clean cache of {lib} at {lib_path}')
54+
FileUtils.remove_file(lib_path)
6355

64-
@print_func_name
6556
def zip_all_libs_to_cache(self):
6657
os.system('rm -rf ' + self.cache_libs_path + '/*')
6758
FileUtils.create_dir(self.cache_libs_path)
@@ -75,30 +66,28 @@ def clean_and_pull(self, git_repo_dir):
7566
subprocess.run(['git', '-C', git_repo_dir, 'checkout', 'master'])
7667
subprocess.run(['git', '-C', git_repo_dir, 'pull', '-X', 'theirs'])
7768

78-
@print_func_name
7969
def fetch_cache(self):
70+
logger.info(f'Fetch cache to {self.cache_path}')
8071
with step('fetch_prebuild_libs'):
8172
if not os.path.exists(self.cache_path):
8273
subprocess.run(['git', 'clone', '--depth=1', self.cache_repo, self.cache_path])
8374
else:
8475
self.clean_and_pull(self.cache_path)
8576

86-
@print_func_name
8777
def unzip_cache(self):
78+
logger.info(f'Unzip cache, from {self.cache_libs_path} to {self.generated_path}')
8879
with step('unzip_prebuild_libs'):
8980
FileUtils.remove_dir(self.prebuild_path)
9081
FileUtils.create_dir(self.generated_path)
91-
FileUtils.copy_file_or_dir(self.cache_path + self.manifest_file, self.prebuild_path)
82+
FileUtils.copy_file_or_dir(os.path.join(self.cache_path, self.manifest_file), self.prebuild_path)
9283
# Unzip libs to pod-binary folder
93-
for zipPath in glob.iglob(self.cache_libs_path + '/*.zip'):
94-
ZipUtils.unzip(zipPath, self.generated_path)
84+
for zip_path in glob.iglob(os.path.join(self.cache_libs_path, '*.zip')):
85+
ZipUtils.unzip(zip_path, self.generated_path)
9586

96-
@print_func_name
9787
def fetch_and_apply_cache(self):
9888
self.fetch_cache()
9989
self.unzip_cache()
10090

101-
@print_func_name
10291
def fetch_and_apply_devpod_cache(self):
10392
with step('fetch_and_apply_devpod_cache'):
10493
logger.info('Fetching devpod cache to {}'.format(self.devpod_cache_path))
@@ -113,7 +102,6 @@ def fetch_and_apply_devpod_cache(self):
113102
for zip_path in glob.iglob(self.devpod_cache_libs_path + '/*.zip'):
114103
ZipUtils.unzip(zip_path, devpod_temp_dir)
115104

116-
@print_func_name
117105
def has_libs_change(self):
118106
if os.path.exists(self.delta_path):
119107
return True
@@ -125,7 +113,6 @@ def push_all_to_git(self, git_dir):
125113
os.system('{} commit -m "Prebuild pod libs"'.format(git_input_path))
126114
os.system('{} push'.format(git_input_path))
127115

128-
@print_func_name
129116
def prebuild_if_needed(self, push=True):
130117
self.fetch_and_apply_cache()
131118
subprocess.run(['bundle', 'exec', 'pod', 'install'], check=True)
@@ -150,11 +137,11 @@ def prebuild_if_needed(self, push=True):
150137
self.clean_cache(libName)
151138
self.zip_to_cache(libName)
152139

153-
deletedMatches = re.findall(r'Deleted: \[(.*)\]', data)
154-
if deletedMatches:
155-
deleted = deletedMatches[0].strip()
156-
logger.info('Deleted frameworks: {}'.format(deleted))
140+
match = re.findall(r'Deleted: \[(.*)\]', data)
141+
if match:
142+
deleted = match[0].strip()
157143
if len(deleted):
144+
logger.info('Deleted frameworks: {}'.format(deleted))
158145
libs = deleted.split(',')
159146
for lib in libs:
160147
self.clean_cache(lib.strip())
@@ -165,7 +152,6 @@ def prebuild_if_needed(self, push=True):
165152
except Exception as e:
166153
raise e
167154

168-
@print_func_name
169155
def prebuild_devpod(self):
170156
self.fetch_and_apply_cache()
171157
self.fetch_and_apply_devpod_cache()

0 commit comments

Comments
 (0)