forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_wallet_source.py
94 lines (81 loc) · 2.86 KB
/
extract_wallet_source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
import os
import re
import shutil
ignore_patterns_when_copying = [
"^\\.git$",
"^.*/\\.git$",
]
def mkdir_p(path):
if not os.path.isdir(path):
os.makedirs(path)
def clean_copy_files(dir, destination_dir):
for root, dirs, files in os.walk(dir, topdown=False):
for name in files:
skip_file = False
for pattern in ignore_patterns_when_copying:
if re.match(pattern, name):
skip_file = True
break
if skip_file:
continue
file_path = os.path.relpath(os.path.join(root, name), dir)
dir_path = os.path.dirname(file_path)
mkdir_p(destination_dir + "/" + dir_path)
shutil.copy(dir + "/" + file_path, destination_dir + "/" + file_path)
for name in dirs:
skip_file = False
for pattern in ignore_patterns_when_copying:
if re.match(pattern, name):
skip_file = True
break
if skip_file:
continue
dir_path = os.path.relpath(os.path.join(root, name), dir)
if os.path.islink(dir + "/" + dir_path):
continue
mkdir_p(destination_dir + "/" + dir_path)
if len(sys.argv) != 2:
print('Usage: extract_wallet_source.py destination')
sys.exit(1)
destination = sys.argv[1]
deps_data = os.popen("""bazel query 'kind("source file", deps(//Wallet:Wallet))'""").read().splitlines()
buildfile_deps_data = os.popen("""bazel query 'buildfiles(deps(//Wallet:Wallet))'""").read().splitlines()
directories = set()
for line in deps_data + buildfile_deps_data:
if len(line) == 0:
continue
if line[:1] == "@":
continue
if line[:2] != "//":
continue
file_path = line[2:].replace(":", "/")
if file_path.startswith("build-input"):
continue
if file_path.startswith("external"):
continue
file_name = os.path.basename(file_path)
file_dir = os.path.dirname(file_path)
mkdir_p(destination + "/" + file_dir)
shutil.copy(file_path, destination + '/' + file_path)
additional_paths = [
".gitignore",
"WORKSPACE",
"build-system/xcode_version",
"build-system/bazel_version",
"build-system/bazel-rules",
"build-system/tulsi",
"build-system/prepare-build.sh",
"build-system/generate-xcode-project.sh",
"build-system/copy-provisioning-profiles-Wallet.sh",
"build-system/prepare-build-variables-Wallet.sh",
".bazelrc",
"wallet_env.sh",
]
for file_path in additional_paths:
if os.path.isdir(file_path):
clean_copy_files(file_path, destination + "/" + file_path)
else:
shutil.copy(file_path, destination + "/" + file_path)
shutil.copy("Wallet.makefile", destination + "/" + "Makefile")
shutil.copy("Wallet/README.md", destination + "/" + "README.md")