Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: third_party/libadblockplus/prepare_dependencies.py

Issue 29674555: Issue 6273 - Apply eyeo python code style (Closed)
Patch Set: Removed sys.exit() where return code is always 0 Created Jan. 29, 2018, 12:50 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 from __future__ import print_function
2
1 import sys 3 import sys
2 import os 4 import os
3 import shutil 5 import shutil
4 6
7
5 def duplicate(src, dst, symlink=False): 8 def duplicate(src, dst, symlink=False):
6 if (os.path.exists(dst)): 9 if os.path.exists(dst):
7 if (os.path.isdir(dst)): 10 if os.path.isdir(dst):
8 print('Deleting %s' % dst) 11 print('Deleting {}'.format(dst))
9 shutil.rmtree(dst); 12 shutil.rmtree(dst)
13 else:
14 # symlink
15 os.unlink(dst)
16
17 dst_parent = os.path.abspath(os.path.join(dst, os.pardir))
18 if not os.path.exists(dst_parent):
19 print('Creating parent directory {} for {}'.format(dst_parent, dst))
20 os.makedirs(dst_parent)
21
22 if symlink:
23 print('Symlinking {} to {}'.format(src, dst))
24 os.symlink(src, dst)
10 else: 25 else:
11 # symlink 26 print('Copying {} to {}'.format(src, dst))
12 os.unlink(dst) 27 shutil.copytree(src, dst)
13
14 dst_parent = os.path.abspath(os.path.join(dst, os.pardir))
15 if not os.path.exists(dst_parent):
16 print('Creating parent directory %s for %s' % (dst_parent, dst))
17 os.makedirs(dst_parent)
18 28
19 if symlink:
20 print('Symlinking %s to %s' % (src, dst))
21 os.symlink(src, dst)
22 else:
23 print('Copying %s to %s' % (src, dst))
24 shutil.copytree(src, dst)
25 29
26 def prepare_deps(): 30 def prepare_deps():
27 cwd = os.getcwd() 31 cwd = os.getcwd()
28 libadblockplus_root = os.path.join(cwd, 'src', 'third_party', 'libadblockplus' , 'third_party') 32 libadblockplus_third_party = os.path.join(cwd,
29 33 'src', 'third_party',
30 # googletest 34 'libadblockplus', 'third_party')
31 # Chromium's googletest has a bit different directories structure ('src' as su bdirectory)
32 #googletest_src = os.path.join(cwd, 'src', 'third_party', 'googletest')
33 #googletest_dst = os.path.join(libadblockplus_root, 'googletest')
34 #duplicate(googletest_src, googletest_dst)
35 35
36 # gyp 36 # googletest
37 # Chromium's gyp can't be used because of compile error: 37 #
38 # *** No rule to make target `shell/src/Main.cpp', needed by `local/armeabi-v7 a/objs/abpshell/shell/src/Main.o'. Stop. 38 # Chromium's googletest has a bit different directories structure
39 # See. https://hg.adblockplus.org/gyp/rev/fix-issue-339 39 # ('src' as subdirectory)
40 #gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp')
41 #gyp_dst = os.path.join(libadblockplus_root, 'gyp')
42 #duplicate(gyp_src, gyp_dst)
43 40
44 # back-up /v8/testing/gtest as it will be deleted while preparing v8 41 # gyp
45 gtest_bak_src = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest') 42 #
46 gtest_bak_dst = os.path.join(libadblockplus_root, 'gtest.bak') 43 # Chromium's gyp can't be used because of compile error:
47 shutil.move(gtest_bak_src, gtest_bak_dst) 44 # *** No rule to make target `shell/src/Main.cpp',
45 # needed by `local/armeabi-v7a/objs/abpshell/shell/src/Main.o'. Stop.
46 # See. https://hg.adblockplus.org/gyp/rev/fix-issue-339
48 47
49 # v8 48 # back-up /v8/testing/gtest as it will be deleted while preparing v8
50 v8_src = os.path.join(cwd, 'src', 'v8') 49 gtest_bak_src = os.path.join(libadblockplus_third_party,
51 v8_dst = os.path.join(libadblockplus_root, 'v8') 50 'v8', 'testing', 'gtest')
52 duplicate(v8_src, v8_dst) 51 gtest_bak_dst = os.path.join(libadblockplus_third_party, 'gtest.bak')
52 shutil.move(gtest_bak_src, gtest_bak_dst)
53 53
54 # restore /v8/testing/gtest from backup 54 # v8
55 shutil.move(gtest_bak_dst, gtest_bak_src) 55 v8_src = os.path.join(cwd, 'src', 'v8')
56 v8_dst = os.path.join(libadblockplus_third_party, 'v8')
57 duplicate(v8_src, v8_dst)
56 58
57 # v8/base/trace_event/common 59 # restore /v8/testing/gtest from backup
58 trace_common_src = os.path.join(cwd, 'src', 'base', 'trace_event', 'common') 60 shutil.move(gtest_bak_dst, gtest_bak_src)
59 trace_common_dst = os.path.join(libadblockplus_root, 'v8', 'base', 'trace_even t', 'common')
60 duplicate(trace_common_src, trace_common_dst)
61 61
62 # v8/build 62 # v8/testing/gtest
63 build_src = os.path.join(cwd, 'src', 'build') 63 #
64 build_dst = os.path.join(libadblockplus_root, 'v8', 'build') 64 # Chromium's gtest can't be used becuase of compile error:
65 duplicate(build_src, build_dst) 65 # fatal error: third_party/googletest/src/googletest/include/gtest/gtest_pro d.h: No such file or directory
66 # #include "third_party/googletest/src/googletest/include/gtest/gtest_prod.h "
67 # so we have to back-up gtest above and restore it
68 # after prepring of 'v8' directory
66 69
67 # v8/testing/gtest 70 for path in [
68 # Chromium's gtest can't be used becuase of compile error: 71 ('base', 'trace_event', 'common'),
69 # fatal error: third_party/googletest/src/googletest/include/gtest/gtest_prod. h: No such file or directory 72 ('build',),
70 # #include "third_party/googletest/src/googletest/include/gtest/gtest_prod.h" 73 ('tools', 'gyp'),
71 # so we have to back-up gtest above and restore it after prepring of 'v8' dire ctory 74 ('tools', 'clang'),
72 #gtest_src = os.path.join(cwd, 'src', 'testing', 'gtest') 75 ('third_party', 'icu'),
73 #gtest_dst = os.path.join(libadblockplus_root, 'v8', 'testing', 'gtest') 76 ('third_party' , 'jinja2'),
74 #duplicate(gtest_src, gtest_dst) 77 ('third_party', 'markupsafe')
78 ]:
79 src = os.path.join(cwd, 'src', *path)
80 dst = os.path.join(libadblockplus_third_party, 'v8', *path)
81 duplicate(src, dst)
75 82
76 # v8/tools/gyp
77 tools_gyp_src = os.path.join(cwd, 'src', 'tools', 'gyp')
78 tools_gyp_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'gyp')
79 duplicate(tools_gyp_src, tools_gyp_dst)
80 83
81 # v8/tools/clang 84 if __name__ == '__main__':
82 clang_src = os.path.join(cwd, 'src', 'tools', 'clang') 85 try:
83 clang_dst = os.path.join(libadblockplus_root, 'v8', 'tools', 'clang') 86 prepare_deps()
84 duplicate(clang_src, clang_dst) 87 except KeyboardInterrupt:
85 88 sys.exit('interrupted')
86 # v8/third_party/icu
87 icu_src = os.path.join(cwd, 'src', 'third_party', 'icu')
88 icu_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'icu')
89 duplicate(icu_src, icu_dst)
90
91 # v8/third_party/jinja2
92 jinja2_src = os.path.join(cwd, 'src', 'third_party', 'jinja2')
93 jinja2_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'jinja2')
94 duplicate(jinja2_src, jinja2_dst)
95
96 # v8/third_party/markupsafe
97 markupsafe_src = os.path.join(cwd, 'src', 'third_party', 'markupsafe')
98 markupsafe_dst = os.path.join(libadblockplus_root, 'v8', 'third_party', 'marku psafe')
99 duplicate(markupsafe_src, markupsafe_dst)
100
101 return 0
102
103 def main(argv):
104 return prepare_deps();
105
106 if '__main__' == __name__:
107 try:
108 sys.exit(main(sys.argv[1:]))
109 except KeyboardInterrupt:
110 sys.stderr.write('interrupted\n')
111 sys.exit(1)
OLDNEW
« no previous file with comments | « third_party/libadblockplus/download_ndk.py ('k') | third_party/libadblockplus_android/prepare_build_tools.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld