Skip to content

Commit bea4e89

Browse files
committed
SwiftPM support
1 parent cc0f40f commit bea4e89

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

pre_commit/languages/all.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pre_commit.languages import python
77
from pre_commit.languages import ruby
88
from pre_commit.languages import script
9+
from pre_commit.languages import swift
910
from pre_commit.languages import system
1011

1112
# A language implements the following constant and two functions in its module:
@@ -47,6 +48,7 @@
4748
'python': python,
4849
'ruby': ruby,
4950
'script': script,
51+
'swift': swift,
5052
'system': system,
5153
}
5254

pre_commit/languages/swift.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from __future__ import unicode_literals
2+
3+
from pre_commit.languages import helpers
4+
from pre_commit.util import clean_path_on_failure
5+
from pre_commit.util import cwd
6+
from pre_commit.languages import helpers
7+
from pre_commit.xargs import xargs
8+
9+
ENVIRONMENT_DIR = None
10+
BUILD_DIR = '.build'
11+
BUILD_CONFIG = 'release'
12+
13+
def install_environment(
14+
repo_cmd_runner,
15+
version='default',
16+
additional_dependencies=(),
17+
):
18+
# Build the swift package
19+
with clean_path_on_failure(repo_cmd_runner.path(BUILD_DIR)):
20+
repo_cmd_runner.run((
21+
'swift', 'build',
22+
'-C', '{prefix}',
23+
'-c', BUILD_CONFIG,
24+
'--build-path', repo_cmd_runner.path(BUILD_DIR),
25+
))
26+
27+
def run_hook(repo_cmd_runner, hook, file_args):
28+
with(cwd(repo_cmd_runner.path(BUILD_DIR, BUILD_CONFIG))):
29+
return xargs(helpers.to_cmd(hook), file_args)

0 commit comments

Comments
 (0)