Skip to content

Commit 12a12ea

Browse files
committed
Add script wrapper
1 parent f0ea434 commit 12a12ea

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ Supporting different time zones requires the `tzdata` package. By default this t
1616

1717
As of Swift 6.0.1, `Locale.current` is hardcoded to be `en_001` on Linux. Manually passing a `Locale` instance to everything that uses it seems to be the only solution for using a custom `Locale` currently.
1818

19+
## Recommended VSCode extension settings
20+
21+
```json
22+
{
23+
"shellcheck.customArgs": [
24+
"-x"
25+
],
26+
"shellcheck.useWorkspaceRootAsCwd": true,
27+
"editorconfig.generateAuto": false
28+
}
29+
```
30+
1931
## TODOs
2032

2133
- TODO: Use base docker image that already includes static Linux SDK.

scripts/_script-wrapper.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/false
2+
3+
# Don't call this script directly.
4+
# Usage from other scripts:
5+
6+
# set -eo pipefail
7+
# pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null
8+
# SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
9+
#
10+
# DOCKER_IMAGE="docker.io/swift:6.1.0"
11+
# PROCESS="swift" # can be an empty string if always have to be run inside container
12+
#
13+
# do_it() {
14+
# echo "add script here"
15+
# }
16+
#
17+
# source scripts/_script-wrapper.sh
18+
19+
if [[ -n "$RUNNING_IN_CONTAINER" ]] || which "$PROCESS" > /dev/null 2>&1; then
20+
do_it
21+
elif which docker > /dev/null 2>&1; then
22+
docker run --rm \
23+
--volume .:/workspace \
24+
--user "$(id -u):$(id -g)" \
25+
--env RUNNING_IN_CONTAINER=true \
26+
"$DOCKER_IMAGE" \
27+
"/workspace/scripts/$SCRIPT_NAME"
28+
elif which podman > /dev/null 2>&1; then
29+
podman run --rm \
30+
--volume .:/workspace \
31+
--userns=keep-id \
32+
--env RUNNING_IN_CONTAINER=true \
33+
"$DOCKER_IMAGE" \
34+
"/workspace/scripts/$SCRIPT_NAME"
35+
else
36+
if [[ -n "$PROCESS" ]]; then
37+
echo "Either '$PROCESS', 'docker' or 'podman' has to be installed to run this script."
38+
else
39+
echo "Either 'docker' or 'podman' has to be installed to run this script."
40+
fi
41+
exit 1
42+
fi

scripts/format.sh

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#!/bin/bash
22

33
set -eo pipefail
4-
54
pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null
5+
SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
6+
67
DOCKER_IMAGE="docker.io/swift:6.1.0"
8+
PROCESS="swift"
79

8-
if which swift > /dev/null 2>&1; then
10+
do_it() {
911
SWIFTFORMAT="./.build/debug/swiftformat"
1012
CACHE="./.build/swiftformat-cache.json"
1113

@@ -26,19 +28,6 @@ if which swift > /dev/null 2>&1; then
2628
"$SWIFTFORMAT" --cache "$CACHE" .
2729
# https://github.com/nicklockwood/SwiftFormat/issues/1904
2830
"$SWIFTFORMAT" --cache "$CACHE" --lint --lenient .
29-
elif which docker > /dev/null 2>&1; then
30-
docker run --rm \
31-
--volume .:/workspace \
32-
--user "$(id -u):$(id -g)" \
33-
"$DOCKER_IMAGE" \
34-
"/workspace/scripts/$(basename "${BASH_SOURCE[0]}")"
35-
elif which podman > /dev/null 2>&1; then
36-
podman run --rm \
37-
--volume .:/workspace \
38-
--userns=keep-id \
39-
"$DOCKER_IMAGE" \
40-
"/workspace/scripts/$(basename "${BASH_SOURCE[0]}")"
41-
else
42-
echo "Either 'swift', 'docker' or 'podman' has to be installed to run swiftformat."
43-
exit 1
44-
fi
31+
}
32+
33+
source scripts/_script-wrapper.sh

0 commit comments

Comments
 (0)