format-source.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh -exuo pipefail
  2. # brew install clang-format
  3. SWIFT_FORMAT_VERSION='0.44.5'
  4. CLANG_FORMAT_VERSION=`clang-format -version | awk '{ print $3 }'`
  5. if [[ "$CLANG_FORMAT_VERSION" != "9.0.0" ]]; then
  6. echo "Unsupported clang-format version"
  7. exit 1
  8. fi
  9. if [[ ! -f "build/swiftformat" ]]; then
  10. mkdir -p "build"
  11. curl -sfL -o "build/SwiftFormat.zip" "https://github.com/nicklockwood/SwiftFormat/archive/$SWIFT_FORMAT_VERSION.zip"
  12. unzip "build/SwiftFormat.zip" "SwiftFormat-$SWIFT_FORMAT_VERSION/CommandLineTool/swiftformat" -d "build"
  13. mv "build/SwiftFormat-$SWIFT_FORMAT_VERSION/CommandLineTool/swiftformat" "build/swiftformat"
  14. fi
  15. pushd "GCDWebServer/Core"
  16. clang-format -style=file -i *.h *.m
  17. popd
  18. pushd "GCDWebServer/Requests"
  19. clang-format -style=file -i *.h *.m
  20. popd
  21. pushd "GCDWebServer/Responses"
  22. clang-format -style=file -i *.h *.m
  23. popd
  24. pushd "GCDWebUploader"
  25. clang-format -style=file -i *.h *.m
  26. popd
  27. pushd "GCDWebDAVServer"
  28. clang-format -style=file -i *.h *.m
  29. popd
  30. pushd "Frameworks"
  31. clang-format -style=file -i *.h *.m
  32. popd
  33. pushd "Mac"
  34. clang-format -style=file -i *.m
  35. popd
  36. build/swiftformat --indent 2 "iOS" "tvOS"
  37. echo "OK"