www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What's the proper way to add a local file dependence to dub?

reply Marc <jckj33 gmail.com> writes:
then copy it to sources folder?

let's say I have a small library folder at C:\mylibrary\D where I 
want to use dir.d from it. How do I add that file dependence to 
dub? But I do not want to that file be passed directly to dmd, I 
want to that file be copied to application's source folder (so 
it's easy to distribuite, with the dependences together as 
possible) then compiled. So, what I want to some extension is dub 
work with loca files.
Is this possible to do solely with dub? I know I can easily write 
a script to run before dub which copies the dependence files from 
C:\mylibrary to application's source but I'm looking for a more 
elegant
  approach as possible; I'm afraid of rewriting a makefile-like 
soon (I find cmake/make/makefiles just ugly).
Mar 04 2018
next sibling parent bauss <jj_1337 live.dk> writes:
On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote:
 then copy it to sources folder?

 let's say I have a small library folder at C:\mylibrary\D where 
 I want to use dir.d from it. How do I add that file dependence 
 to dub? But I do not want to that file be passed directly to 
 dmd, I want to that file be copied to application's source 
 folder (so it's easy to distribuite, with the dependences 
 together as possible) then compiled. So, what I want to some 
 extension is dub work with loca files.
 Is this possible to do solely with dub? I know I can easily 
 write a script to run before dub which copies the dependence 
 files from C:\mylibrary to application's source but I'm looking 
 for a more elegant
  approach as possible; I'm afraid of rewriting a makefile-like 
 soon (I find cmake/make/makefiles just ugly).
Make it a sub package.
Mar 04 2018
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2018-03-04 17:46, Marc wrote:
 then copy it to sources folder?

 let's say I have a small library folder at C:\mylibrary\D where I want
 to use dir.d from it. How do I add that file dependence to dub? But I do
 not want to that file be passed directly to dmd, I want to that file be
 copied to application's source folder (so it's easy to distribuite, with
 the dependences together as possible) then compiled. So, what I want to
 some extension is dub work with loca files.
 Is this possible to do solely with dub? I know I can easily write a
 script to run before dub which copies the dependence files from
 C:\mylibrary to application's source but I'm looking for a more elegant
   approach as possible; I'm afraid of rewriting a makefile-like soon (I
 find cmake/make/makefiles just ugly).
You can use "preGenerateCommands" or "preBuildCommands" to run arbitrary commands before Dub builds the project [1]. Alternativly you can use the "import" expression [2], together with the "stringImportPaths" Dub build setting. The "import" expression will embed the file into the executable as a string literal. [1] https://code.dlang.org/package-format?lang=sdl#build-settings [2] https://dlang.org/spec/expression.html#import_expressions -- /Jacob Carlborg
Mar 06 2018
prev sibling next sibling parent crimaniak <crimaniak gmail.com> writes:
On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote:
 then copy it to sources folder?
... Also, symlinks are power tool for organizing your files without copying.
Mar 09 2018
prev sibling next sibling parent reply Martin Tschierschke <mt smartdolphin.de> writes:
On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote:
 then copy it to sources folder?

 let's say I have a small library folder at C:\mylibrary\D where 
 I want to use dir.d from it. How do I add that file dependence 
 to dub? But I do not want to that file be passed directly to 
 dmd, I want to that file be copied to application's source 
 folder (so it's easy to distribuite, with the dependences 
 together as possible) then compiled. So, what I want to some 
 extension is dub work with loca files.
 Is this possible to do solely with dub? I know I can easily 
 write a script to run before dub which copies the dependence 
 files from C:\mylibrary to application's source but I'm looking 
 for a more elegant
  approach as possible; I'm afraid of rewriting a makefile-like 
 soon (I find cmake/make/makefiles just ugly).
I did it this sway: the part of dub.json: "dependencies": { "diet-ng": "~>1.4", "vibe-d:tls": "~>0.8.0", "vibe-d:http": "~>0.8", "mysql-d": "~>0.3", "mylib":{ "versions": "~master", "path": "/home/mt/d/mylib" } }, In spite of using a version directly after the used lib, you give two parameters "versions" : "~master" and "path": "/path_to_your_lib/" Works well.
Mar 12 2018
parent Martin Tschierschke <mt smartdolphin.de> writes:
On Monday, 12 March 2018 at 09:38:41 UTC, Martin Tschierschke 
wrote:
 On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote:
 [...]
I did it this sway: the part of dub.json: "dependencies": {
[...]
                 "mylib":{
                         "versions": "~master",
                         "path": "/home/mt/d/mylib"
                 }
 },

 In spite of using a version directly after the used lib,
 you give two parameters

   "versions" : "~master"

 and

   "path": "/path_to_your_lib/"

 Works well.
And in ...mylib/dub.json you just add: "targetType": "library", on the top-level, and place your dir.d in ...mylib/source/
Mar 12 2018
prev sibling parent reply Seb <seb wilzba.ch> writes:
On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote:
 then copy it to sources folder?

 let's say I have a small library folder at C:\mylibrary\D where 
 I want to use dir.d from it. How do I add that file dependence 
 to dub? But I do not want to that file be passed directly to 
 dmd, I want to that file be copied to application's source 
 folder (so it's easy to distribuite, with the dependences 
 together as possible) then compiled. So, what I want to some 
 extension is dub work with loca files.
 Is this possible to do solely with dub? I know I can easily 
 write a script to run before dub which copies the dependence 
 files from C:\mylibrary to application's source but I'm looking 
 for a more elegant
  approach as possible; I'm afraid of rewriting a makefile-like 
 soon (I find cmake/make/makefiles just ugly).
You can also add a simple dub.sdl to your local files and then use `dub add-local` to add the package to your dub environment. Dub will only rebuild the dependency on your local files if they changed (or you use a different compiler / build settings).
Mar 12 2018
parent Jim Balter <Jim Balter.name> writes:
On Monday, 12 March 2018 at 10:20:20 UTC, Seb wrote:
 On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote:
 then copy it to sources folder?

 let's say I have a small library folder at C:\mylibrary\D 
 where I want to use dir.d from it. How do I add that file 
 dependence to dub? But I do not want to that file be passed 
 directly to dmd, I want to that file be copied to 
 application's source folder (so it's easy to distribuite, with 
 the dependences together as possible) then compiled. So, what 
 I want to some extension is dub work with loca files.
 Is this possible to do solely with dub? I know I can easily 
 write a script to run before dub which copies the dependence 
 files from C:\mylibrary to application's source but I'm 
 looking for a more elegant
  approach as possible; I'm afraid of rewriting a makefile-like 
 soon (I find cmake/make/makefiles just ugly).
You can also add a simple dub.sdl to your local files and then use `dub add-local` to add the package to your dub environment. Dub will only rebuild the dependency on your local files if they changed (or you use a different compiler / build settings).
Why is there no documentation for this? The dub documentation should have a filesystem layout page, with examples of how to structure local libraries, how to register them, how to add them to projects. AFAICT no such documentation exists. I've tried to follow the structure of libraries I've loaded into dub's packages directory, but it seems to treat local packages differently. And dub add-package is useless ... for one thing, it *overwrites* local-packages.json rather than adding to it.
Jan 06