format.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. # Copyright 2020, gRPC Authors All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -eu
  16. HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  17. REPO="$HERE/.."
  18. SWIFTFORMAT_DIR="$HERE/.swiftformat-source"
  19. # Important: if this is changed then make sure to update the version
  20. # in .travis-install.sh as well!
  21. SWIFTFORMAT_VERSION=0.46.3
  22. # Clone SwiftFormat if we don't already have it.
  23. if [ ! -d "$SWIFTFORMAT_DIR" ]; then
  24. echo "- Cloning SwiftFormat @ $SWIFTFORMAT_VERSION"
  25. git clone \
  26. --depth 1 \
  27. --branch "$SWIFTFORMAT_VERSION" \
  28. https://github.com/nicklockwood/SwiftFormat.git \
  29. "$SWIFTFORMAT_DIR"
  30. fi
  31. cd "$SWIFTFORMAT_DIR"
  32. # Figure out the path for the binary.
  33. SWIFTFORMAT_BIN="$(swift build --show-bin-path -c release)/swiftformat-$SWIFTFORMAT_VERSION"
  34. # Build it if we don't already have it.
  35. if [ ! -f "$SWIFTFORMAT_BIN" ]; then
  36. # We're not on the right tag, fetch and checkout the right one.
  37. echo "- Fetching SwiftFormat @ $SWIFTFORMAT_VERSION"
  38. git fetch --depth 1 origin "refs/tags/$SWIFTFORMAT_VERSION:refs/tags/$SWIFTFORMAT_VERSION"
  39. git checkout "$SWIFTFORMAT_VERSION"
  40. # Now build and name the bin appropriately.
  41. echo "- Building SwiftFormat @ $SWIFTFORMAT_VERSION"
  42. swift build -c release --product swiftformat
  43. mv "$(swift build --show-bin-path -c release)/swiftformat" "$SWIFTFORMAT_BIN"
  44. echo "- OK"
  45. fi
  46. # Now run it.
  47. $SWIFTFORMAT_BIN "$REPO"