dlang / dub

Package and build management system for D
MIT License
673 stars 230 forks source link

Using --root prevents caching of dependencies #2668

Open AndrejMitrovic opened 1 year ago

AndrejMitrovic commented 1 year ago

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 git@github.com: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:

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