code-d icon indicating copy to clipboard operation
code-d copied to clipboard

Dub Build Tasks don't use environment variables from tasks.json

Open aubade opened this issue 3 years ago • 2 comments

I'm trying to set LD_LIBRARY_PATH from tasks.json so it'll link to library files created in another root of my build.

Unfortunately, for whatever reason, it seems like the dub build task isn't respecting the environment while a simple test task does.

My tasks.json:

{
	"version": "2.0.0",
	"options": {
		"env": {
			"LD_LIBRARY_PATH":"${workspaceFolder:DSFMLC}/build/lib",
			"LIBRARY_PATH":"${workspaceFolder:DSFMLC}/build/lib"
		}
	},
	"tasks": [
		{
			"label": "test env",
			"type": "shell",
			"command": "echo",
			"args": [
				"$LD_LIBRARY_PATH"
			],
			"problemMatcher": []
		},
		{
			"type": "dub",
			"run": false,
			"cwd": "${workspaceFolder}",
			"dub_args": [
				"ice-engine:enginetest"
			],
			"configuration": "standard",
			"problemMatcher": [
				"$dmd"
			],
			"group": "build",
			"label": "dub: Build ICE Enginetest",
			"detail": "dub build --compiler=dmd -a=x86_64 -b=debug"
		}
	]
}

For my test, I replaced the normal LD with this shell script:

#!/bin/bash

echo LIBRARY PATH IS: o $LD_LIBRARY_PATH o

Running the normal build task, followed by the test_env task produces this output:

Linking...
LIBRARY PATH IS: o o 
Source file does not exist.
The terminal process "fish '-c', ''/usr/bin/dub' 'build' '--config=standard' 'ice-engine:enginetest''" terminated with exit code: 2.

Terminal will be reused by tasks, press any key to close it.

> Executing task in folder ice: echo $LD_LIBRARY_PATH <

/home/erika/Devel/git/DSFMLC/build/lib

Terminal will be reused by tasks, press any key to close it.

aubade avatar Jan 15 '22 22:01 aubade

What happens when you replace the dub executable with a script out putting the environment variable?

I wonder wheter it is an issue with the plugin or dub itself.

andre2007 avatar Jan 16 '22 17:01 andre2007

I don't pass in environment variables anywhere to the build task I pass to the vscode tasks API, so I don't think it will contain the environment variables from elsewhere in the tasks file

WebFreak001 avatar Jan 16 '22 19:01 WebFreak001