forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.bzl
103 lines (81 loc) · 2.91 KB
/
utils.bzl
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
94
95
96
97
98
99
100
101
102
OTHER_LINKER_FLAGS_KEY = 'OTHER_LDFLAGS'
def config_with_updated_linker_flags(config, other_linker_flags, config_key=OTHER_LINKER_FLAGS_KEY):
new_config = { }
config_key_found = False
for key in config:
if key == config_key:
new_config[key] = config[key] + (" %s" % other_linker_flags)
config_key_found = True
else:
new_config[key] = config[key]
if config_key_found == False:
# If `config` does not currently contain `config_key`, add it. Inherit for good measure.
new_config[config_key] = '$(inherited) ' + other_linker_flags
return new_config
def xcode_configs(config):
return {
"Debug": config,
"Profile": config,
"Release": config,
}
def merge_maps(dicts):
result = dict()
for d in dicts:
for key in d:
if key in result and result[key] != d[key]:
fail(
"Conflicting files in file search paths. " +
"\"%s\" maps to both \"%s\" and \"%s\"." %
(key, result[key], d[key]),
)
result.update(d)
return result
def basename(p):
return p.rpartition("/")[-1]
def glob_map(glob_results):
result = dict()
for path in glob_results:
file_name = basename(path)
if file_name in result:
fail('\"%s\" maps to both \"%s\" and \"%s\"' % (file_name, result[file_name], path))
result[file_name] = path
return result
def glob_sub_map(prefix, glob_specs):
result = dict()
for path in native.glob(glob_specs):
if not path.startswith(prefix):
fail('\"%s\" does not start with \"%s\"' % (path, prefix))
file_key = path[len(prefix):]
if file_key in result:
fail('\"%s\" maps to both \"%s\" and \"%s\"' % (file_key, result[file_key], path))
result[file_key] = path
return result
def gen_header_targets(header_paths, prefix, flavor, source_rule, source_path):
result = dict()
for header_path in header_paths:
name = prefix + header_path.replace('/', '_sub_')
native.genrule(
name = name + flavor,
cmd = 'cp $(location :' + source_rule + ')/' + source_path + '/' + header_path + ' $OUT',
out = name,
)
result[header_path] = ':' + name + flavor
return result
def lib_basename(name):
result = name
if result.startswith('lib'):
result = result[3:]
if result.endswith('.a'):
result = result[:-2]
return result
def combined_config(dicts):
result = dict()
for d in dicts:
result.update(d)
return result
valid_build_variants = ['project', 'release']
def get_build_variant():
build_variant = native.read_config('build', 'variant', '')
if build_variant not in valid_build_variants:
fail('build_variant should be one of %s' % valid_build_variants)
return build_variant