def classify_parameters(command): """ Prepare compiler flags (filters some and add others) and take out language (-x) and architecture (-arch) flags for future processing. """ result = { 'flags': [], # the filtered compiler flags 'arch_list': [], # list of architecture flags 'language': None, # compilation language, None, if not specified 'compiler': compiler_language(command) # 'c' or 'c++' } # iterate on the compile options args = iter(command[1:]) for arg in args: # take arch flags into a separate basket if arg == '-arch': result['arch_list'].append(next(args)) # take language elif arg == '-x': result['language'] = next(args) # parameters which looks source file are not flags elif re.match(r'^[^-].+', arg) and classify_source(arg): pass # ignore some flags elif arg in IGNORED_FLAGS: count = IGNORED_FLAGS[arg] for _ in range(count): next(args) # we don't care about extra warnings, but we should suppress ones # that we don't want to see. elif re.match(r'^-W.+', arg) and not re.match(r'^-Wno-.+', arg): pass # and consider everything else as compilation flag. else: result['flags'].append(arg) return result
def test_is_compiler_call(self): self.assertIsNotNone(sut.compiler_language(['clang'])) self.assertIsNotNone(sut.compiler_language(['clang-3.6'])) self.assertIsNotNone(sut.compiler_language(['clang++'])) self.assertIsNotNone(sut.compiler_language(['clang++-3.5.1'])) self.assertIsNotNone(sut.compiler_language(['cc'])) self.assertIsNotNone(sut.compiler_language(['c++'])) self.assertIsNotNone(sut.compiler_language(['gcc'])) self.assertIsNotNone(sut.compiler_language(['g++'])) self.assertIsNotNone(sut.compiler_language(['/usr/local/bin/gcc'])) self.assertIsNotNone(sut.compiler_language(['/usr/local/bin/g++'])) self.assertIsNotNone(sut.compiler_language(['/usr/local/bin/clang'])) self.assertIsNotNone( sut.compiler_language(['armv7_neno-linux-gnueabi-g++'])) self.assertIsNone(sut.compiler_language([])) self.assertIsNone(sut.compiler_language([''])) self.assertIsNone(sut.compiler_language(['ld'])) self.assertIsNone(sut.compiler_language(['as'])) self.assertIsNone(sut.compiler_language(['/usr/local/bin/compiler']))