Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to assign an environment variable from DUB? #940

Closed
MGWL opened this issue Sep 28, 2016 · 6 comments
Closed

How to assign an environment variable from DUB? #940

MGWL opened this issue Sep 28, 2016 · 6 comments

Comments

@MGWL
Copy link

MGWL commented Sep 28, 2016

My application in Linux shall load the libraries from a certain place. How to tell DUB what it would change LD_LIBRASRY_PATH?

@s-ludwig
Copy link
Member

If everything is right, it should forward environment variables from the parent environment to the compiler/liner, so LD_LIBRARY_PATH=... dub should work. I haven't tried it yet, though.

@MGWL
Copy link
Author

MGWL commented Sep 29, 2016

I want to have an opportunity to run again created application (from dub)
for which correct working it is necessary to set variable environments.
Values of these variables should be registered in sdl and json files.
Example:

   "enviroment": [
        { "LD_LIBRARY_PATH", "$PACKAGE_DIR" },
        { "MY_VARIABLE", "$PACKAGE_DIR/IMAGES"}
   ]

I tried to change source text of DUB entering the next lines there:

module app;
import dub.commandline;
import std.process;

int main(string[] args)
{
    // -------------- I change the variable environments
    environment["LD_LIBRARY_PATH"] = "/home/gena/qte5";
    environment["MY_VARIABLE"] = "/home/gena/qte5";
    // -------------- and it works as it is necessary for me 

    return runDubCommandLine(args);
}

I ask to consider the possibility of change of an algorithm of dub for
a possibility of handling enviroment variables

@s-ludwig
Copy link
Member

It wouldn't be a good idea to put machine specific paths into the package recipe, as it is one of the goals of DUB to avoid this kind of system setup dependence. A library path within the package directory would be okay, though. An alternative for LD_LIBRARY_PATH it to directly specify library files with their full path in the "sourceFiles" directive.

Are there any other environment variables that would be important for the compiler/linker?

@MGWL
Copy link
Author

MGWL commented Sep 29, 2016

Sorry. We don't understand each other :-(
My STARTING application shall read the enviroment variable. For example MY_VARIABLE= "I'm Gena". How to describe it in dub.json? Please, write an example of dub.json for it.

@MGWL
Copy link
Author

MGWL commented Sep 30, 2016

I suggest to add:

   "enviroment": [
        { "LD_LIBRARY_PATH", "$PACKAGE_DIR" },
        { "MY_VARIABLE", "$PACKAGE_DIR/IMAGES"}
   ]

change build.d:
from:
auto prg_pid = spawnProcess(exe_path_string ~ run_args);
to:
auto prg_pid = spawnProcess(exe_path_string ~ run_args, enviromrnt);
string[string] enviroment from section "enviroment"

@WebFreak001
Copy link
Member

fixed with #2121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants