Conversation
macports.tcl sets env(CCACHE_DIR) once at startup to the global
ccache_dir default ($portdbpath/build/.ccache). A port can override the
ccache_dir Tcl variable to a per-build workpath (e.g. py-pytorch does
`set ccache_dir ${workpath}/.ccache`), and portconfigure correctly
creates and chowns that per-build directory. However, the subsequent
`exec ccache -M` inherited the stale process-level CCACHE_DIR pointing
at the never-created root-owned default path, causing:
Warning: ccache_dir .../work/.ccache could not be initialized;
disabling ccache: ccache: error: Failed to create directory
.../build/.ccache: Permission denied
Fix: set env(CCACHE_DIR) to the current ccache_dir value immediately
before invoking ccache, so the binary always targets the directory that
was just prepared above.
Workaround until this lands: manually create the default directory with
macports-user ownership:
sudo mkdir /opt/local/var/macports/build/.ccache
sudo chown macports:macports /opt/local/var/macports/build/.ccache
|
Globals representing macports.conf values are not meant to be modified, so what py-pytorch is doing is not supported. We might start defining them as |
|
Thanks — that's a fair objection, and it makes this patch the wrong shape. Syncing Withdrawing rather than leaving it open. If there's later appetite for a real |
Problem
macports.tclsetsenv(CCACHE_DIR)once at startup to the globalccache_dirdefault ($portdbpath/build/.ccache, typically/opt/local/var/macports/build/.ccache).A Portfile can override the Tcl variable
ccache_dirto a per-build workpath —py-pytorchdoes this:portconfigure.tcl(configure_start) correctly picks up the overridden Tcl variable and creates/chowns that per-build directory. However the subsequentexec ccache -M ${ccache_size}inherits the stale process-levelCCACHE_DIRthat still points at the never-created, root-owned default path. The result is:ccache is silently disabled for the entire build even though the port set things up correctly.
Root cause
portconfigure.tcllines 423–431 (excerpt):env(CCACHE_DIR)is never updated to match the current (possibly overridden)${ccache_dir}beforeexec ccacheruns.Fix
One line added immediately before the
exec:This syncs the environment to whatever
ccache_dirwas resolved to (global default or per-build override) so theccache -Mcall targets the directory that was just prepared withfile mkdir/file attributes.Verification
Reproduced on MacPorts 2.12.5, ccache 4.13.1, macOS 26 (Darwin 25.5.0) with
py314-pytorch. Applying the patch and rebuilding eliminates the warning and ccache works correctly for the build.Workaround (until this lands)
This is fragile — the directory is wiped by
sudo port clean --all.