Debian Codegraph @

contrib/utilities/download_clang_format

raw
1 #!/bin/bash
2 ## ------------------------------------------------------------------------
3 ##
4 ## SPDX-License-Identifier: LGPL-2.1-or-later
5 ## Copyright (C) 2018 - 2023 by the deal.II authors
6 ##
7 ## This file is part of the deal.II library.
8 ##
9 ## Part of the source code is dual licensed under Apache-2.0 WITH
10 ## LLVM-exception OR LGPL-2.1-or-later. Detailed license information
11 ## governing the source code and code contributions can be found in
12 ## LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
13 ##
14 ## ------------------------------------------------------------------------
15
16 #
17 # This script downloads and installs the clang-format binary. The
18 # destination directory is
19 # [contrib/utilities]/programs/clang-<VERSION>/bin.
20 #
21 # This script only works on Linux (amd64) and macOS. For other
22 # architectures it is necessary to compile the clang-format binary by hand.
23 # This can be done with the compile_clang_format script.
24 #
25
26 VERSION=16
27 PRG="$(cd "$(dirname "$0")" && pwd)/programs"
28 CLANG_PATH="${PRG}/clang-${VERSION}"
29
30 URL="https://github.com/dealii/dealii/releases/download/v9.5.1"
31
32 # Find out which kind of OS we are running and set the appropriate settings
33 case "${OSTYPE}" in
34 linux*)
35 FILENAME="clang-format-${VERSION}-linux.tar.gz"
36 CHECKSUM_CMD="sha256sum"
37 CHECKSUM="e6d92ab1b385f5e4392466a3cf651a9e403a5c212f4c1c3737ee173bc6d79d93 $FILENAME"
38 ;;
39 darwin*)
40 CHECKSUM_CMD="shasum"
41 ARCH=$(uname -m)
42 if [[ "$ARCH" == "arm64" ]]; then
43 FILENAME="clang-format-${VERSION}-darwin-arm.tar.gz"
44 CHECKSUM="8b1733414dec5a91e15060f482bebeb0723ac8e8f3115241c1ea595302758b46 $FILENAME"
45 else
46 FILENAME="clang-format-${VERSION}-darwin-intel.tar.gz"
47 CHECKSUM="edff4341fb3b9e25c670902227538be6348d3b91ff88aa676ff8e7bb589b2ae5 $FILENAME"
48 fi
49 ;;
50 *)
51 echo "unknown: ${OSTYPE}"
52 exit 1
53 ;;
54 esac
55
56 if [ ! -d "${PRG}" ]
57 then
58 echo "create folder ${PRG}"
59 mkdir "${PRG}"
60 fi
61
62 if [ -d "${CLANG_PATH}" ]
63 then
64 echo "${CLANG_PATH} exists. Exiting."
65 exit 1
66 fi
67
68 echo "Downloading and installing clang-format-${VERSION} from ${URL}/${FILENAME}"
69 mkdir "${CLANG_PATH}"
70
71 tmpdir="${TMPDIR:-/tmp}/dealiiclang${RANDOM}${RANDOM}"
72 mkdir -p "${tmpdir}"
73 cd "${tmpdir}"
74 if [ -x "$(command -v wget)" ]; then
75 echo "Using wget to download..."
76 # set progress option if available
77 wget --help | grep -q '\--show-progress' && \
78 _PROGRESS_OPT="--show-progress" || _PROGRESS_OPT=""
79
80 wget -q $_PROGRESS_OPT -L "${URL}/${FILENAME}" > /dev/null
81 else
82 if [ -x "$(command -v curl)" ]; then
83 echo "Using curl to download..."
84 curl --progress-bar -L "${URL}/${FILENAME}" -O > /dev/null
85 else
86 echo "Error: Neither wget nor curl is available..."
87 exit 1
88 fi
89 fi
90
91 if echo "${CHECKSUM}" | "${CHECKSUM_CMD}" -c; then
92 tar xfz "${FILENAME}" -C "${PRG}" > /dev/null
93 else
94 echo "*** The downloaded file has the wrong SHA256 checksum!"
95 exit 1
96 fi
97 rm -r "${tmpdir}"
98
99 echo "All done. clang-format successfully installed into"
100 echo " ${CLANG_PATH}/bin"