From 022386c4aec25b521b1579c8dbad6c57db5e5595 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Mon, 10 May 2021 15:39:06 -0600 Subject: [PATCH 1/7] Throw errors when packages are missing --- bin/install | 72 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/bin/install b/bin/install index d213d1e..0d6f4ce 100755 --- a/bin/install +++ b/bin/install @@ -13,16 +13,25 @@ install_php() { local tmp_download_dir=${TMPDIR%/} fi + echo "Installing PHP ${version}..." echo "Determining configuration options..." + local source_path=$(get_download_file_path $install_type $version $tmp_download_dir) local configure_options="$(construct_configure_options $install_path)" local make_flags="-j$ASDF_CONCURRENCY" local operating_system=$(uname -a) + # many macos packages require modifications to various env variables in order for the build process to pick + # up the correct version of the packages. These checks are done here instead of `construct_configure_options` + # because modifications to $PKG_CONFIG_PATH are not propogated from the subshell to this shell. if [[ $operating_system =~ "Darwin" ]]; then exit_if_homebrew_not_installed + local missing_required_packages="" + + echo "Configuring compilation variables for custom packages..." + local bison_path=$(homebrew_package_path bison) local icu4c_path=$(homebrew_package_path icu4c) local krb5_path=$(homebrew_package_path krb5) @@ -33,37 +42,42 @@ install_php() { if [ -n "$bison_path" ]; then export "PATH=${bison_path}/bin:${PATH}" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING bison" + missing_required_packages="$missing_required_packages bison" fi if [ -n "$icu4c_path" ]; then export "PKG_CONFIG_PATH=${icu4c_path}/lib/pkgconfig:${PKG_CONFIG_PATH}" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING icu4c" + missing_required_packages="$missing_required_packages icu4c" fi if [ -n "$krb5_path" ]; then export "PKG_CONFIG_PATH=${krb5_path}/lib/pkgconfig:${PKG_CONFIG_PATH}" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING krb5" + missing_required_packages="$missing_required_packages krb5" fi if [ -n "$libedit_path" ]; then export "PKG_CONFIG_PATH=${libedit_path}/lib/pkgconfig:${PKG_CONFIG_PATH}" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libedit" + missing_required_packages="$missing_required_packages libedit" fi if [ -n "$libxml2_path" ]; then export "PKG_CONFIG_PATH=${libxml2_path}/lib/pkgconfig:${PKG_CONFIG_PATH}" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libxml2" + missing_required_packages="$missing_required_packages libxml2" fi if [ -n "$openssl_path" ]; then export "PKG_CONFIG_PATH=${openssl_path}/lib/pkgconfig:${PKG_CONFIG_PATH}" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING openssl" + missing_required_packages="$missing_required_packages openssl" + fi + + if [ -n "$missing_required_packages" ]; then + echo "Required packages are missing, install via homebrew: $missing_required_packages" + exit 1 fi fi @@ -177,9 +191,7 @@ construct_configure_options() { homebrew_package_path() { local package_name=$1 - if [ "$(brew ls --versions $package_name)" = "" ]; then - echo "" - else + if [ -n "$(brew ls --versions $package_name)" ]; then echo "$(brew --prefix $package_name)" fi } @@ -199,6 +211,8 @@ os_based_configure_options() { exit_if_homebrew_not_installed + local missing_required_packages="" + local bison_path=$(homebrew_package_path bison) local bzip2_path=$(homebrew_package_path bzip2) local freetype_path=$(homebrew_package_path freetype) @@ -235,89 +249,90 @@ os_based_configure_options() { if [ -n "$freetype_path" ]; then configure_options="$configure_options --with-freetype-dir=$freetype_path" else - export ASDF_PKG_MISSING="freetype" + missing_required_packages="freetype" fi if [ -n "$bison_path" ]; then - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING bison" + missing_required_packages="$missing_required_packages bison" fi if [ -n "$gettext_path" ]; then configure_options="$configure_options --with-gettext=$gettext_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING gettext" + missing_required_packages="$missing_required_packages gettext" fi + # PHP 7.4+ will pick up ICU with pkg-config only, previous versions will use pkg-config or --with-icu-dir. if [ -n "$icu4c_path" ]; then configure_options="$configure_options --with-icu-dir=$icu4c_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING icu4c" + missing_required_packages="$missing_required_packages icu4c" fi if [ -n "$jpeg_path" ]; then configure_options="$configure_options --with-jpeg-dir=$jpeg_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING jpeg" + missing_required_packages="$missing_required_packages jpeg" fi if [ -n "$webp_path" ]; then configure_options="$configure_options --with-webp-dir=$webp_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING webp" + missing_required_packages="$missing_required_packages webp" fi if [ -n "$libpng_path" ]; then configure_options="$configure_options --with-png-dir=$libpng_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libpng" + missing_required_packages="$missing_required_packages libpng" fi if [ -n "$openssl_path" ]; then configure_options="$configure_options --with-openssl=$openssl_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING openssl" + missing_required_packages="$missing_required_packages openssl" fi if [ -n "$libxml2_path" ]; then configure_options="$configure_options --with-libxml-dir=$libxml2_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libxml2" + missing_required_packages="$missing_required_packages libxml2" fi if [ -n "$zlib_path" ]; then configure_options="$configure_options --with-zlib-dir=$zlib_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING zlib" + missing_required_packages="$missing_required_packages zlib" fi if [ -n "$libzip_path" ]; then configure_options="$configure_options --with-libzip=$libzip_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libzip" + missing_required_packages="$missing_required_packages libzip" fi if [ -n "$readline_path" ]; then configure_options="$configure_options --with-readline=$readline_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING readline" + missing_required_packages="$missing_required_packages readline" fi if [ -n "$libedit_path" ]; then configure_options="$configure_options --with-libedit=$libedit_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libedit" + missing_required_packages="$missing_required_packages libedit" fi if [ -n "$bzip2_path" ]; then configure_options="$configure_options --with-bz2=$bzip2_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING bzip2" + missing_required_packages="$missing_required_packages bzip2" fi if [ -n "$iconv_path" ]; then configure_options="$configure_options --with-iconv=$iconv_path" else - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libiconv" + missing_required_packages="$missing_required_packages libiconv" fi else local jpeg_path=$(locate libjpeg.so | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) @@ -325,18 +340,23 @@ os_based_configure_options() { configure_options="--with-openssl --with-curl --with-zlib --with-readline --with-gettext" if [ "$jpeg_path" = "" ]; then - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING jpeg" + missing_required_packages="$missing_required_packages jpeg" else configure_options="$configure_options --with-jpeg-dir=$jpeg_path --with-jpeg" fi if [ "$libpng_path" = "" ]; then - export ASDF_PKG_MISSING="$ASDF_PKG_MISSING libpng" + missing_required_packages="$missing_required_packages libpng" else configure_options="$configure_options --with-png-dir=$libpng_path --with-png" fi fi + if [ -n "$missing_required_packages" ]; then + echo "Required packages are missing, install via homebrew: $missing_required_packages" + exit 1 + fi + echo $configure_options } From f0afc9863908235bbdb791397c43649c21308d65 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Mon, 10 May 2021 15:39:19 -0600 Subject: [PATCH 2/7] Note about installing older packages --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f19720..7aa4091 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ extension=imagick.so" > $(asdf where php)/conf.d/php.ini To install PHP on macOS, you'll need a set of packages [installed via homebrew](https://github.com/asdf-community/asdf-php/blob/248e9c6e2a7824510788f05e8cee848a62200b65/.github/workflows/workflow.yml#L52). -You may want to install these packages using `upgrade` instead of `install` to ensure the latest version of all required packages is installed. +You may want to install these packages using `upgrade` instead of `install` to ensure the latest version of all required packages is installed. In some cases, newer versions of a package may cause compilation issues for specific PHP versions and you may need to install an older version. When you install an older version of a package, ensure it uses the exact same name as the expected package ([more info here](http://mikebian.co/installing-an-old-homebrew-package/)). There's also a set of optional packages which enable additional extensions to be enabled: From 655f2f84bcaeed6c21b63126ef42e4826035353f Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Thu, 20 May 2021 14:34:19 -0600 Subject: [PATCH 3/7] Fix ubuntu locate command --- bin/install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/install b/bin/install index 0d6f4ce..a18845c 100755 --- a/bin/install +++ b/bin/install @@ -335,8 +335,8 @@ os_based_configure_options() { missing_required_packages="$missing_required_packages libiconv" fi else - local jpeg_path=$(locate libjpeg.so | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) - local libpng_path=$(locate libpng.so | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) + local jpeg_path=$(locate libjpeg | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) + local libpng_path=$(locate libpng | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) configure_options="--with-openssl --with-curl --with-zlib --with-readline --with-gettext" if [ "$jpeg_path" = "" ]; then From 4ea1ec8ccfe7206f21492b8e12aa794addaf425e Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Thu, 20 May 2021 14:36:02 -0600 Subject: [PATCH 4/7] Install bizip2 --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 854a4b7..2cf4ae8 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -49,7 +49,7 @@ jobs: steps: - name: Install packages - run: brew install autoconf automake bison freetype gd gettext icu4c krb5 libedit libiconv libjpeg libpng libxml2 libzip pkg-config re2c zlib + run: brew install autoconf automake bison bzip2 freetype gd gettext icu4c krb5 libedit libiconv libjpeg libpng libxml2 libzip pkg-config re2c zlib - name: asdf_plugin_test uses: asdf-vm/actions/plugin-test@v1 From abfda8206520cad6eb6fa33cb5a7f3d98db80470 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Thu, 20 May 2021 14:42:12 -0600 Subject: [PATCH 5/7] Removed homebrew from error message --- bin/install | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/install b/bin/install index a18845c..c0e8f28 100755 --- a/bin/install +++ b/bin/install @@ -22,6 +22,12 @@ install_php() { local operating_system=$(uname -a) + echo "test2" + echo $(locate libpng) + echo $(locate libjpeg) + exit 1 + + # many macos packages require modifications to various env variables in order for the build process to pick # up the correct version of the packages. These checks are done here instead of `construct_configure_options` # because modifications to $PKG_CONFIG_PATH are not propogated from the subshell to this shell. @@ -76,7 +82,7 @@ install_php() { fi if [ -n "$missing_required_packages" ]; then - echo "Required packages are missing, install via homebrew: $missing_required_packages" + echo "Required packages are missing: $missing_required_packages" exit 1 fi fi @@ -335,6 +341,10 @@ os_based_configure_options() { missing_required_packages="$missing_required_packages libiconv" fi else + echo "test" + echo $(locate libpng) + echo $(locate libjpeg) + exit 1 local jpeg_path=$(locate libjpeg | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) local libpng_path=$(locate libpng | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) configure_options="--with-openssl --with-curl --with-zlib --with-readline --with-gettext" @@ -353,7 +363,7 @@ os_based_configure_options() { fi if [ -n "$missing_required_packages" ]; then - echo "Required packages are missing, install via homebrew: $missing_required_packages" + echo "Required packages are missing: $missing_required_packages" exit 1 fi From 5d6b22acb8490f08831fafbdaa3113bc4f504402 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Thu, 20 May 2021 14:56:06 -0600 Subject: [PATCH 6/7] Installing locate command on gh env --- .github/workflows/workflow.yml | 2 +- bin/install | 19 ++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 2cf4ae8..3078461 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Install packages - run: apt-get update && apt-get install -y autoconf bison build-essential curl gettext git libgd-dev libcurl4-openssl-dev libedit-dev libicu-dev libjpeg-dev libmysqlclient-dev libonig-dev libpng-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev libxml2-dev libzip-dev openssl pkg-config re2c zlib1g-dev + run: apt-get update && apt-get install -y autoconf bison build-essential curl gettext git libgd-dev libcurl4-openssl-dev libedit-dev libicu-dev libjpeg-dev libmysqlclient-dev libonig-dev libpng-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev libxml2-dev libzip-dev openssl pkg-config re2c zlib1g-dev mlocate - name: asdf_plugin_test uses: asdf-vm/actions/plugin-test@v1 diff --git a/bin/install b/bin/install index c0e8f28..16d96ff 100755 --- a/bin/install +++ b/bin/install @@ -22,12 +22,6 @@ install_php() { local operating_system=$(uname -a) - echo "test2" - echo $(locate libpng) - echo $(locate libjpeg) - exit 1 - - # many macos packages require modifications to various env variables in order for the build process to pick # up the correct version of the packages. These checks are done here instead of `construct_configure_options` # because modifications to $PKG_CONFIG_PATH are not propogated from the subshell to this shell. @@ -219,7 +213,6 @@ os_based_configure_options() { local missing_required_packages="" - local bison_path=$(homebrew_package_path bison) local bzip2_path=$(homebrew_package_path bzip2) local freetype_path=$(homebrew_package_path freetype) local gettext_path=$(homebrew_package_path gettext) @@ -258,10 +251,6 @@ os_based_configure_options() { missing_required_packages="freetype" fi - if [ -n "$bison_path" ]; then - missing_required_packages="$missing_required_packages bison" - fi - if [ -n "$gettext_path" ]; then configure_options="$configure_options --with-gettext=$gettext_path" else @@ -341,12 +330,8 @@ os_based_configure_options() { missing_required_packages="$missing_required_packages libiconv" fi else - echo "test" - echo $(locate libpng) - echo $(locate libjpeg) - exit 1 - local jpeg_path=$(locate libjpeg | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) - local libpng_path=$(locate libpng | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1) + local jpeg_path=$(locate libjpeg.so | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1 | xargs dirname) + local libpng_path=$(locate libpng.so | awk '{ print length(), $0 | "sort -n" }' | cut -d" " -f2- | head -n 1 | xargs dirname) configure_options="--with-openssl --with-curl --with-zlib --with-readline --with-gettext" if [ "$jpeg_path" = "" ]; then From f357098bf1c84487c33e487ac5647f7387fdaa03 Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Thu, 18 Nov 2021 08:44:13 -0700 Subject: [PATCH 7/7] More helpful error message Indicate which packages need to be installed via brew Co-authored-by: Adam Hawkins --- bin/install | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/install b/bin/install index 16d96ff..e20740b 100755 --- a/bin/install +++ b/bin/install @@ -77,6 +77,7 @@ install_php() { if [ -n "$missing_required_packages" ]; then echo "Required packages are missing: $missing_required_packages" + echo "Install with: brew install $missing_required_packages" exit 1 fi fi