Last active
January 4, 2016 03:47
-
-
Save ponpoko1968/a6c89dcb8a2510bf7bef to your computer and use it in GitHub Desktop.
emacs flycheckでSwiftの構文チェックを行う ref: http://qiita.com/ponpoko1968/items/78629472038c019f9f4d
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
$ brew instal xctool |
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
$ xctool -workspace ./${PROJECT}.xcworkspace -scheme ${PROJECT} -reporter json-compilation-database -sdk iphonesimulator build |
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
[ | |
{ | |
"command" : "<コンパイルコマンドライン>", | |
"file" : "<対象ファイル>", | |
"directory" : "<ディレクトリ>" | |
... | |
} | |
] |
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
(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) | |
... | |
) | |
) | |
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
#!/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