RejectedSoftware Forums

Sign up

Running dub with a current working directory that doesn't match the directory of dub.json

I have this situation where I want my editor to run dub to build the file I have currently opened (I'm using Scite as an example).

Typically, all I need is a SciTEDirectory.properties file in either the current or some parent directory with these contents:

command.go.subsystem.*.d=0
command.go.*.d=rdmd $(FilePath)

But if I want to use dub things won't be that easy. I can tell where exactly the dub.json file is located, so I could attempt to place my editor script next to it and write this in SciTEDirectory.properties:

command.go.subsystem.*.d=0
# SciteDirectoryHome => Directory path of SciTEDirectory.properties
command.go.*.d=dub $(SciteDirectoryHome)\dub.json --config=$(FileName)

That would have worked perfectly, but it doesn't because the working directory of the editor doesn't match the directory of the dub.json file. I can't make the editor change its current working directory.

Currently my best workaround is to write a separate batch file like so:

build.bat:

@echo off
setlocal EnableDelayedExpansion

:: CD into the root folder so dub can find dub.json
set this_path=%~dp0
cd %this_path%\..

:: Now run dub
dub %*

And my editor script then becomes:

command.go.subsystem.*.d=0
command.go.*.d=$(SciteDirectoryHome)\build.bat --config=$(FileName)

But I wish I could get rid of the batch file and just be able to run dub from within another directory.

Can this be implemented/supported?

Re: Running dub with a current working directory that doesn't match the directory of dub.json

On Tue, 06 May 2014 20:28:13 GMT, Andrej Mitrovic wrote:

I have this situation where I want my editor to run dub to build the file I have currently opened (I'm using Scite as an example).

Typically, all I need is a SciTEDirectory.properties file in either the current or some parent directory with these contents:

command.go.subsystem.*.d=0
command.go.*.d=rdmd $(FilePath)

But if I want to use dub things won't be that easy. I can tell where exactly the dub.json file is located, so I could attempt to place my editor script next to it and write this in SciTEDirectory.properties:

command.go.subsystem.*.d=0
# SciteDirectoryHome => Directory path of SciTEDirectory.properties
command.go.*.d=dub $(SciteDirectoryHome)\dub.json --config=$(FileName)

That would have worked perfectly, but it doesn't because the working directory of the editor doesn't match the directory of the dub.json file. I can't make the editor change its current working directory.

(...)

There is the possibility to do dub --root=$(SciteDirectoryHome), which should do the right thing here. The only thing notable is that for pre-0.9.20 versions, the resulting executable will always execute in it's own package directory as the CWD, while 0.9.20 will let it execute in the editor's CWD, if no explicit "workingDirectory" is specified in its dub.json.

Re: Running dub with a current working directory that doesn't match the directory of dub.json

On Wed, 07 May 2014 07:03:17 GMT, Sönke Ludwig wrote:

The only thing notable is that for pre-0.9.20 versions, the resulting executable will always execute in it's own package directory as the CWD, while 0.9.20 will let it execute in the editor's CWD, if no explicit "workingDirectory" is specified in its dub.json.

Corresponding ticket: #272

Re: Running dub with a current working directory that doesn't match the directory of dub.json

On Wed, 07 May 2014 07:03:17 GMT, Sönke Ludwig wrote:

There is the possibility to do dub --root=$(SciteDirectoryHome), which should do the right thing here.

Didn't know about that, thanks. Although it seems it doesn't work properly:

Compiling...
DMD v2.066 DEBUG
Linking...
DMD v2.066 DEBUG
Running .\tut_01.exe 
Error executing command run: Program exited with code -1073741515

Maybe dub isn't taking --root into account when executing the app. It is put into the bin folder as I've specified in the targetType option.

Re: Running dub with a current working directory that doesn't match the directory of dub.json

On Wed, 07 May 2014 09:37:20 GMT, Andrej Mitrovic wrote:

Maybe dub isn't taking --root into account when executing the app. It is put into the bin folder as I've specified in the targetType option.

Oops sorry about that, turns out I was missing a DLL.

Is there any reason why dialog boxes do not pop-up when dub runs the exe? Otherwise it would have showed me:

---------------------------
tut_01.exe - System Error
---------------------------
The program can't start because glfw3.dll is missing from your computer. Try reinstalling the program to fix this problem. 
---------------------------
OK   
---------------------------

Re: Running dub with a current working directory that doesn't match the directory of dub.json

Am 07.05.2014 11:48, schrieb Andrej Mitrovic:

On Wed, 07 May 2014 09:37:20 GMT, Andrej Mitrovic wrote:

Maybe dub isn't taking --root into account when executing the app. It is put into the bin folder as I've specified in the targetType option.

Oops sorry about that, turns out I was missing a DLL.

Is there any reason why dialog boxes do not pop-up when dub runs the exe? Otherwise it would have showed me:

---------------------------
tut_01.exe - System Error
---------------------------
The program can't start because glfw3.dll is missing from your computer. Try reinstalling the program to fix this problem.
---------------------------
OK
---------------------------

Hm, interesting question. It's just run with spawnProcess. I'll see if
I get the same behavior.