dlang / dub

Package and build management system for D
MIT License
677 stars 227 forks source link

building with `--cache=local` should not touch system paths #2654

Open WebFreak001 opened 1 year ago

WebFreak001 commented 1 year ago

Bug Description

See issue posted on the forum: https://forum.dlang.org/post/xbsyphzxokwtpjmpkxqv@forum.dlang.org

This may be introduced by #2542, although I haven't verified this yet.

The problem here is that $DUB_HOME may not be writable, which is the case here for example on nix. A workaround would be changing the path of it to somewhere writable, but you don't want to do that for every project.

The real fix here would be fixing the build cache to use the local .dub path when building with --cache=local, as well as adding a dub.settings.json entry to be able to default the cache location to always be local on OSes where this is needed.

How to reproduce?

mkdir home
chmod 500 home
export DUB_HOME=$(pwd)/home
mkdir project
cd project
dub init -n -f sdl
dub add asdf
dub build --cache=local

Expected Behavior

Dependencies are fetched into project/.dub/packages and build cache is done in project/.dub/cache.

Actual Behavior

Build cache attempts to write to $DUB_HOME/cache

Logs

# fetching works, building fails
$ dub build --cache=local
    Fetching mir-core 1.5.5 (getting selected version)
    Fetching silly 1.1.1 (getting selected version)
    Fetching mir-algorithm 3.20.4 (getting selected version)
    Fetching asdf 0.7.17 (getting selected version)
    Starting Performing "debug" build using /usr/bin/dmd for x86_64.
Error /tmp/root/home/cache: Permission denied

# packages are there
$ ls .dub/packages/
asdf-0.7.17/  mir-algorithm-3.20.4/  mir-core-1.5.5/  silly-1.1.1/
CyberShadow commented 1 year ago

Is this the same as https://github.com/dlang/dub/issues/2651 ?

Note that you need --temp-build to make Dub not try to write to the package cache. https://github.com/dlang/dub/pull/2652 fixes a remaining occurrence of an attempt to write there even with --temp-build.

WebFreak001 commented 1 year ago

seems to be a related, but different, issue

Geod24 commented 10 months ago

@WebFreak001 : This is very much on purpose.

The help text for --cache mentions:

      --cache=VALUE     Puts any fetched packages in the specified location
                        [local|system|user].

So I never thought someone would think the build cache would follow the --cache argument. For Nix build, can you not provide a DUB_HOME via the env ?