www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Dub build failure

reply jerome <jegaultier gmail.com> writes:
I am trying to compile a simple lib, and a simple demo using this 
lib.

So I have 2 directories at the same level in the same DEV 
directory:
    demo1          Dterrent

In the Dterrent directory, the dub.json is pretty common, 
compiling as a lib:
	"name": "dterrent",
	"targetPath": "libs",

Inside Dterrent, I also have a regular "source" directory, which 
contains a package.d file:
Dterrent
|-> source
   |-> package.d

The first line of package.d is :
module dterrent;

If I am in the Dterrent directory, a `dub build` command compiles 
the library dterrent properly, exactly as expected.

***

I go back up to DEV, then go down into demo1. There I have again 
a dub.json file, with :
	"dependencies": {
                  ...
		 "dterrent" : { "path": "../Dterrent" },

In the demo1 directory, I also have a regular source/app.d file, 
whose first line is:
import dterrent;

Then I try a `dub build`:
----
jerome laptop:/DATA/DEV/demo1$ dub build
Performing "debug" build using 
/home/jerome/dlang/dmd-2.093.1/linux/bin64/dmd for x86_64.
dterrent ~master: target for configuration "library" is up to 
date.
demo1 ~master: building configuration "application"...
source/app.d(9,8): Error: module dterrent is in file 'dterrent.d' 
which cannot be read
import path[0] = source/
import path[4] = ../Dterrent/source/
import path[5] = 
/home/jerome/dlang/dmd-2.093.1/linux/bin64/../../src/phobos
import path[6] = 
/home/jerome/dlang/dmd-2.093.1/linux/bin64/../../src/druntime/import
/home/jerome/dlang/dmd-2.093.1/linux/bin64/dmd failed with exit 
code 1.
----

Well, the module dterrent is obviously not in dterrent.d
dterrent.d does not exist as it, since it is a package.d file 
with the "module dterrent;" line.

If I change package.d for dterrent.d, I get some other errors. 
But at this point, I think we agree I should not have to change 
the name of package.d, right?

What am I doing wrong? What would be the right way? Or is there a 
workaround.

Thanks
Oct 04 2020
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Sunday, 4 October 2020 at 18:45:34 UTC, jerome wrote:
 I am trying to compile a simple lib, and a simple demo using 
 this lib.

 [...]
If I am not wrong there is following issue: in D a package is a folder. Having the package.d file as child of folder source is not correct. Moving the file package.d into folder source/dterrent/ should solve the issue. Kind regards Andre
Oct 04 2020
parent jerome <jegaultier gmail.com> writes:
On Sunday, 4 October 2020 at 20:25:48 UTC, Andre Pany wrote:
 On Sunday, 4 October 2020 at 18:45:34 UTC, jerome wrote:
 I am trying to compile a simple lib, and a simple demo using 
 this lib.

 [...]
If I am not wrong there is following issue: in D a package is a folder. Having the package.d file as child of folder source is not correct. Moving the file package.d into folder source/dterrent/ should solve the issue. Kind regards Andre
Hi Andre, your solution solved the problem. Thanks. Reading again the error message, with the solution at hand, I think your answer may be completed. I explain: The message was: source/app.d(9,8): Error: module dterrent is in file 'dterrent.d' which cannot be read I think dub looked for a dterrent.d file in registered paths. Then it also looked for a dterrent directory in paths, possibly verifying that a package.d file was present in that directory. Finding neither nor, it concluded that the module should have been in an eponymous dterrent.d file somewhere, and displayed that ambiguous error message. So it seems that dub does not parse any file looking for the line "module dterrent;" as I thought. It just looks for a file or directory named dterrent(.d) Maybe it also verify that an eponymous folder has a package.d, in this case we can say "a folder must have a normative package.d file". Maybe. Thanks again for your fast answer.
Oct 04 2020