A suggestion for modules names / sharing code between projects

Jesse Phillips via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 29 11:56:20 PST 2016


On Monday, 29 February 2016 at 19:03:53 UTC, Sebastien Alaiwan 
wrote:
> Hi all,
>
> I've came across the following problem number of times.
> Let's say I have project A and B, sharing code but having a 
> different tree structure.
>
> $ find projectA
> ./projectA/internal/math/algo.d
> ./projectA/internal/math/lcp.d
> ./projectA/internal/math/optimize.d
> ./projectA/gui/main.d
>
> $ find projectB
> ./projectB/app/render/gfx.d
> ./projectB/app/render/algo.d
> ./projectB/app/physics/math/algo.d
> ./projectB/app/physics/math/lcp.d
> ./projectB/app/physics/math/optimize.d
> ./projectB/main.d

I've used this pattern.

  ./projectA/lib/math/algo.d
  ./projectA/lib/math/lcp.d
  ./projectA/lib/math/optimize.d
  ./projectA/gui/main.d

  ./projectB/app/render/gfx.d
  ./projectB/app/render/algo.d
  ./projectB/lib/math/algo.d
  ./projectB/lib/math/lcp.d
  ./projectB/lib/math/optimize.d
  ./projectB/main.d


Dub doesn't like me too much, but in general it works.

Note that it doesn't matter where your modules live, if they have 
the declared module name in the file:

module math.optimize;

If DMD reads this file all your imports should look like:

import math.optimize;

Even if the file is in app/physics/math.


More information about the Digitalmars-d mailing list