Skip to content

fix: fix env escaping #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 27, 2023
Merged

fix: fix env escaping #25

merged 8 commits into from
Mar 27, 2023

Conversation

@bf4 bf4 force-pushed the fix_path_escaping branch from caef7e8 to 6cf88fa Compare March 27, 2023 16:11
bf4 added 5 commits March 27, 2023 11:18
 * Avoid adding extra : characters to the end of gcc paths.  This will
   cause gcc to use the current directory in system include paths, which
   breaks C #include <file> vs #include "file" semantics.

   heroku/heroku-buildpack-apt@c8c021e
CACHED_TAR="${FREETDS_CACHE_DIR}/freetds-${FREETDS_VERSION}-heroku.tar.bz2"
if [[ "$CACHED_STACK" != "$STACK" ]] ; then
topic "Stack has changed. Clearing cache"
rm -f "$CACHED_TAR"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆕

# Default rebuild to true since I'm having issues linking the library to tiny_tds gem with a cached build.
if [ "${FREETDS_REBUILD:-}" = "true" ]; then
FREETDS_CACHE_DIR="$CACHE_DIR/freetds/cache"
mkdir -p "${FREETDS_CACHE_DIR}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new namespaced directory

fi
# Ensure we store the STACK in the cache for next time.
mkdir -p "$CACHE_DIR/.freetds"
echo "$STACK" > "$CACHE_DIR/.freetds/STACK"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new, cache reference to stack.

# shellcheck disable=SC2034
ENV_DIR="${3}"
# echo "$STACK"
# echo "$SOURCE_VERSION"
# See https://devcenter.heroku.com/articles/buildpack-api#bin-compile-summary

mkdir -p "$BUILD_DIR" "$CACHE_DIR"
# Store which STACK we are running on in the cache to bust the cache if it changes
if [ -f "${CACHE_DIR}/.freetds/STACK" ]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new, cache everything in a .freetds directory

mkdir -p "${BUILD_TARGET_DIR}"

# This is the path that will be used at dyno runtime, and in which we build.
APP_TARGET_DIR="/app/freetds"
APP_TARGET_DIR="${HOME:-app}/.freetds" # /app/freetds"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new: always home, always in .freetds

@@ -84,44 +136,51 @@ configure_app_env_vars() {
# These exports must point to /app, because the profile is
# executed in a running dyno, not the buildpack environment
cat <<EOF > "${BUILD_DIR}/.profile.d/freetds.sh"
export PATH="${APP_TARGET_DIR}/bin:\$PATH"
export PATH="\${HOME}/.freetds/bin:\$PATH"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new, always escape, always use home

export LIBRARY_PATH="${APP_TARGET_DIR}/lib:${LIBRARY_PATH:-/usr/local/lib}"
export SYBASE="${APP_TARGET_DIR}"
export FREETDS_DIR="\${HOME}/.freetds"
export LD_LIBRARY_PATH="\${HOME}/.freetds/lib:\${LD_LIBRARY_PATH:-}"
Copy link
Contributor Author

@bf4 bf4 Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new, always escape, no more fallback when empty

# Assert $APP_TARGET_DIR = $HOME/.freetds # /app/freetds
export PATH="${HOME}/.freetds/bin:$PATH"
export FREETDS_DIR="${HOME}/.freetds"
export LD_LIBRARY_PATH="${HOME}/.freetds/lib:${LD_LIBRARY_PATH:-}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new, always use home

# give environment to later buildpacks
export | grep -E -e ' (PATH|LD_LIBRARY_PATH|LIBRARY_PATH|FREETDS_DIR|SYBASE)=' > "${LP_DIR}/export"
export | grep -E -e ' (PATH|LD_LIBRARY_PATH|LD_RUN_PATH|LIBRARY_PATH|FREETDS_DIR|SYBASE)=' > "${LP_DIR}/export"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new, use LD_RUN_PATH


echo "configured BUILDPACK env vars:" | indent
indent < "${LP_DIR}/export"

topic "Rewrite package-config files"
find "$BUILD_DIR/.freetds" -type f -ipath '*/pkgconfig/*.pc' | xargs --no-run-if-empty -n 1 sed -i -e 's!^prefix=\(.*\)$!prefix='"$BUILD_DIR"'/.freetds\1!g'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new from heroku-aptfile-buildpack. not sure if important

@bf4 bf4 merged commit 0adfe53 into master Mar 27, 2023
@bf4 bf4 deleted the fix_path_escaping branch March 27, 2023 18:01
bf4 added a commit that referenced this pull request Mar 27, 2023
@bf4 bf4 mentioned this pull request Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant