From 6b1903cde901ec087f3825f8d40b87f67a23f87b Mon Sep 17 00:00:00 2001 From: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:21:37 -0500 Subject: [PATCH] `cd` into root of mas project at beginning of every bash script. Partial #638 Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com> --- script/bottle | 9 ++++++++- script/brew_build_interactive | 7 +++++++ script/brew_core_update | 10 ++++++++-- script/brew_release_validate | 7 +++++++ script/brew_tap_update | 7 +++++++ script/build_artifacts | 7 +++++++ script/clean | 7 +++++++ script/install | 7 +++++++ script/package | 11 +++++++++-- script/package_install | 7 +++++++ script/uninstall | 7 +++++++ script/update_headers | 7 +++++++ 12 files changed, 88 insertions(+), 5 deletions(-) diff --git a/script/bottle b/script/bottle index 9146450..17cdf14 100755 --- a/script/bottle +++ b/script/bottle @@ -14,7 +14,14 @@ # Variables # -BUILD_DIR="${PWD}/.build" +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + +BUILD_DIR=.build BOTTLE_DIR="${BUILD_DIR}/bottles" CORE_TAP_PATH="$(brew --repo homebrew/core)" MAS_VERSION="$(script/version)" diff --git a/script/brew_build_interactive b/script/brew_build_interactive index 654bb49..d93a039 100755 --- a/script/brew_build_interactive +++ b/script/brew_build_interactive @@ -6,6 +6,13 @@ # https://docs.brew.sh/Formula-Cookbook#check-the-build-system # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + HOMEBREW_NO_INSTALL_FROM_API=1 \ brew reinstall \ --interactive mas diff --git a/script/brew_core_update b/script/brew_core_update index 33df90d..b44f2a7 100755 --- a/script/brew_core_update +++ b/script/brew_core_update @@ -9,11 +9,17 @@ # brew bump-formula-pr --help # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + CORE_TAP_PATH="$(brew --repo homebrew/core)" CORE_MAS_FORMULA_FILE="${CORE_TAP_PATH}/Formula/m/mas.rb" -PROJECT_PATH="$(git rev-parse --show-toplevel)" -LOCAL_MAS_FORMULA_PATH="${PROJECT_PATH}/Homebrew/mas.rb" +LOCAL_MAS_FORMULA_PATH=Homebrew/mas.rb function usage { echo "Usage: brew_core_update [-d] [ []]" diff --git a/script/brew_release_validate b/script/brew_release_validate index bc4f767..abb51e1 100755 --- a/script/brew_release_validate +++ b/script/brew_release_validate @@ -7,6 +7,13 @@ # https://github.com/Homebrew/homebrew-core/blob/master/CONTRIBUTING.md#to-contribute-a-fix-to-the-foo-formula # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + brew uninstall --force mas brew install --build-from-source mas brew test mas diff --git a/script/brew_tap_update b/script/brew_tap_update index edfe45a..7447ea8 100755 --- a/script/brew_tap_update +++ b/script/brew_tap_update @@ -7,6 +7,13 @@ # https://github.com/mas-cli/homebrew-tap/blob/main/Formula/mas.rb # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + function usage { echo "Usage: brew_tap_update [ []]" echo " version will be inferred using version script if not provided" diff --git a/script/build_artifacts b/script/build_artifacts index a89c9ac..a8ee44a 100755 --- a/script/build_artifacts +++ b/script/build_artifacts @@ -6,6 +6,13 @@ # Runs all related scripts for generating all artifacts. # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + MAS_VERSION="$(script/version)" echo "Building mas ${MAS_VERSION} artifacts" diff --git a/script/clean b/script/clean index ded54c5..d08285b 100755 --- a/script/clean +++ b/script/clean @@ -6,5 +6,12 @@ # Deletes the build directory. # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + swift package clean swift package reset diff --git a/script/install b/script/install index b653875..cb992be 100755 --- a/script/install +++ b/script/install @@ -10,6 +10,13 @@ # https://github.com/Homebrew/homebrew-core/blob/master/Formula/m/mas.rb # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + ARCH="$(uname -m)" RELEASE=".build/${ARCH}-apple-macosx/release" MAS_VERSION="$(script/version)" diff --git a/script/package b/script/package index 20fae42..1e049a3 100755 --- a/script/package +++ b/script/package @@ -6,7 +6,14 @@ # Builds macOS installer component and distribution packages. # -BUILD_DIR="${PWD}/.build" +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + +BUILD_DIR=.build COMPONENT_PACKAGE="${BUILD_DIR}/mas_components.pkg" DISTRIBUTION_PACKAGE="${BUILD_DIR}/mas.pkg" @@ -17,7 +24,7 @@ IDENTIFIER="com.mphys.mas-cli" DISTRIBUTION_PLIST="Package/Distribution.plist" # Destination for install root -DSTROOT=.build/distributions +DSTROOT="${BUILD_DIR}/distributions" script/install "${DSTROOT}/usr/local" --universal MAS_VERSION="$(script/version)" diff --git a/script/package_install b/script/package_install index 5d05a7b..67f6cc3 100755 --- a/script/package_install +++ b/script/package_install @@ -6,6 +6,13 @@ # Installs the mas distribution package. Requires sudo access. # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + IDENTIFIER=com.mphys.mas-cli echo "==> 📲 Installing mas" diff --git a/script/uninstall b/script/uninstall index 12ff608..e5b163e 100755 --- a/script/uninstall +++ b/script/uninstall @@ -6,6 +6,13 @@ # Removes mas from PREFIX. # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + # Override default prefix path with optional 1st arg PREFIX="${1:-"$(brew --prefix)"}" diff --git a/script/update_headers b/script/update_headers index f42c102..b44c255 100755 --- a/script/update_headers +++ b/script/update_headers @@ -6,6 +6,13 @@ # Runs class-dump to generate headers for Apple private frameworks. # +mas_dir="$(readlink -fn "$(dirname "${BASH_SOURCE:-"${0}"}")/..")" + +if ! cd -- "${mas_dir}"; then + printf $'Error: Could not cd into mas directory: %s\n' "${mas_dir}" >&2 + exit 1 +fi + main() { check_class_dump extract_private_framework_headers "CommerceKit"