Skip to content

Instantly share code, notes, and snippets.

@ponpoko1968
Last active Jan 4, 2016
Embed
What would you like to do?
emacs flycheckでSwiftの構文チェックを行う ref: http://qiita.com/ponpoko1968/items/78629472038c019f9f4d
$ brew instal xctool
$ xctool -workspace ./${PROJECT}.xcworkspace -scheme ${PROJECT} -reporter json-compilation-database -sdk iphonesimulator build
[
{
"command" : "<コンパイルコマンドライン>",
"file" : "<対象ファイル>",
"directory" : "<ディレクトリ>"
...
}
]
(flycheck-define-checker swift
"Flycheck plugin for for Apple's Swift programming language."
:command ("<your-bin-directory>/compile_swift"
source-original)
:error-patterns
((error line-start (file-name) ":" line ":" column ": "
"error: " (message) line-end)
(warning line-start (file-name) ":" line ":" column ": "
"warning: " (message) line-end))
:modes swift-mode)
...
(add-hook 'swift-mode-hook
'(lambda()
(add-to-list 'flycheck-checkers 'swift)
...
)
)
#!/usr/bin/env python
import sys
import json
import re
import os.path
def main():
sources=[]
with open( sys.argv[1] ) as f:
result = json.load(f)
for l in result:
line = l["command"]
dir = l["directory"]
if os.path.basename(dir) == 'Pods':
continue
primary_file = re.search("-primary-file ([^ ]+) ",line)
if primary_file:
srcs = re.search("-c (.+) -target",line)
list = []
for src in srcs.group(1).split(' '):
if src == '-primary-file':
continue
sources.append(src)
print(primary_file.group(1),file=sys.stderr)
prefix = (os.path.basename(primary_file.group(1)).split('.'))[0]
replaced = re.sub("-frontend", '-frontend -parse',line)
replaced = re.sub("-c (.+) -target", '-c ${SRCS} -primary-file $1 -target',replaced)
replaced = re.sub(prefix, '${PRIMARY_PREFIX}',replaced)
cmd = """\
#!/bin/bash
SRCS="%s"
PRIMARY=`basename $1`
PRIMARY_PREFIX=${PRIMARY%%.swift}
%s""" % (' '.join(sources), replaced)
print(cmd)
break
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment