Skip to content

Commit

Permalink
Bash scripts: Change all non-environment variable names to lowercase.
Browse files Browse the repository at this point in the history
Inline variables that are only used once.

Improve comments.

Partial #638

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
  • Loading branch information
rgoldberg committed Nov 18, 2024
1 parent b9a1196 commit 0faa0f8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 41 deletions.
12 changes: 6 additions & 6 deletions script/build
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ fi

# Build for the host architecture by default.
if [[ "${#}" -ge 1 && "${1}" == '--universal' ]]; then
ARCH=(
arch=(
--arch arm64
--arch x86_64
)
else
ARCH=()
arch=()
fi

# Disable the manifest cache.
if [[ "$(swift build --help)" =~ manifest-cache ]]; then
CACHE=(--manifest-cache none)
cache=(--manifest-cache none)
else
CACHE=()
cache=()
fi

script/generate_version_info_for_swift

echo "==> 🏗️ Building mas $(script/version)"
swift build \
--configuration release \
"${ARCH[@]+"${ARCH[@]}"}" \
"${arch[@]+"${arch[@]}"}" \
--disable-sandbox \
"${CACHE[@]+"${CACHE[@]}"}"
"${cache[@]+"${cache[@]}"}"
20 changes: 10 additions & 10 deletions script/format
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ fi

printf $'==> 🚨 Formatting mas\n'

for LINTER in markdownlint prettier shfmt swift-format swiftformat swiftlint yamllint; do
if [[ ! -x "$(command -v "${LINTER}")" ]]; then
printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${LINTER}" "${LINTER}" >&2
for linter in markdownlint prettier shfmt swift-format swiftformat swiftlint yamllint; do
if [[ ! -x "$(command -v "${linter}")" ]]; then
printf $'error: %s is not installed. Run \'script/bootstrap\' or \'brew install %s\'.\n' "${linter}" "${linter}" >&2
exit 1
fi
done

for SOURCE in Package.swift Sources Tests; do
printf -- $'--> 🕊 %s swift-format\n' "${SOURCE}"
swift-format format --in-place --recursive "${SOURCE}"
printf -- $'--> 🕊 %s swiftformat\n' "${SOURCE}"
swiftformat "${SOURCE}"
printf -- $'--> 🕊 %s swiftlint\n' "${SOURCE}"
swiftlint --fix --strict "${SOURCE}"
for source in Package.swift Sources Tests; do
printf -- $'--> 🕊 %s swift-format\n' "${source}"
swift-format format --in-place --recursive "${source}"
printf -- $'--> 🕊 %s swiftformat\n' "${source}"
swiftformat "${source}"
printf -- $'--> 🕊 %s swiftlint\n' "${source}"
swiftlint --fix --strict "${source}"
done

printf -- $'--> 📜 Bash shfmt\n'
Expand Down
29 changes: 11 additions & 18 deletions script/package
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,31 @@ if ! cd -- "${mas_dir}"; then
exit 1
fi

BUILD_DIR=.build
COMPONENT_PACKAGE="${BUILD_DIR}/mas_components.pkg"
DISTRIBUTION_PACKAGE="${BUILD_DIR}/mas.pkg"

IDENTIFIER=com.mphys.mas-cli

# Distribution package definition
# https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html
DISTRIBUTION_PLIST=Package/Distribution.plist
build_dir=.build
distribution_package="${build_dir}/mas.pkg"

# Destination for install root
DSTROOT="${BUILD_DIR}/distributions"
script/install "${DSTROOT}/usr/local"
dstroot="${build_dir}/distributions"
script/install "${dstroot}/usr/local"

version="$(script/version)"

echo "==> 📦 Assembling installer package for mas ${version}"

# Assemble macOS installer component package (aka 'product archive').
pkgbuild \
--identifier "${IDENTIFIER}" \
--identifier com.mphys.mas-cli \
--install-location '/' \
--version "${version}" \
--root "${DSTROOT}" \
"${COMPONENT_PACKAGE}"
--root "${dstroot}" \
"${build_dir}/mas_components.pkg"

# Build distribution package (aka 'product archive'). Not sure why, but this is how Carthage does it.
# https://github.com/Carthage/Carthage/blob/master/Makefile#L69
productbuild \
--distribution "${DISTRIBUTION_PLIST}" \
--package-path "${BUILD_DIR}" \
"${DISTRIBUTION_PACKAGE}"
--distribution Package/Distribution.plist \
--package-path "${build_dir}" \
"${distribution_package}"

echo '==> 🔢 File Hash'
shasum -a 256 "${DISTRIBUTION_PACKAGE}"
shasum -a 256 "${distribution_package}"
6 changes: 3 additions & 3 deletions script/package_install
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ if ! cd -- "${mas_dir}"; then
exit 1
fi

IDENTIFIER=com.mphys.mas-cli
identifier=com.mphys.mas-cli

echo '==> 📲 Installing mas'

sudo installer \
-pkg .build/mas.pkg \
-target /

pkgutil --pkg-info "${IDENTIFIER}"
pkgutil --pkg-info "${identifier}"

pkgutil --files "${IDENTIFIER}"
pkgutil --files "${identifier}"
8 changes: 4 additions & 4 deletions script/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# script/uninstall
# mas
#
# Removes mas from PREFIX.
# Removes mas from a bin folder under a prefix folder, defaulting to /usr/local.
#

mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")"
Expand All @@ -14,8 +14,8 @@ if ! cd -- "${mas_dir}"; then
fi

# Override default prefix path with optional 1st arg
PREFIX="${1:-"$(brew --prefix)"}"
prefix="${1:-"$(brew --prefix)"}"

echo "==> 🔥 Uninstalling mas from ${PREFIX}"
echo "==> 🔥 Uninstalling mas from ${prefix}"

trash -F "${PREFIX}/bin/mas" || true
trash -F "${prefix}/bin/mas" || true

0 comments on commit 0faa0f8

Please sign in to comment.