dub icon indicating copy to clipboard operation
dub copied to clipboard

Using --root prevents caching of dependencies

Open AndrejMitrovic opened this issue 2 years ago • 0 comments
trafficstars

Create a folder named project and add this dub.sdl:

name "project"
description "none"
authors "none"
copyright "Copyright © 2023"
license "proprietary"
dependency "protobuf" path="lib/protobuf" version="~>0.6.2"

Then add the protobuf submodule:

$ cd project
$ git submodule add --name protobuf [email protected]:dcarp/protobuf-d.git lib/protobuf

Now CD up one directory and try to use --root:

$ cd ..

# First run
$ dub --root $PWD/project build
    Starting Performing "debug" build using /home/drey/dlang/dmd-2.102.0/linux/bin64/dmd for x86_64.
    Building protobuf ~master: building configuration [protobuf]
    Building project ~master: building configuration [application]
     Linking project

# Second run
$ dub --root $PWD/project build
    Starting Performing "debug" build using /home/drey/dlang/dmd-2.102.0/linux/bin64/dmd for x86_64.
    Building protobuf ~master: building configuration [protobuf]
    Building project ~master: building configuration [application]
     Linking project

Notice that dub rebuilds all the dependencies every time, it does not cache them.

Compare that to running it within the project folder:

$ cd project
$ dub build
    Starting Performing "debug" build using /home/drey/dlang/dmd-2.102.0/linux/bin64/dmd for x86_64.
  Up-to-date protobuf ~master: target for configuration [protobuf] is up to date.
    Building project ~master: building configuration [application]
     Linking project
    Finished To force a rebuild of up-to-date targets, run again with --force

It correctly uses the cached version: Up-to-date protobuf.


My main use-case is running scripts or sample code which happens to use the library in the root.

My options are:

  • Use configurations in the root dub file to create sample code. But this is problematic when the sample code uses extra dependencies which the library code should not itself depend on.
  • Create a separate .dub file for the sample code. This is what I did and it's why I used --root.

Since --root has this caching problem I think I'll have to manually CD to the sample project and run dub without --root.

AndrejMitrovic avatar Jul 01 '23 09:07 AndrejMitrovic