def test_match_uplid(self): # format: # { configure uplid: ((matched masks), (unmatched masks)) } uplid_masks = { 'unix-linux-x86-3.2.0-gcc-4.7.2': (('unix', 'unix-', 'unix-*-x86', 'unix-linux-x86-3.2.0', 'unix-linux-x86-3.1.9', 'unix-linux-x86-2.9.9', 'unix-linux-x86-3.2.0-gcc', 'unix-linux-x86-3.2.0-gcc-4.7.2', 'unix-linux-x86-3.2.0-gcc-4.7.1', 'unix-linux-x86-3.2.0-gcc-4.6.2', 'unix-linux-x86-3.2.0-gcc-3.7.2'), ('windows', 'unix-sunos', 'unix-linux-pcc', 'unix-linux-x86-3.2.1', 'unix-linux-x86-3.3.0', 'unix-linux-x86-4.0.0', 'unix-linux-x86-3.2.0-clang', 'unix-linux-x86-3.2.0-gcc-4.7.3', 'unix-linux-x86-3.2.0-gcc-4.10.1', 'unix-linux-x86-3.2.0-gcc-4.7.2.3', 'unix-linux-x86-3.2.0-gcc-5.1.9')), 'unix-linux-x86-3.2.0-gcc-clang': (('unix', 'unix-*-x86', 'unix-linux-x86-3.2.0', 'unix-linux-x86-3.2.0-gcc-clang'), ('windows', 'unix-linux-x86-3.2.0-gcc-5.1.9')) } for uplid_str in uplid_masks: masks = uplid_masks[uplid_str] matched_masks = masks[0] unmatched_masks = masks[1] uplid = optiontypes.Uplid.from_str(uplid_str) for mask_str in matched_masks: mask = optiontypes.Uplid.from_str(mask_str) self.assertTrue(optionsutil.match_uplid(uplid, mask), 'uplid: %s mask: %s' % (uplid, mask)) for mask_str in unmatched_masks: mask = optiontypes.Uplid.from_str(mask_str) self.assertFalse(optionsutil.match_uplid(uplid, mask), 'uplid: %s mask: %s' % (uplid, mask))
def _match_rule(self, option_rule): """Determine if an option rule matches with the build configuration. """ # These keys are used to preserve backwards compatibility with # bde_build.pl and should be ignored. ignore_keys = ('XLC_INTERNAL_PREFIX1', 'XLC_INTERNAL_PREFIX2', 'AIX_GCC_PREFIX', 'SUN_CC_INTERNAL_PREFIX', 'SUN_GCC_INTERNAL_PREFIX', 'LINUX_GCC_PREFIX', 'WINDOWS_CC_PREFIX', 'RETRY_ON_SIGNAL') if option_rule.key in ignore_keys: return False global DEFAULT_COMPILER if not optionsutil.match_uplid(self._uplid, option_rule.uplid, DEFAULT_COMPILER): return False if not optionsutil.match_ufid(self._ufid, option_rule.ufid): return False return True
def _match_rule(self, option_rule): """Determine if an option rule matches with the build configuration. """ if not optionsutil.match_uplid(self._uplid, option_rule.uplid): return False if not optionsutil.match_ufid(self._ufid, option_rule.ufid): return False return True
def get_compilerinfos(hostname, uplid, file_): """Get the list of applicable compilers from a compiler config file. Args: hostname (str): Hostname of the machine to be matched. uplid (str): UPLID of the machine to be matched. file_ (File): The compiler configuration file. Returns: list of matched CompilerInfo objects. """ loaded_value = json.load(file_) matched_obj = None for obj in loaded_value: if 'hostname' in obj: m = re.match(obj['hostname'], hostname) if not m: continue uplid_mask = optiontypes.Uplid.from_str(obj['uplid']) if not optionsutil.match_uplid(uplid, uplid_mask): continue matched_obj = obj break if not matched_obj: return [] infos = [] for compiler in matched_obj['compilers']: type_ = compiler['type'] version = compiler['version'] c_path = compiler['c_path'] cxx_path = compiler['cxx_path'] if 'toolchain' in compiler: toolchain = compiler['toolchain'] else: toolchain = None if 'flags' in compiler: flags = compiler['flags'] else: flags = None info = CompilerInfo(type_, version, c_path, cxx_path, toolchain, flags) infos.append(info) return infos
def get_compilerinfos(hostname, uplid, file_): """Get the list of applicable compilers from a compiler config file. Args: hostname (str): Hostname of the machine to be matched. uplid (str): UPLID of the machine to be matched. file_ (File): The compiler configuration file. Returns: list of matched CompilerInfo objects. """ loaded_value = json.load(file_) matched_obj = None for obj in loaded_value: if 'hostname' in obj: m = re.match(obj['hostname'], hostname) if not m: continue uplid_mask = optiontypes.Uplid.from_str(obj['uplid']) if not optionsutil.match_uplid(uplid, uplid_mask): continue matched_obj = obj break if not matched_obj: return None infos = [] for compiler in matched_obj['compilers']: type_ = compiler['type'] version = compiler['version'] c_path = compiler['c_path'] cxx_path = compiler['cxx_path'] if 'flags' in compiler: flags = compiler['flags'] else: flags = None info = CompilerInfo(type_, version, c_path, cxx_path, flags) infos.append(info) return infos
def detect_installed_compilers(uplid): """Find installed system compilers. This function is expected to work primarily on Linux/Darwin in OSS environment. Args: uplid (str): UPLID of the machine to be matched. Returns: list of matched CompilerInfo objects. """ default_config=''' [ { "uplid": "unix-linux-", "compilers": [ { "type": "gcc", "c_name": "gcc", "cxx_name": "g++", "toolchain": "gcc-default" }, { "type": "gcc", "c_name": "gcc-5", "cxx_name": "g++-5", "toolchain": "gcc-default" }, { "type": "gcc", "c_name": "gcc-6", "cxx_name": "g++-6", "toolchain": "gcc-default" }, { "type": "gcc", "c_name": "gcc-7", "cxx_name": "g++-7", "toolchain": "gcc-default" }, { "type": "gcc", "c_name": "gcc-8", "cxx_name": "g++-8", "toolchain": "gcc-default" }, { "type": "gcc", "c_name": "gcc-9", "cxx_name": "g++-9", "toolchain": "gcc-default" }, { "type": "clang", "c_name": "clang", "cxx_name": "clang++", "toolchain": "clang-default" }, { "type": "clang", "c_name": "clang-7", "cxx_name": "clang++-7", "toolchain": "clang-default" }, { "type": "clang", "c_name": "clang-8", "cxx_name": "clang++-8", "toolchain": "clang-default" }, { "type": "clang", "c_name": "clang-9", "cxx_name": "clang++-9", "toolchain": "clang-default" } ] }, { "uplid": "unix-darwin-", "compilers": [ { "type": "clang", "c_name": "clang", "cxx_name": "clang++", "toolchain": "clang-default" } ] } ] ''' loaded_value = json.loads(default_config) matched_obj = None for obj in loaded_value: uplid_mask = optiontypes.Uplid.from_str(obj['uplid']) if not optionsutil.match_uplid(uplid, uplid_mask): continue matched_obj = obj break if not matched_obj: return [] infos = [] for compiler in matched_obj['compilers']: c_path = get_command_output(['which', compiler['c_name'] ]) cxx_path = get_command_output(['which', compiler['cxx_name'] ]) if (c_path and os.path.exists(c_path) and cxx_path and os.path.isfile(cxx_path)): version = get_compiler_version(compiler['type'], cxx_path) if 'toolchain' in compiler: toolchain = compiler['toolchain'] else: toolchain = None info = CompilerInfo(compiler['type'], version, c_path, cxx_path, toolchain, None) infos.append(info) return infos