summaryrefslogtreecommitdiff
path: root/docker/scripts/ciq-env.sh
blob: 945d59acd4ddaad94a07309ecf88d000f08f23c5 (plain) (blame)
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
#!/usr/bin/env bash
# Shared helpers for the container scripts. Source this file; don't run it.
#
# Paths, as seen inside the container:
#   /work               the project folder (bind mount)
#   /home/dev           the project's .cache/home folder (bind mount); the Garmin
#                       tools keep the SDK and device files under ~/.Garmin
#   /work/.cache/keys   the developer key (never baked into an image)

CIQ_HOME="${HOME}/.Garmin/ConnectIQ"
KEY_DIR="/work/.cache/keys"
DEV_KEY="${KEY_DIR}/developer_key.der"
BUILD_DIR="/work/build"

# Print an error and stop. Used for every user-facing failure, so the message
# says what to do next instead of leaving a bare stack trace.
die() {
  echo "error: $*" >&2
  exit 1
}

# Progress line on stderr, so stdout stays clean for machine-readable output.
log() {
  echo "==> $*" >&2
}

# Find the SDK selected by `make sdk` and put its bin/ folder on PATH.
# Sets CIQ_SDK to the SDK root folder.
ciq_require_sdk() {
  local cfg="${CIQ_HOME}/current-sdk.cfg"
  [[ -f "${cfg}" ]] || die "Connect IQ SDK not installed. Run 'make sdk' first (you accept Garmin's licence and log in there)."
  CIQ_SDK="$(tr -d '\r\n' < "${cfg}")"
  CIQ_SDK="${CIQ_SDK%/}"
  [[ -x "${CIQ_SDK}/bin/monkeyc" ]] || die "SDK folder '${CIQ_SDK}' has no bin/monkeyc. Run 'make sdk' again."
  export CIQ_SDK
  export PATH="${CIQ_SDK}/bin:${PATH}"
}

# The developer key signs every build, including test builds.
ciq_require_key() {
  [[ -f "${DEV_KEY}" ]] || die "No developer key at .cache/keys/developer_key.der. Run 'make key' first."
}

# Fail early, with a pointer to `make sdk`, when a device's files are missing.
ciq_require_device() {
  local device="$1"
  [[ -f "${CIQ_HOME}/Devices/${device}/compiler.json" ]] \
    || die "No device files for '${device}'. Is it in manifest.xml? Then run 'make sdk' to download them."
}