def test_encode(self): self.assertEqual(sut.encode(['clang', "it's me", 'again']), 'clang "it\'s me" again') self.assertEqual(sut.encode(['clang', "it(s me", 'again)']), 'clang "it(s me" "again)"') self.assertEqual(sut.encode(['clang', 'redirect > it']), 'clang "redirect > it"') self.assertEqual(sut.encode(['clang', '-DKEY="VALUE"']), 'clang -DKEY=\\"VALUE\\"') self.assertEqual(sut.encode(['clang', '-DKEY="value with spaces"']), 'clang -DKEY=\\"value with spaces\\"')
def format_entry(entry): """ Generate the desired fields for compilation database entries. """ def abspath(cwd, name): """ Create normalized absolute path from input filename. """ fullname = name if os.path.isabs(name) else os.path.join(cwd, name) return os.path.normpath(fullname) logging.debug('format this command: %s', entry['command']) atoms = classify_parameters(entry['command']) if atoms['action'] <= Action.Compile: for source in atoms['files']: compiler = 'c++' if atoms['c++'] else 'cc' flags = atoms['compile_options'] flags += ['-o', atoms['output']] if atoms['output'] else [] flags += ['-x', atoms['language']] if 'language' in atoms else [] flags += [elem for arch in atoms.get('archs_seen', []) for elem in ['-arch', arch]] command = [compiler, '-c'] + flags + [source] logging.debug('formated as: %s', command) yield { 'directory': entry['directory'], 'command': encode(command), 'file': abspath(entry['directory'], source) }
def format_entry(entry): """ Generate the desired fields for compilation database entries. """ def abspath(cwd, name): """ Create normalized absolute path from input filename. """ fullname = name if os.path.isabs(name) else os.path.join(cwd, name) return os.path.normpath(fullname) logging.debug('format this command: %s', entry['command']) atoms = classify_parameters(entry['command']) if atoms['action'] <= Action.Compile: for source in atoms['files']: compiler = 'c++' if atoms['c++'] else 'cc' flags = atoms['compile_options'] flags += ['-o', atoms['output']] if atoms['output'] else [] flags += ['-x', atoms['language']] if 'language' in atoms else [] flags += [ elem for arch in atoms.get('archs_seen', []) for elem in ['-arch', arch] ] command = [compiler, '-c'] + flags + [source] logging.debug('formated as: %s', command) yield { 'directory': entry['directory'], 'command': encode(command), 'file': abspath(entry['directory'], source) }
def format_entry(exec_trace): """ Generate the desired fields for compilation database entries. """ def abspath(cwd, name): """ Create normalized absolute path from input filename. """ fullname = name if os.path.isabs(name) else os.path.join(cwd, name) return os.path.normpath(fullname) logging.debug('format this command: %s', exec_trace['command']) compilation = split_command(exec_trace['command']) if compilation: for source in compilation.files: compiler = 'c++' if compilation.compiler == 'c++' else 'cc' command = [compiler, '-c'] + compilation.flags + [source] logging.debug('formated as: %s', command) yield { 'directory': exec_trace['directory'], 'command': encode(command), 'file': abspath(exec_trace['directory'], source) }
def test(value): self.assertEqual(sut.decode(sut.encode(value)), value)