File: create_bazel_dmg.sh

package info (click to toggle)
bazel-bootstrap 4.2.3%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 85,476 kB
  • sloc: java: 721,710; sh: 55,859; cpp: 35,359; python: 12,139; xml: 295; objc: 269; makefile: 113; ansic: 106; ruby: 3
file content (95 lines) | stat: -rwxr-xr-x 2,532 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash

# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# The script for creating a dmg file for Bazel installation on macOS.

set -e

for i in "$@"
do
case $i in
    # The Bazel binary we are going to ship
    --bazel_binary=*)
    BAZEL_BINARY="${i#*=}"
    ;;

    # (Optional) The macOS resource file for Bazel icon (.rsrc)
    --bazel_icon*)
    BAZEL_ICON="${i#*=}"
    ;;

    # (Optional) The .DS_STORE we use for the dmg file, which contains
    # information about the layout and background of the dmg disk.
    --ds_store=*)
    DS_STORE="${i#*=}"
    ;;

    # (Optional) The background we use when opening the dmg file.
    # It will only work with a corresponding .DS_STORE file.
    --background=*)
    BACKGROUND="${i#*=}"
    ;;

    # The output dmg file
    --output=*)
    OUTPUT="${i#*=}"
    ;;

    *)
    echo "Warning: Unknown option ${i}"
    ;;
esac
done

if [ -z "${BAZEL_BINARY}" ]; then
    echo "Error: Bazel binary must be specified by --bazel_binary"
    exit 1
fi

if [ -z "${OUTPUT}" ]; then
    echo "Error: Output dmg file must be specified by --output"
    exit 1
fi

TMP_DIR="$(mktemp -d -t bazel-dmg-XXXX)"
trap "rm -rf ${TMP_DIR}" EXIT

cp "${BAZEL_BINARY}" "${TMP_DIR}/bazel"
ln -s /usr/local/bin "${TMP_DIR}/bin"

# Set Bazel icon
if [ -n "${BAZEL_ICON}" ]; then
    chmod +w "${TMP_DIR}/bazel"
    # Append icon resource file for the Bazel binary
    Rez -append "${BAZEL_ICON}" -o "${TMP_DIR}/bazel"
    # Set Custom icon attribute for the Bazel binary
    SetFile -a C "${TMP_DIR}/bazel"
    chmod 0755 "${TMP_DIR}/bazel"
fi

# Use a preconfigured .DS_STORE and set the background image
if [ -n "${DS_STORE}" ]; then
    cp "${DS_STORE}" "${TMP_DIR}/.DS_Store"

    if [ -n "${BACKGROUND}" ]; then
        mkdir "${TMP_DIR}/.background"
        cp "${BACKGROUND}" "${TMP_DIR}/.background/"
    fi
fi

# Create the dmg file
hdiutil create "${OUTPUT}" -ov -volname "bazel-install" -format UDZO -fs HFS+ -srcfolder "${TMP_DIR}"