dub icon indicating copy to clipboard operation
dub copied to clipboard

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

Open WebFreak001 opened this issue 2 years ago • 3 comments

Bug Description

See issue posted on the forum: https://forum.dlang.org/post/[email protected]

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/

WebFreak001 avatar Jun 02 '23 11:06 WebFreak001

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.

CyberShadow avatar Jul 07 '23 10:07 CyberShadow

seems to be a related, but different, issue

WebFreak001 avatar Jul 07 '23 13:07 WebFreak001

@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 ?

Geod24 avatar Jan 17 '24 23:01 Geod24