Created
November 28, 2017 17:22
-
-
Save dflems/1d6f79c8a3ea9f644791131c703597bb to your computer and use it in GitHub Desktop.
Buck macros for overriding `configs`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
def merge_configs(*configs): | |
master = {} | |
for config_d in configs: | |
for key in config_d: | |
value = config_d[key] | |
if key not in master: | |
master[key] = copy.copy(value) | |
else: | |
existing = master[key] | |
if isinstance(existing, dict): | |
master[key] = merge_configs(existing, value) | |
elif isinstance(existing, list): | |
master[key] = existing + value | |
else: | |
master[key] = value # just overwrite | |
return master | |
DEFAULT_CONFIG_SET = { | |
'CLANG_CXX_LANGUAGE_STANDARD': 'c++14', | |
'IPHONEOS_DEPLOYMENT_TARGET': '10.0', | |
'SDKROOT': 'iphoneos', | |
} | |
DEFAULT_CONFIGS = { | |
'Debug': merge_configs(DEFAULT_CONFIG_SET, { | |
'GCC_OPTIMIZATION_LEVEL': '0', | |
'SWIFT_OPTIMIZATION_LEVEL': '-Onone', | |
'ONLY_ACTIVE_ARCH': 'YES', | |
}), | |
'Release': merge_configs(DEFAULT_CONFIG_SET, { | |
'GCC_OPTIMIZATION_LEVEL': 's', | |
'SWIFT_OPTIMIZATION_LEVEL': '-O -whole-module-optimization', | |
'ONLY_ACTIVE_ARCH': 'NO', | |
}), | |
'Profile': merge_configs(DEFAULT_CONFIG_SET, { | |
'GCC_OPTIMIZATION_LEVEL': 's', # ??? | |
'SWIFT_OPTIMIZATION_LEVEL': '-O -whole-module-optimization', | |
'ONLY_ACTIVE_ARCH': 'NO', | |
}), | |
} | |
def df_apple_binary(**kwargs): | |
_df_apple_tweak(kwargs) | |
apple_binary(**kwargs) | |
def df_apple_library(**kwargs): | |
_df_apple_tweak(kwargs) | |
apple_library(**kwargs) | |
def _df_apple_tweak(d): | |
d['configs'] = merge_configs(DEFAULT_CONFIGS, d.pop('configs', {})) | |
d['linker_flags'] = d.pop('linker_flags', []) + ['-ObjC'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment