BUCK configuration

This commit is contained in:
Peter 2019-06-06 00:17:51 +01:00
parent e09df60796
commit 124eaea2b7
28 changed files with 320 additions and 47 deletions

20
tools/buck_defs.bzl Normal file
View file

@ -0,0 +1,20 @@
SHARED_CONFIGS = {
'IPHONEOS_DEPLOYMENT_TARGET': '8.0', # common target version
'SDKROOT': 'iphoneos', # platform
'GCC_OPTIMIZATION_LEVEL': '0', # clang optimization
'SWIFT_OPTIMIZATION_LEVEL': '-Onone', # swiftc optimization
'SWIFT_WHOLE_MODULE_OPTIMIZATION': 'NO', # for build performance
'ONLY_ACTIVE_ARCH': 'YES',
'LD_RUNPATH_SEARCH_PATHS': '@executable_path/Frameworks', # To allow source files in binary
}
LIB_SPECIFIC_CONFIG = {
'SKIP_INSTALL': 'YES',
'APPLICATION_EXTENSION_API_ONLY': 'YES',
}
def combined_config(dicts):
result = dict()
for d in dicts:
result.update(d)
return result

97
tools/buck_utils.bzl Normal file
View file

@ -0,0 +1,97 @@
OTHER_LINKER_FLAGS_KEY = 'OTHER_LDFLAGS'
# Either appends or assigns `other_linker_flags` to `config` under `config_key`.
# Params:
# - config: A dictionary of config names and their values
# - additional_linker_flags: A string-representable value of additional linker flags
# - config_key: The key to which to append or assign the additional linker flags
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
# Creates a dictionary where the top level keys are the supported build configurations and the value of each key is `config`.
def configs_with_config(config):
return {
"Debug": config,
"Profile": config,
"Release": config,
}
def subdir_glob(glob_specs, exclude = None, prefix = ""):
"""Returns a dict of sub-directory relative paths to full paths.
The subdir_glob() function is useful for defining header maps for C/C++
libraries which should be relative the given sub-directory.
Given a list of tuples, the form of (relative-sub-directory, glob-pattern),
it returns a dict of sub-directory relative paths to full paths.
Please refer to native.glob() for explanations and examples of the pattern.
Args:
glob_specs: The array of tuples in form of
(relative-sub-directory, glob-pattern inside relative-sub-directory).
type: List[Tuple[str, str]]
exclude: A list of patterns to identify files that should be removed
from the set specified by the first argument. Defaults to [].
type: Optional[List[str]]
prefix: If is not None, prepends it to each key in the dictionary.
Defaults to None.
type: Optional[str]
Returns:
A dict of sub-directory relative paths to full paths.
"""
if exclude == None:
exclude = []
results = []
for dirpath, glob_pattern in glob_specs:
results.append(
_single_subdir_glob(dirpath, glob_pattern, exclude, prefix),
)
return _merge_maps(*results)
def _merge_maps(*file_maps):
result = {}
for file_map in file_maps:
for key in file_map:
if key in result and result[key] != file_map[key]:
fail(
"Conflicting files in file search paths. " +
"\"%s\" maps to both \"%s\" and \"%s\"." %
(key, result[key], file_map[key]),
)
result[key] = file_map[key]
return result
def _single_subdir_glob(dirpath, glob_pattern, exclude = None, prefix = None):
if exclude == None:
exclude = []
results = {}
files = native.glob([dirpath + '/' + glob_pattern], exclude = exclude)
for f in files:
if dirpath:
key = f[len(dirpath) + 1:]
else:
key = f
if prefix:
key =prefix + '/' + key
results[key] = f
return results