bin/install builds the wrong version when python3 resolves to an asdf shim

Open Beginner friendly
#213 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
77/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php, python
Domain
build-system

Research direction

Start by reading the Python entry point bin/install and how it reads ASDF_INSTALL_VERSION and ASDF_INSTALL_PATH; the issue identifies both variables as overwritten when python3 resolves to an asdf shim. Compare the proposed shell wrapper approach with resolving a non-shim interpreter. Done means asdf install php 8.5.12 builds that PHP version into its PHP install path when Python is managed by asdf.

Written by the indexing model from the issue text.

Description

Summary

Since the php-build rewrite (#200), bin/install is a Python script started via
#!/usr/bin/env python3. If python3 on PATH is an asdf shim (i.e. the user
manages Python with asdf-python and has a version set), the shim overwrites
ASDF_INSTALL_VERSION and ASDF_INSTALL_PATH with the Python tool's values
before the script runs. The plugin then tries to build PHP using the Python
version and install path.

Steps to reproduce

  1. Manage Python with asdf and set a version, e.g. python 3.15.2 in
    ~/.tool-versions.
  2. asdf install php 8.5.12

Actual result

Building PHP 3.15.2...
[Error]: Definition 3.15.2 not found.
asdf-php: Command ('~/.asdf/plugins/php/vendor/php-build/bin/php-build', '3.15.2', '~/.asdf/installs/python/3.15.2') returned non-zero exit status 127.

Expected result

PHP 8.5.12 is built into ~/.asdf/installs/php/8.5.12.

Root cause

Running a command through an asdf shim sets ASDF_INSTALL_VERSION /
ASDF_INSTALL_PATH for the shimmed tool, and those values reach the exec'd
process. Minimal check (asdf 0.20.0):

ASDF_INSTALL_VERSION=8.5.12 ASDF_INSTALL_PATH=/x/php/8.5.12 ASDF_CUSTOM=8.5.12 \
  python3 -c 'import os; print(os.environ["ASDF_INSTALL_VERSION"], os.environ["ASDF_INSTALL_PATH"], os.environ["ASDF_CUSTOM"])'
# -> 3.15.2 ~/.asdf/installs/python/3.15.2 8.5.12

ASDF_INSTALL_TYPE and unrelated variables are left untouched, so only the
version and path are corrupted.

Workaround

Put a non-shim python3 first on PATH only for the install, keeping the
rest of PATH (e.g. Homebrew's pkg-config) intact:

d=$(mktemp -d) && ln -s /usr/bin/python3 "$d/python3"
PATH="$d:$PATH" asdf install php 8.5.12
rm -r "$d"

(Prepending /usr/bin to PATH also avoids the shim, but it breaks builds that
rely on Homebrew's pkg-config / libraries on Linux.)

Possible fix

Keep bin/install as a small shell wrapper that captures the values before
any shim can run, e.g. into ASDF_PHP_INSTALL_VERSION / ASDF_PHP_INSTALL_PATH,
and have the Python code read those. Alternatively, resolve a python3 that is
not under ${ASDF_DATA_DIR:-$HOME/.asdf}/shims.

Environment

  • asdf 0.20.0 (Homebrew on Linux)
  • asdf-php at 8c51982
  • asdf-python with python 3.15.2 set globally
  • Ubuntu 26.04.1 LTS on WSL2 (kernel 6.18.58)
Dominant language
Python
Stars
255
Forks
118
Avg merge
42m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from asdf-community/asdf-php

All issues in asdf-community/asdf-php

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.